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 am trying to add a second virtual host to nginx. When i go to the new domain it redirects to the old one. I have tried restarting Nginx, rebooting the server.

Has anyone come across this before, care to share?

File: nginx.conf ###

    user www-data www-data;
    worker_processes  4;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        tcp_nopush      on;
        tcp_nodelay     off;
        keepalive_timeout  5;
        gzip  on;
        gzip_comp_level 2;
        gzip_proxied any;
        gzip_types      text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
        include /usr/local/nginx/sites-enabled/*;
    }

File: ../sites-enabled/domain1.co.uk

server {
            listen   80;
            server_name  www.domain1.co.uk;
            rewrite ^/(.*) http://domain1.co.uk/$1 permanent;
       }
server {
            listen   80;
            server_name domain1.co.uk;
            access_log /home/me/public_html/domain1.co.uk/log/access.log;
            error_log /home/me/public_html/domain1.co.uk/log/error.log;
            location /  {
                        root   /home/me/public_html/domain1.co.uk/public/;
                        index  index.php index.html;
                        # WordPress supercache &  permalinks.
                        include /usr/local/nginx/conf/wordpress_params.super_cache;
                        }
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            location ~ \.php$
                    {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include /usr/local/nginx/conf/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /home/me/public_html/domain1.co.uk/public/$fastcgi_script_name;
                        }
       }

File: ../sites-enabled/domain2.co.uk

server {
        listen 80;
        server_name  www.domain2.co.uk;
        rewrite ^/(.*) http://domain2.co.uk/$1 permanent;
}
server {

            listen 80;
            server_name domain2.co.uk;

            access_log /home/me/public_html/domain2.co.uk/log/access.log;
            error_log /home/me/public_html/domain2.co.uk/log/error.log;

            location /
            {

                root   /home/me/public_html/domain2.co.uk/public/;
                index  index.php index.html;

                # Basic version of WordPress parameters, supporting nice permalinks.
                # include /usr/local/nginx/conf/wordpress_params.regular;
                # Advanced version of WordPress parameters supporting nice permalinks and WP Super Cache plugin
                include /usr/local/nginx/conf/wordpress_params.super_cache;
            }

            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include /usr/local/nginx/conf/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /home/me/public_html/domain2/public/$fastcgi_script_name;
            }
      }
share|improve this question
3  
Define "redirects". Do you get an actual redirect where the address in the bar changes, or does it just load the wrong content? Posting your config, removing sensitive chunks, would help. –  Shane Madden Apr 28 '11 at 2:53
    
It's hard to say anything without looking at the Nginx config –  Alexander Azarov Apr 28 '11 at 8:18
    
Yes the address bar actually changes. From domain2.co.uk to domain1.co.uk –  showFocus Apr 28 '11 at 11:55
1  
Your posted config does not do this. Most likely when you removed information about the domain you fixed the actual problem. –  Martin Fjordvald Apr 28 '11 at 12:23
    
So I should double check the domain names in my config files and make sure they are correct? –  showFocus Apr 28 '11 at 12:35

2 Answers 2

I put an index.php page in my directory and accessed it through the browser. No redirect occurred. So it seems if nginx does not find what it is looking for it redirects to another domain.

share|improve this answer
3  
Have you looked at the Nginx logs to verify that that's really what's happening? There's nothing in your posted configuration to tell Nginx to redirect any requests. If it doesn't find what it is looking for, it should return a 404. –  pjmorse Apr 29 '11 at 16:15

Try removing extra slash from fastcgi_param SCRIPT_FILENAME, so the line would be:

 /home/me/public_html/domain2/public$fastcgi_script_name;
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.