nginx proxy_pass将端口号添加到URL

我有一个标准的Rails应用程序部署到Heroku。 我正在使用自定义buildpack来安装nginx,所以我可以创build一些重写规则和反向代理。 除了一个问题我主要工作。

我有以下的location定义代理通过所有的url/博客/到另一个应用程序的URL。

 location ~* ^/blog/?(.*) { set $forward_host 'another.app.com'; set $url_full '$1'; resolver 8.8.8.8 valid=300s; resolver_timeout 10s; # always add trailing slash rewrite ^([^.]*[^/])$ $1/ permanent; index index.html; proxy_hide_header Set-Cookie; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Scheme $scheme; proxy_set_header Host $forward_host; proxy_ignore_headers "Set-Cookie"; proxy_buffering off; proxy_intercept_errors on; proxy_redirect off; proxy_pass http://$forward_host/$url_full; } 

我希望我的所有URL都以斜线结尾,这就是为什么我添加了:

 rewrite ^([^.]*[^/])$ $1/ permanent; 

一切正常,当我打:

 http://nginx-playground.herokuapp.com/blog/ 

但是,当我没有结尾的斜杠和重写规则踢,proxy_pass添加内部Heroku PORT号码的url,它看起来像这样:

 http://nginx-playground.herokuapp.com:27348/blog/ 

我已经尝试了很多不同的东西,比如设置proxy_redirect,但一直没有弄明白。

这里是我设置的示例应用程序的github项目的链接。 你可以派生/克隆它,并尝试部署到heroku,看看自己会发生什么。

https://github.com/WeConnect/nginx-playground

如果你这样做,你将需要以下ENVvariables:

 BUILDPACK_URL: https://github.com/ddollar/heroku-buildpack-multi.git LANG: en_US.UTF-8 RACK_ENV: production 

这是我用作起点的博客文章: http : //blog.codeship.com/how-to-deploy-nginx-on-heroku/

任何帮助或线索将不胜感激。