我在一个 nginx conf 文件中有大约 1300 个虚拟主机。所有具有以下布局(它们在 vhost 文件中依次列出)。
现在我的问题是有时我的浏览器会将site2重定向到site1。出于某种原因,虽然域名不匹配。
看起来 nginx 总是重定向到 vhosts 文件中的第一个站点。
有人知道这个问题可能是什么吗?
server {
listen 80;
server_name site1.com;
rewrite ^(.*) http://www.site1.com$1 permanent;
}
server {
listen 80;
root /srv/www/site/public_html/src/public/;
error_log /srv/www/site/logs/error.log;
index index.php;
server_name www.site1.com;
location / {
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
}
location ~ .(php|phtml)$ {
try_files $uri $uri/ /index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/site/public_html/src/public$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
server {
listen 80;
server_name site2.com;
rewrite ^(.*) http://www.site2.com$1 permanent;
}
server {
listen 80;
root /srv/www/site/public_html/src/public/;
error_log /srv/www/site/logs/error.log;
index index.php;
server_name www.site2.com;
location / {
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
}
location ~ .(php|phtml)$ {
try_files $uri $uri/ /index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/site/public_html/src/public$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
编辑也许要提到的另一件事是,我每 2 分钟使用 nginx -s reload 重新加载所有这些虚拟主机。
在第一次测试中,重定向似乎只在重新加载时发生......要做更多测试,但这可能会有所帮助..