nginx+tomcat均衡负载配置,nginxtomcat负载


nginx 安装 在虚拟机上要先安装pcre 然后是nginx 或者直接安装中文wiki上的方案安装。

输入./nginx -t
显示如下:
nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/nginx.conf test is successful
表示启动成功。

./nginx 启动服务

修改nginx.conf后执行 kill -HUP 进程号  进行服务重启。

在这里的配置是: 一台虚拟机上 192.168.1.8我安装了nginx ,另一台window上面,ip是192.168.2.26部署了war包 并启动服务,单独访问192.168.2.26::880/bas可以访问相应的网站。在另一台虚拟机上ip是192.168.111.3上面也部署了相应的war包并启动服务。单独访问192.168.111.3:8088也能访问相应的页面。之后192.168.1.8上面的nginx配置文件中实现负载均衡,启动后 没有效果,日志里面也没有显示。nginx是安装好的。

在192.168.1.8属于代理服务器,部署nginx ,war包部署在192.168.2.26和192.168.2.154上 配置好服务器后 保证各个服务器之间能够ping同,还要保证单独访问192.168.2.26和192.168.2.154成功。
根据在upstream中部署的server 路径 必须与单独访问负载服务器的路径一致。我这里全部以ROOT发布 所以单独访问的路径分别是:192.168.2.26::80和192.168.2.154:8080


nginx.conf
#user  nobody;
worker_processes  1;

error_log  logs/error.log;

events {
    worker_connections  1024;
}


http {
        include       mime.types;
            default_type  application/octet-stream;
            sendfile on;
            tcp_nopush on;
            keepalive_timeout 60;
            tcp_nodelay on;

    upstream 192.168.1.8  {
              server 192.168.2.26:80 weight=2;
              server 192.168.2.154:8080;
      }

    server {
        listen       80;

         server_name 192.168.1.8;

        location / {
                        proxy_redirect off;
                        #保留用户真实信息
                        proxy_set_header Host $host;
                        proxy_set_header   X-Real-IP   $remote_addr;
                        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                        proxy_pass        http://192.168.1.8;
         }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        log_format www_test_com  '$remote_addr - $remote_user [$time_local] $request '
         '"$status" $body_bytes_sent "$http_referer" '
           '"$http_user_agent" "$http_x_forwarded_for"';
                                                access_log  /usr/local/nginx/logs/nginx.log  www_test_com;

    }
}

这里没有设置nginx用户。不过没有关系。

一些启动命令:
测试安装成功:
./nginx -t
nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/nginx.conf test is successful
显示如上信息 即可
启动命令:
./nginx
修改配置文件后平滑启动nginx命令:
kill -HUP  进程号

关于日志的配置如下:

相关内容

    暂无相关文章