【发布时间】:2018-06-16 14:20:24
【问题描述】:
我有几个配置了 nginx 的虚拟主机。他们彼此非常相似,对于他们中的大多数人来说,一切似乎都很好。
然而,
- 如果我通过未配置任何虚拟主机的 url 访问服务器,nginx 总是重定向到现有虚拟主机之一(似乎是列表中的第一个。
- 如果我只是使用 IP 地址去那里,也会发生同样的情况。
大部分虚拟主机是这样的:
server {
server_name iibs.co;
return 302 $scheme://www.iibs.co$request_uri;
}
server {
server_name www.iibs.co;
root /var/www/iibs.co;
index index.php;
include global/restrictions.conf;
client_max_body_size 64M;
# Additional rules go here.
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
# Only include one of the files below.
# include global/wordpress.conf;
# include global/wordpress-ms-subdir.conf;
# include global/wordpress-ms-subdomain.conf;
}
我刚刚尝试添加另一个,非常相似,只是具有不同的域和根。而那个特定的,也被重定向到列表中的第一个虚拟主机。
此时,我不知道应该在哪里寻找什么。
【问题讨论】:
-
当你没有定义一个 default_server 时,nginx 会选择一个。因此,只需使用 default_server 标签定义一个虚拟主机并返回 444 或类似的东西。
标签: php nginx virtualhost