nginx 配置反向代理和负载均衡

Nginx的配置文件:

nginx安装目录/conf/nginx.conf

重新加载配置文件

./nginx -s reload

配置虚拟主机

一个server就是一台虚拟主机

 server {
        listen       80;//监听端口
        server_name  localhost;//域名

        location / {
            root   html;
            index  index.html index.htm;
        }
 }

反向代理与负载均衡

upstream tomcat {
        server ip1:端口号1 weight=2;
        server ip2:端口号2 weight=2;//权重
}
 server {
        listen       80;//监听端口
        server_name  www.test.com;//域名

        location / {
            proxy_pass   http://tomcat;
            index                       index.html index.htm;
        }
 }