您的位置:首页 > 运维架构 > Tomcat

1.10版本以上Nginx tomcat集群配置

2016-08-20 14:27 337 查看
先说遇到的问题和需要解决的问题:

1.nginx启动很快,但是请求到集群的时间很慢很慢,总是提示upstream请求不到。

2.整个集群环境的重启特别耗费时间。

3.nginx的配置不对,导致websocket不好用,以及集群的响应缓慢。(看起来1跟3是一个问题,其实并不是)

环境安装五花八门,软件下载地址分享:http://pan.baidu.com/s/1qYVIOgs

nginx建议安装地址(转发):http://jingyan.baidu.com/article/454316ab6b1406f7a6c03a5b.html,安装命令帮忙贴出来:

./configure --sbin-path=/home/nginx-1.11.2/nginx --conf-path=/home/nginx-1.11.2/nginx.conf --pid-path=/home/nginx-1.11.2/nginx.pid --with-http_ssl_module --with-pcre=/home/pcre-8.39 --with-zlib=/home/zlib-1.2.8 --with-openssl=/home/openssl-1.0.1g

我只贴出来现在完全OK的配置:

user  nginx;

worker_processes 4;

worker_rlimit_nofile 100000;

error_log  /var/log/nginx/error.log;

pid        /var/run/nginx.pid;

events {

    worker_connections  8096;

    multi_accept on;

    use epoll;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  /var/log/nginx/access.log  main;

    access_log off;

    sendfile    on;

    tcp_nopush  on;

    #keepalive_timeout  0;

    keepalive_timeout  120;

    gzip on;

upstream orderapp {
server    127.0.0.1:8080  weight=1;
server    127.0.0.1:8180  weight=1;
server    127.0.0.1:8280  weight=1;
server    127.0.0.1:8380  weight=1;
ip_hash;
}

server {
listen       80;
server_name  localhost;

location / {
proxy_pass http://orderapp; proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
root   /usr/share/nginx/html;
index  index.html index.htm;
}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /usr/share/nginx/html;
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx tomcat 集群