CentOS7下配置Nginx并实现简单的负载均衡

1.Nginx的配置和安装

https://www.cnblogs.com/zhoading/p/8514050.html

2.安装多个Tomcat

你可以把webapps目录里ROOT下的index.jsp改下,好看到tomcat有没有切换

https://www.linuxidc.com/Linux/2018-02/151085.htm

3.nginx的配置 /usr/local/nginx/conf/nginx.conf

# http里面,server外面
upstream tomcat{
  #轮流
   server 127.0.0.1:8080;
   server 127.0.0.1:8081;
   server 127.0.0.1:8082;
}

server{
   # 其他的省略
  listen       80;
   server_name localhost;

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

 

4.最后启动nginx和tomcat,在浏览器里输入localhost:80

5.如果你修改了server_name,那么你需要到/etc/hosts文件里添加你的server_name和ip

加入我把server_name改成www.123.com那么我需要在hosts文件里加入127.0.0.1 www.123.com

posted @ 2019-07-09 21:16  KuroNJQ  阅读(970)  评论(0编辑  收藏  举报