nginx+tomcat反向代理負載均衡配置

小不點丶發表於2017-05-02

1、nginx的安裝和配置見:http://www.cnblogs.com/ll409546297/p/6795362.html

2、tomcat部署專案到對應的伺服器上面並啟動,不詳解

3、在nginx中配置nginx.conf檔案: 

user  nobody; 
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    #                  `"$http_user_agent" "$http_x_forwarded_for"`;

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    upstream tomcat_client { #針對於8080埠實現
        ip_hash;
        server localhost:8080; #如果存在多個部署,寫入地址和埠即可

    }
    server {
        listen       80;
        server_name  localhost; #本地訪問名稱可以修改,針對於外網可以寫成域名

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://tomcat_client; 
            proxy_redirect default;
            #設定代理
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }

4、啟動nginx就可以訪問自己的專案


相關文章