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

I have several virtual hosts listening on port 80, and one listening on 8080. They have different hosts names.

When connecting to port 8080, nginx serves a 301 and redirects to the same host name on port 80. This seems to come from the correct virtual host, because the 301 appears in the access logs for the desired target.

any ideas why this would happen?

The server block has fast cgi and some rewrites as follows (and works 100% on port 80)

 server {
    listen       8080;
    server_name  myhost.local;
    root         /path/to/httpdocs;
    access_log   /path/to/log/access.log main;
    error_log    /path/to/log/error.log  warn;

    location / {
        index  index.php;
        # rewrite clean URLs for wordpress
        if (-e $request_filename) {
          break;
        }
        rewrite ^/(.+)$ /index.php?q=$1 last;
    }

    # Process PHP files with fastcgi
    location ~ \.php$ {
      if ( !-f $request_filename ) {
         return 404;
      }
      include /etc/nginx/conf/php-fastcgi.conf;
      fastcgi_pass   127.0.0.1:8890;
      fastcgi_index  index.php;
    }

}
share|improve this question
    
Can you post the server block for this virtualhost? –  theotherreceive Aug 7 '10 at 17:44

3 Answers 3

there is an nginx core module directive called port_in_redirect that you might need to set to 'off' to avoid this.

like so:

location ~ \.php$ {
  if ( !-f $request_filename ) {
     return 404;
  }
  include /etc/nginx/conf/php-fastcgi.conf;
  fastcgi_pass   127.0.0.1:8890;
  fastcgi_index  index.php;
  port_in_redirect off;
}

that should solve the problem.

share|improve this answer

I had your same problem. I wanted to have 2 wordpress istances on the same domain and server but on different ports. Wordpress was indeed redirecting to the default port (80, or 443 for SSL). I solved it by going to Wordpress Admin Panel, and under "General" changing the http://example.com to http://example.com:xx" where xx is the port you want that instance of Wordpress to listen to.

share|improve this answer

I think it's the Wordpress installation forcing the redirect at the PHP level.

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.