我有 3 个域名、1 个服务器、1 个 IPv4 和 1 个 IPv6。我已为我的 IPv4 设置了记录(我现在不使用 IPv6)。我的 3 个网站使用 Wordpress。我已为域名配置了 Nginx 和 php-fpm。
/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;
}
}
问题:当我输入 domain.com 时,域 1 会出现在我的导航器上,但当我输入 totally-different-domain.com 时,域 1 也会出现在我的导航器上。
- domain.com -> 显示 domain.com
- totally-different-domain.com -> 显示 domain.com
附言:我知道我可以优化它,但我想了解为什么我以前遇到过这个问题。
更新 1:
这是我的工作文件:
/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;
}
答案1
好的,我找到了解决方案。您必须替换:
server_name totaly-different-domain.com;
经过
server_name totaly-different-domain.com www.totaly-different-domain.com;
对于 domain.com 来说也是同样如此。
答案2
您不需要更换
server_name totaly-different-domain.com;
和
server_name totaly-different-domain.com www.totaly-different-domain.com;
使用您发布的配置,我无法重现您的问题。您的问题不在于您的配置。
尝试暂时用以下代码替换 index.php 的内容
<?php echo $_SERVER['SERVER_NAME']; ?>
并访问每个站点。如果每个域都显示正确的服务器名称,您可能会发现此链接很有帮助。http://tommcfarlin.com/resolving-the-wordpress-multisite-redirect-loop/