1

I have 3 domain name, 1 server and 1 IPv4 and 1ipv6. I’ve set a record to my ipv4 (I doesn’t use IPv6 right now). My 3 sites use Wordpress. I have configured Nginx, and php-fpm for a domain.

/etc/nginx/conf.d/php5-fpm :

upstream php5-fpm-sock {
        server unix:/var/run/php5-fpm.sock; }

/etc/nginx/sites-available/domain.com.conf :

server {
    listen       80;
    server_name  domain.com;

    root /var/www/domain.com;
    index index.php index.html;

    #charset koi8-r;
    access_log  /var/log/nginx/domain.com.access.log;
    error_log /var/log/nginx/domain.com.error.log;

    #include global/common.conf;
    #include global/wordpress.conf;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_index index.php;
                fastcgi_pass php5-fpm-sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        }
}

/etc/nginx/sites-available/totaly-different-domain.com.conf :

server {
    listen       80;
    server_name  totaly-different-domain.com;

    root /var/www/totaly-different-domain.com;
    index index.php index.html;

    #charset koi8-r;
    access_log  /var/log/nginx/totaly-different-domain.com.access.log;
    error_log /var/log/nginx/totaly-different-domain.com.error.log;


    #include global/common.conf;
    #include global/wordpress.conf;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_index index.php;
                fastcgi_pass php5-fpm-sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        }
}

Problem : domain 1 appears on my navigator when I type domain.com but also when I type totaly-different-domain.com.

  • domain.com -> show domain.com
  • totaly-different-domain.com -> show domain.com

PS : I know I can optimize that but I want to understand why I have got this problem before.

UPDATE 1 :

Here are my working files :

/etc/nginx/sites-available/domain.com.conf :

server {
    server_name domain.com www.domain.com;

    root /var/www/domain.com/;
    index index.php index.html;

    access_log  /var/log/nginx/domain.com.access.log;
    error_log /var/log/nginx/domain.com.error.log;

    include global/common.conf;
    include global/wordpress.conf;

}

/etc/nginx/sites-available/totaly-different-domain.com.conf :

server {
    server_name totaly-different-domain.com www.totaly-different-domain.com;

    root /var/www/totaly-different-domain.com/;
    index index.php index.html;

    access_log  /var/log/nginx/totaly-different-domain.com.access.log;
    error_log /var/log/nginx/totaly-different-domain.com.error.log;

    include global/common.conf;
    include global/wordpress.conf;

}

/etc/nginx/global/common.conf :

# Global configuration file.
# ESSENTIAL : Configure Nginx Listening Port
listen 80;

# ESSENTIAL : Default file to serve. If the first file isn't found,
index index.php index.html index.htm;

# ESSENTIAL : no favicon logs
location = /favicon.ico {
    log_not_found off;
    access_log off;
}

# ESSENTIAL : robots.txt
location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}

# ESSENTIAL : Configure 404 Pages
error_page 404 /404.html;

# ESSENTIAL : Configure 50x Pages
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /usr/share/nginx/www;
}

# SECURITY : Deny all attempts to access hidden files .abcde
location ~ /\. {
    access_log off;
    log_not_found off;
    deny all;
}

# PERFORMANCE : Set expires headers for static files and turn off logging.
location ~* ^.+\.(js|css|swf|xml|txt|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|$
    access_log off;
    log_not_found off;
    expires 30d;
}

/etc/nginx/global/wordpress.conf :

# WORDPRESS : Rewrite rules, sends everything through index.php and keeps the a$
location / {
    try_files $uri $uri/ /index.php?$args;
}

# SECURITY : Deny all attempts to access PHP Files in the uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
}

# REQUIREMENTS : Enable PHP Support
location ~ \.php$ {
    # SECURITY : Zero day Exploit Protection
    try_files $uri =404;

    fastcgi_index index.php;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php5-fpm-sock;

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
}
Oyabi
  • 133
  • 2
  • 13
  • Have you restarted nginx? Check if you visit `totaly-different-domain.com` and not `www.totaly-different-domain.com`. – Alexey Ten May 06 '14 at 11:53
  • Yes, I have restart Nginx and php-fpm. Same result with or without www. – Oyabi May 06 '14 at 12:01
  • Do you have other server blocks enabled? – Alexey Ten May 06 '14 at 12:50
  • No :( In my conf.d I only have php5-fpm.conf and in sites-enabled only domain.com.conf and totaly-different-domain.com.conf. In my nginx.conf I have include `/etc/nginx/sites-enabled/*.conf;` and `include /etc/nginx/conf.d/*;` – Oyabi May 06 '14 at 13:36
  • Well, I'm lack of ideas. Just check spelling of address, also check if you request really get to you machine, not some other one. – Alexey Ten May 06 '14 at 14:13
  • Address are correct and when I tracert to domain.com or totaly-different-domain.com I've get my server IP. Maybe I must change a parameter in php-fpm, but I don't know what. – Oyabi May 06 '14 at 16:53

2 Answers2

0

Ok I have find solution. You must replace :

server_name totaly-different-domain.com;

by

server_name totaly-different-domain.com www.totaly-different-domain.com;

Same thing for domain.com.

Oyabi
  • 133
  • 2
  • 13
  • So I was right about www – Alexey Ten May 07 '14 at 04:21
  • Indeed but when I tried to access www.domain.com, domain.com, totaly-different-domain.com or www.totaly-different-domain.com I was redirected to domain.com any case. I don't understand why I must write www. before my domain in .conf because my domain have not the same name. It's like foo.com and toto.fr. – Oyabi May 07 '14 at 08:17
0

You do not need to replace

     server_name totaly-different-domain.com;

with

     server_name totaly-different-domain.com www.totaly-different-domain.com;

Using the configurations you posted I was unable to reproduce your problem. Your issue is not with your configuration.

Trying temporarily replacing the contents of index.php with

   <?php echo $_SERVER['SERVER_NAME']; ?>

and visit each site. If the correct server name is displayed for each domain, you may find this link helpful. http://tommcfarlin.com/resolving-the-wordpress-multisite-redirect-loop/

mjmcull
  • 1
  • 1
  • Same problem with this configuration. – Oyabi May 07 '14 at 19:49
  • Could you post the reset of your nginx configuration files? I can't see how it is responsible, but maybe I'll understand if I see them. – mjmcull May 08 '14 at 02:22
  • See Update 1 ;) – Oyabi May 08 '14 at 09:15
  • I'm still unable to reproduce the issue. I suggest comparing the session cookies for each site and see if they are the same. I suspect they would be, but it would be nice to be sure. Take a look at these sites and let me know if it seems relevant. http://tommcfarlin.com/resolving-the-wordpress-multisite-redirect-loop/ and http://blog.caercam.org/2014/03/19/wordpress-network-cookie-error-when-using-different-domains/ – mjmcull May 08 '14 at 13:04