Ok, eu encontrei a solução. Você deve substituir:
server_name totaly-different-domain.com;
por
server_name totaly-different-domain.com www.totaly-different-domain.com;
Mesma coisa para domain.com.
Eu tenho 3 nomes de domínio, 1 servidor e 1 IPv4 e 1ipv6. Eu configurei um registro para o meu ipv4 (eu não uso o IPv6 agora). Meus 3 sites usam o Wordpress. Eu configurei o Nginx e o php-fpm para um domínio.
/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;
}
}
Problema: o domínio 1 aparece no meu navegador quando eu digito domain.com, mas também quando digito totaly-diferente-domínio.com.
PS: Eu sei que posso otimizar isso, mas quero entender por que tenho esse problema antes.
UPDATE 1 :
Aqui estão meus arquivos de trabalho:
/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;
}
Você não precisa substituir
server_name totaly-different-domain.com;
com
server_name totaly-different-domain.com www.totaly-different-domain.com;
Usando as configurações que você postou, não consegui reproduzir seu problema. Seu problema não está na sua configuração.
Tentando substituir temporariamente o conteúdo do index.php por
<?php echo $_SERVER['SERVER_NAME']; ?>
e visite cada site. Se o nome correto do servidor for exibido para cada domínio, você poderá achar esse link útil. link