1、多域名访问
功能实现场景:
就是安装部署一个nginx,启动端口为80,可以使用www.java.cn/userWeb/index.html访问,也可以使用game.net.cn/userWeb/login.jsp访问。
Nginx配置:
实现过程,放置2个server{…… server_name www.xxx.com; ……},配置参见下面的案例细节,然后启动nginx就可以实现。
server { listen 80; server_name www.java.cn; #charset koi8-r; #access_log logs/host.access.log main;
upstream gatewaybackend{ #ip_hash; server 192.168.121.213:6100 ; ##server 192.168.180.104:6100 down ; }
location ~* ^/*$ { proxy_pass http://gatewaybackend; include proxy.conf;
error_log logs/gateway_error.log info; access_log logs/gateway_access.log main; }
location /meeting { root html; index index.html index.htm; } location /demo { root html; index index.html index.htm; }
error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }
}
server { listen 80; server_name game.net.cn;
#charset koi8-r;
#access_log logs/host.access.log main;
location / { root html/game; index index.html; }
error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }
} |
2、二次转发
功能实现场景
输入plocc.powerlong.com/gt/glc/index.html这样简短的域名,然后实现直接访问linux下部署的几台tomcat应用OCC_DataCollection_Web,而且浏览器的url显示不能改变。
在nginx.conf配置:
# 配置负载均衡路由 upstream odw_backend{ server 192.168.121.243:6700; server 192.168.121.223:6700; server 192.168.121.253:6700; }
# 第一次跳转转发,主要是浏览器输入框的url不会变化 location ~* ^/dt/.*$ { rewrite /dt/(.*) /OCC_DataCollection_Web/$1 ;
}
# 第二次跳转转发,url不会变,然后实际访问的是linux下的tomcat应用 location ~* ^/OCC_DataCollection_Web/.*$ { include deny.conf;
proxy_pass http:// odw_backend; include proxy.conf;
error_log logs/occ_dataconnection_web.log error; access_log logs/occ_dataconnection_web.log sso;
}
|
在tomcat里面部署一个临时目录glc,里面准备index.xml:
# 进入tomcat工程目录cd /usr/local/app/apache-tomcat-6.0.37_7000/webapps/glc;准备测试的html文件: [tomcat@test_idc_web_1_24 glc]$ more index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>交易主页</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head>
hello, welcome to yueworld ! <body> <div>
</div> </body> </html> [tomcat@test_idc_web_1_24 glc]$ |
在网页中验证跳转信息,输入plocc.powerlong.com/gt/glc/index.html,成功跳转后会显示如下界面,如下图所示: