我有以下两个服务器指令设置包括conf.d / *。conf。 当我通过公共的外部IP地址导航到服务器时,它似乎与127.0.0.1的服务器匹配,因为一个条目被添加到localhost.access_log文件中。 我期望这只会发生在通过本地主机访问。 我希望从外部IP匹配.host.tld server_name
指令或default_server
参数。
我需要确保订单如何加载conf文件? 为什么127.0.0.1上的监听是这样匹配的呢? 它是第二个位置指令是空的吗?
server { listen 127.0.0.1; server_name localhost; access_log /var/log/nginx/localhost.access_log main; error_log /var/log/nginx/localhost.error_log info; root /var/www/localhost/htdocs; } server { listen 80 default_server; server_name .host.tld; access_log /var/log/nginx/host.access_log main; error_log /var/log/nginx/host.error_log info; root /var/www/host/htdocs; location = / { index index.php index.html; } location / { } }
将两个listen
指令都更改为80
,并将127.0.0.1
名称添加到localhost
段的server_name
,以修复它:
server { listen 80; server_name localhost; access_log /var/log/nginx/localhost.access_log main; error_log /var/log/nginx/localhost.error_log info; root /var/www/localhost/htdocs; } server { listen 80 default_server; server_name .host.tld; access_log /var/log/nginx/host.access_log main; error_log /var/log/nginx/host.error_log info; root /var/www/host/htdocs; location = / { index index.php index.html; } ... }