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 have two domains setup on one server running LEMP.

When i access the domain2.co.uk everything is fine. But when I go to www.domain2.co.uk it is redirecting to www.domain1.co.uk

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/*;
    }

../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;
                        }
       }

../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
    
You've probably have some error in www.domain2.co.uk domain: missed ';', non-printable character, etc. Try re-writing it from scratch in a new file. –  rvs Apr 28 '11 at 18:16
    
Any chance that the script has a redirect coded into it as well as nginx? –  Jack M. Apr 28 '11 at 18:17
    
@rvs I tried what you suggested and it never resolved the issue. –  showFocus Apr 28 '11 at 19:45
    
@Jack M not sure I understand what you mean? –  showFocus Apr 28 '11 at 19:46
    
You are passing control from nginx to wordpress or some other .php file. Are those scripts doing a redirect? –  Jack M. Apr 28 '11 at 19:51

1 Answer 1

Make sure you're testing the redirect with curl -I and not a browser. A browser may have cached an incorrect 301 if you had a problem in the past, and sometimes they'll continue to use that cached 301 long after the server configuration has been corrected.

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.