uri_for 包括重定向上的端口号
我正在尝试使用 nginx 作为静态文件的前端 Web 代理,并使用 Starman 作为我的后端 Web 服务器来实现 Catalyst 应用程序。 (我可以使用 Apache 和 FastCGI,它工作得很好,但我真的很想解决整个 PSGI / Plack 和 Starman 的问题)
Starman 启动正常,并且可以在 http 上很好地处理我的请求: //本地主机:5000
。当我启动 nginx 作为前端代理时,无论何时何地使用 $c->uri_for
方法,我的 url 都会变得丑陋并与端口号 (5000) 混淆。
示例:
$c->uri_for("/login") becomes http://myapp.example.com:5000/login rather than http://myapp.example.com/login
我创建了一些日志,以便可以查看 X-Forwarded-Host
和 X-Forwarded-For
的设置。对于普通请求,会设置值(来自 nginx),但每当使用 $c->uri_for 方法时,这些值都不存在。
还有其他人遇到过这个问题吗?
我的 nginx 或 Catalyst conf 配置中是否缺少其他内容?
谢谢!
nginx 配置:
server { listen 80; server_name myapp.example.com; location /static { root /data/users/MyApp/root; expires 30d; } location / { proxy_set_header Host $host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://localhost:5000/; } }
事件虽然这将在同一物理服务器上运行,但在 MyApp 配置中我已经设置:
MyApp->config(using_frontend_proxy => 1)
版本:
Catalyst : 5.80024 nginx : 0.7.67 Plack : 0.9942 Starman : 0.2006
I'm attempting to implement a Catalyst application using nginx as a frontend web proxy for static files, and using Starman for my backend webserver. (I could use Apache & FastCGI and it works just fine, but I'd really like to get the whole PSGI / Plack and Starman thing ironed out)
Starman starts up okay and can handle my requests just fine on http://localhost:5000
. When I fire up nginx to use as my front-end proxy, my urls become ugly and mangle with the port number (5000) whenever or wherever I use the $c->uri_for
method.
Example :
$c->uri_for("/login") becomes http://myapp.example.com:5000/login rather than http://myapp.example.com/login
I have some logs being created so I can see what X-Forwarded-Host
and X-Forwarded-For
are set as. For normal requests, there are values set (coming from nginx), but whenever the $c->uri_for
method is used, those values do not exist.
Has anyone else had this problem?
Am I missing something else in my configuration of either nginx or my Catalyst conf?
Thanks!
nginx config :
server { listen 80; server_name myapp.example.com; location /static { root /data/users/MyApp/root; expires 30d; } location / { proxy_set_header Host $host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://localhost:5000/; } }
Event though this will be ran on the same physical server, in MyApp config I have set :
MyApp->config(using_frontend_proxy => 1)
Versions :
Catalyst : 5.80024 nginx : 0.7.67 Plack : 0.9942 Starman : 0.2006
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的问题出在我的
myapp.psgi
文件中。来自 Catalyst::Engine:: PSGI 并查看
Plack::Middleware::ReverseProxy
:My problem was in my
myapp.psgi
file.from Catalyst::Engine::PSGI and look at
Plack::Middleware::ReverseProxy
:就我而言,前端位于不同的主机中,添加
确实产生了影响并解决了问题。
In my case the frontend was in a different host and adding
did make a difference and solved the problem.