【问题标题】:why nginx proxy_pass to sub directory is not working?为什么 nginx proxy_pass 到子目录不起作用?
【发布时间】:2018-09-28 23:45:42
【问题描述】:
我正在尝试对子目录 http://ms.server.com:8085/ms 执行 proxy_pass。所以每当有人点击http://ms.example.com' it should be redirected tohttp://ms.example.com/ms`。我正在尝试通过以下配置来做到这一点
upstream example {
server ms.server.com:8085;
}
server {
server_name ms.example.com;
location / {
proxy_pass http://example/ms;
}
}
现在我正在重定向到“Nginx 测试页面”。
【问题讨论】:
标签:
redirect
nginx
proxypass
【解决方案1】:
proxy_pass 用于通知 Nginx 在主机级别将代理请求发送到哪里,并且不考虑 URI。
您想改用 return 语句,如下所示:
upstream example {
server ms.server.com:8085;
}
server {
server_name ms.example.com;
location = / {
return 301 http://ms.example.com/ms;
}
location / {
proxy_pass http://example;
}
}
这将使用 301 重定向将请求重定向到 server_name http://ms.example.com 的根 URL,所有其他流量都将传递到定义的上游。