Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I currently have nginx setup to serve content through Varnish. Nginx listens on port 8000 and varnish connects users' requests from 80 to 8000.

The problem is, on some occasions, particularly when trying to hit a directory, like site.com/2010, nginx is redirecting the request to site.com:8000/2010/.

How can I prevent this?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

I found the answer to this question by more carefully reading the HttpCoreModule docs.

port_in_redirect off;

This retains the port used by the client during redirects. Closely related is server_name_in_redirect which uses the first hostname for redirects. As I didn't want sitename.v.myserver.com to redirect to sitename.com,

share|improve this answer

The code behind NGINX probably uses the FASTCGI variable SERVER_PORT to determine where to direct the user. SERVER_PORT will contain the port nginx listens on, so that would be 8000 in your case.

You can try something like this for testing purpose:

location ~ \.php$ {
        [...]
        fastcgi_param  SERVER_PORT 80;
}

adapted to your configuration. That's a dirty hack but can help you diagnose the problem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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