我的服务器上有几个域名。有 wordpress 多站点和 vanilla php 站点。所有 WP 站点都正常工作,但如果 vanilla php 站点重定向到主 WP 站点。以下是主 WP 站点的配置:
map $http_host $blogid {
1survey.cc 0;
b-shield.icu 1;
airlinetravel.life 2;
}
server {
server_name 1survey.cc *.1survey.cc;
return 301 https://$host$request_uri;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/1survey.cc/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/1survey.cc/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
listen 5.187.1.93:443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/1survey.cc/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/1survey.cc/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
if ($host = www.1survey.cc) {
return 301 https://$host$request_uri;
} # managed by Certbot
root /home/fornex/wordpress;
index index.php;
client_max_body_size 7m;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* /\. {
deny all;
}
location ~*\.(php)$ {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
server {
if ($host = www.1survey.cc) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = b-shield.icu) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 5.187.1.93:80;
server_name 1survey.cc *.1survey.cc;
return 404; # managed by Certbot
}
server {
if ($host = 1survey.cc) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name 1survey.cc *.1survey.cc;
listen 80;
return 404; # managed by Certbot
}
以下是 vanilla php 站点的配置:
map $http_host $blogid {
1survey.cc 1;
b-shield.icu 0;
airlinetravel.life 2;
apparel.rest 3;
}
server {
if ($host = www.b-shield.icu) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = b-shield.icu) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name b-shield.icu *.b-shield.icu;
return 301 https://$host$request_uri;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/1survey.cc/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/1survey.cc/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.b-shield.icu) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name b-shield.icu *.b-shield.icu;
root /home/fornex/b-shield.icu;
index index.php;
include /home/fornex/b-shield.icu/nginx.conf;
client_max_body_size 7m;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* /\. {
deny all;
}
location ~*\.(php)$ {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
server {
if ($host = b-shield.icu) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 5.187.1.93:80;
server_name b-shield.icu *.b-shield.icu;
return 404; # managed by Certbot
}
如果我尝试访问b-shield.icu
它会重定向到https://1survey.cc/wp-signup.php?new=b-shield.icu。 怎么了?
答案1
您listen 5.187.1.93:443 ssl;
在一个server
区块中,又listen 443 ssl;
在另一个区块中。
Nginx 使用 IP 地址部分在server
具有多个 IP 地址的服务器上选择块,其中不同的 IP 地址需要由不同的server
块处理。
大多数情况下,语句中不需要 IP 地址listen
。
如果您有一些listen
带有 IP 地址的语句,而有些不带有,listen
则将选择更具体的语句,这可能是您的某个server
块不接受连接的原因。
为了保持一致性,在所有块中server
,使用:
listen 80;
和/或:
listen 443 ssl;
看这个文件了解详情。