1、配置Nginx的反向代理html
配置两台Tomcat服务器tomcat
配置两台Tomcat的端口分别是8087和8088服务器
保证两台Tomcat服务器的三处端口不一致才能启动负载均衡
启动8087端口打开Tomcat7,启动8088端口打开Tomcat8测试
配置Nginx反向代理服务器spa
修改配置文件代理
修改配置文件注意点code
定义upstream tomcat7内的server需指向反向代理指向的服务器地址,分号结束不能忘。server
定义location的proxy_pass为http://tomcat7,对应upstream的名称。htm
upstream manager{ server 192.168.31.159:8087; } server { listen 80; server_name manager.dhc.com; location / { proxy_pass http://manager; index index.html index.htm; } } upstream portal{ server 192.168.31.159:8088; } server { listen 80; server_name portal.dhc.com; location / { proxy_pass http://portal; index index.html index.htm; } }
3. 重启并加载配置文件,并测试是否成功
· 需求:配置Nginx的负载均衡
1.配置文件的修改,其余同上个需求
upstream portal{ server 192.168.31.159:8087 weight=2; server 192.168.31.159:8088; } server { listen 80; server_name portal.dhc.com; location / { proxy_pass http://portal; index index.html index.htm; } }
· 能够在upstream中配置权重weight=2(轮询)