ProxyPass在nginx中

我正在尝试在nginx中使用以下configuration进行proxy_pass:

location /abc_service { proxy_pass http://127.0.0.1:3030; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }

但我得到/ abc_service作为前缀在我的应用程序(rails应用程序运行在端口3030)。 例如:我得到'/ abc_service / users / sign_in'应该是'/ users / sign_in'

我想删除这个前缀。

它在Apache中工作正常:

ProxyPass /abc_service http://localhost:3030 timeout=300 KeepAlive=On ProxyPassReverse /abc_service/ http://localhost:3030/

proxy_pass的操作在nginx文档中有解释: http : //nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

一个请求URI被传递给服务器,如下所示:

如果proxy_pass指令是使用URI指定的,那么当请求传递给服务器时,与该位置匹配的标准化请求URI部分将被指令中指定的URIreplace:

 location /name/ { proxy_pass http://127.0.0.1/remote/; } 

如果指定了proxy_pass而没有URI,那么请求URI将在处理原始请求时以与客户端发送的格式相同的forms传递给服务器,或者在处理更改的URI时传递完整的规范化请求URI:

 location /some/path/ { proxy_pass http://127.0.0.1; } 

所以,你需要使用这个:

 location /abc_service { proxy_pass http://127.0.0.1:3030/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }