如何设置 nginx 将单个文件夹反向代理到一台服务器,并将根目录的其余部分反向代理到另一台服务器?
根“/”由CMS管理,而“其他”是我自己的程序(独立于CMS)。
这是我目前的配置
server {
listen 80;
server_name www.example.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443;
... <ssl stuff> ...
server_name www.example.com;
location /other {
proxy_pass http://192.168.2.2/other ;
}
location / {
proxy_pass http://192.168.1.1;
}
}
最佳答案
引用 nginx 文档:
http://wiki.nginx.org/HttpCoreModule#location
http://wiki.nginx.org/HttpProxyModule#proxy_pass
您应该更改 other
位置:
location /other/ {
proxy_pass http://192.168.2.2/other/ ;
}
注意尾随
/
.它实际上有所作为,因为它得到 proxy_pass
使请求正常化。我引用:when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the [proxy_pass] directive.
这应该可以帮助那些找到这个页面的人。
关于nginx proxy_pass 到一个目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26449466/