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 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;
}
share|improve this question
    
Have you restarted nginx? Check if you visit totaly-different-domain.com and not www.totaly-different-domain.com. –  Alexey Ten May 6 at 11:53
    
Yes, I have restart Nginx and php-fpm. Same result with or without www. –  Oyabi May 6 at 12:01
    
Do you have other server blocks enabled? –  Alexey Ten May 6 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 6 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 6 at 14:13

2 Answers 2

up vote 0 down vote accepted

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.

share|improve this answer
    
So I was right about www –  Alexey Ten May 7 at 4: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 7 at 8:17

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/

share|improve this answer
    
Same problem with this configuration. –  Oyabi May 7 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 8 at 2:22
    
See Update 1 ;) –  Oyabi May 8 at 9: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. tommcfarlin.com/resolving-the-wordpress-multisite-redirect-loop and blog.caercam.org/2014/03/19/… –  mjmcull May 8 at 13:04

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.