一、配置Nginx的反向代理
-
配置两台Tomcat服务器
-
配置两台Tomcat的端口分别是8087和8088
-
保证两台Tomcat服务器的三处端口不一致才能启动
-
启动8087端口打开Tomcat7,启动8088端口打开Tomcat8
-
-
配置Nginx反向代理服务器
-
修改配置文件
-
修改配置文件注意点
-
定义upstream tomcat7内的server需指向反向代理指向的服务器地址,分号结束不能忘。
-
定义location的proxy_pass为http://tomcat7,对应upstream的名称。
-
-
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(轮询)
...
...