mjpeters_ mjpeters_ - 4 years ago 156
Perl Question

uri_for includes port number on redirects

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

. 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

Example :

rather than

I have some logs being created so I can see what
are set as. For normal requests, there are values set (coming from nginx), but whenever the
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?


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

Answer Source

My problem was in my myapp.psgi file.

from Catalyst::Engine::PSGI and look at Plack::Middleware::ReverseProxy:

use Plack::Builder;
use MyApp;

my $app = sub { MyApp->run(@_) };

builder {
 enable_if { $_[0]->{REMOTE_ADDR} eq '' } 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download