5

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;
            }
      }
showFocus
  • 161
  • 1
  • 4
  • 4
    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 02:53
  • It's hard to say anything without looking at the Nginx config – Alexander Azarov Apr 28 '11 at 08:18
  • Yes the address bar actually changes. From domain2.co.uk to domain1.co.uk – showFocus Apr 28 '11 at 11:55
  • 3
    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
  • Ok I double checked the domain name spelling and they are all correct. If that is what you are referring to Martin? – showFocus Apr 28 '11 at 12:39
  • It's also possible that redirect is sent by application logic. And can you provide your fastcgi_params file? There could be some issue within it. – DukeLion Sep 16 '12 at 07:27
  • On the second domain, the path mentioned with `fastcgi_params` doesn't match the rest of the config. – Jenny D May 30 '16 at 09:12

2 Answers2

0

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

 /home/me/public_html/domain2/public$fastcgi_script_name;
Andrei Mikhaltsov
  • 3,027
  • 1
  • 23
  • 31
-1

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.

showFocus
  • 161
  • 1
  • 4
  • 4
    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