0

I have a website running with nginx and Plack/Starman as upstream. simple configuration looks like:

upstream findmjob {
    server unix:/tmp/findmjob.sock;
}

server {
  listen       80;
  server_name findmjob.com www.findmjob.com fb.findmjob.com;

  access_log /findmjob.com/log/access.log;
  error_log  /findmjob.com/log/error.log info;

  root /findmjob.com/static;
  location / {
    try_files $uri @proxy;
    access_log off;
    expires max;
  }

  location @proxy {
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass       http://findmjob;
  }
}

I have some perl code which returns a redirect. it means it works fine under perl/plack:

Faylands-MacbookPro:findmjob.com fayland$ curl -I 'http://findmjob.com:5000/job/GK3bmm+P4RG+2MTa2fVHmw/'
HTTP/1.0 301 Moved Permanently
Date: Tue, 01 May 2012 06:14:38 GMT
Server: HTTP::Server::PSGI
Location: http://findmjob.com/freelance/GK3bmm+P4RG+2MTa2fVHmw
Server: Perl Dancer 1.3095
Content-Length: 0
Content-Type: text/html; charset=utf-8
X-Powered-By: Perl Dancer 1.3095

as you see it's really with 'http://findmjob.com/'.

but when I use the socks and nginx, it returns something like:


Faylands-MacbookPro:findmjob.com fayland$ curl -I 'http://findmjob.com/job/GK3bmm+P4RG+2MTa2fVHmw/'
HTTP/1.1 301 Moved Permanently
Server: nginx/0.7.65
Date: Tue, 01 May 2012 06:15:20 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Location: .com/freelance/GK3bmm+P4RG+2MTa2fVHmw
Content-Length: 0
X-Powered-By: Perl Dancer 1.3095

the http://findmjob is dropped, only .com is left?!

any help is really appreciated.

Updated: upgrade to the latest version fixed it.

Faylands-MacbookPro:findmjob.com fayland$ curl -I 'http://findmjob.com/job/GK3bmm+P4RG+2MTa2fVHmw/'
HTTP/1.1 301 Moved Permanently
Server: nginx/1.2.0
Date: Tue, 01 May 2012 08:22:29 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 0
Connection: keep-alive
Location: http://findmjob.com/freelance/GK3bmm+P4RG+2MTa2fVHmw
X-Powered-By: Perl Dancer 1.3095

Thanks

1 Answer 1

1

This is because your upstream defined as 'http://findjob' and default for proxy_redirect is

proxy_redirect   http://findjob /;

And this means that nginx will strip string equal to first arg to proxy_redirect (http://findjob) from proxied Location:.

Use proxy_redirect off; instead to fix this issue. Check documentation for details.

2
  • Thanks for it. and weird that I upgraded it to the latest version and it fixes too. May 1, 2012 at 8:23
  • Well, I think that using upsteam id in this case was a bug in nginx which was worth fixing.
    – AlexD
    May 1, 2012 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.