基于nginx配置实现隐藏金蝶s-HR访问地址的端口和上下文路径1.前言通常我们访问s-HR系统的地址一般是http://[域名或ip]:8080/shr,现有客户需要隐藏掉端口8080和shr,希望能做到直接访问域名即可访问到系统,不需要填写端口和shr。因s-HR系统需要结合portal、easweb、web、eassso等子项目配合使用,故地址栏不能隐藏shr,这里只能做到输入域名默认跳转shr,不用客户手动输入shr。本文档面向服务器管理员,需要有一定的服务器管理知识。2.安装nginx下载安装最新稳定版本nginx,具体安装方法请自行查阅相关资料。3.配置nginx打开nginx目录conf下的nginx.conf,增加和修改如下配置即可:server{listen80;server_namelocalhost;server_namewww.test.com;server_name_in_redirectoff;#charsetkoi8-r;#access_loglogs/host.access.logmain;location/{roothtml;indexredir.htmlindex.htmlindex.htm;}location/shr/{proxy_redirectoff;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$remote_addr;proxy_passhttp://localhost:6888/shr/;}location/easweb/{proxy_redirectoff;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$remote_addr;proxy_passhttp://localhost:6888/easweb/;}location/web/{proxy_redirectoff;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$remote_addr;proxy_passhttp://localhost:6888/web/;}location/res/{proxy_redirectoff;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$remote_addr;proxy_passhttp://localhost:6888/res/;}location/eassso/{proxy_redirectoff;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$remote_addr;proxy_passhttp://localhost:6888/eassso/;}location/portal/{proxy_redirectoff;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$remote_addr;proxy_passhttp://localhost:6888/portal/;}#如shr有更多子项目目录,这里可以再按上面格式添加}其中将www.test.com换成客户自己的域名,http://localhost:6888/[xxx]/换成客户实际系统地址。如果有用到SSL,请按nginx的配置另行修改4.增加默认跳转页面在nginx安装目录html下新增redir.html文件,用于默认首页跳转到shr/,文件内容如下:5.完成启动或重启nginx,直接访问域名www.xxx.com,即可正常访问到s-HR系统,查看浏览器地址栏,端口号不会显示,shr项目名会自动添加上去。