nginx跳转到指定工程名

tomcat部署的应用通常需要加工程名进行访问,如www.test.com/app/index,nginx需要跳转到app这一级才能打开想要的页面,可以使用下面的配置:

#精确匹配
location = / {
    ……
    proxy_pass http://ip:port/app/;
}
location / {
    ……
    proxy_pass http://ip:port;
}

需要注意ip:port/app/后有无/的区别,加/则省略app,访问时直接显示访问对应的文件,否则是全路径:
如 不加/访问 http://192.168.10.100:9080/app/index.html 显示为 http://192.168.10.100:9080/app/index.html
加/访问 http://192.168.10.100:9080/app/index.html 显示为 http://192.168.10.100:9080/index.html

猜你喜欢

转载自blog.51cto.com/hunt1574/2605768