【发布时间】:2014-06-09 08:53:09
【问题描述】:
我有一个在http://localhost:8080 运行的服务器,我希望该服务器的特定 url 由 nginx 代理。
例如,我只想将 http://localhost:8080/test/(.*) 反向代理到 http://localhost/test/(.*)。
我正在将另一台服务器代理到http://localhost/。
【问题讨论】:
标签: nginx reverse-proxy
我有一个在http://localhost:8080 运行的服务器,我希望该服务器的特定 url 由 nginx 代理。
例如,我只想将 http://localhost:8080/test/(.*) 反向代理到 http://localhost/test/(.*)。
我正在将另一台服务器代理到http://localhost/。
【问题讨论】:
标签: nginx reverse-proxy
如果只是一个简单的location 块呢?
server {
# ... other stuff
location /test/ {
try_files $uri @testproxy;
}
location @testproxy {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
# all your params
}
}
【讨论】:
我以某种方式做到了,并且成功了。无论如何,感谢您的评论。 :)
server {
listen 80;
# ... other stuff
upstream backend1 {
server 127.0.0.1:8080;
}
location /test/ {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://backend1/test/;
}
}
【讨论】: