今天自己在部署业务的时候, 一个同事说他用另一个域名访问到了我这个域名下的网页, 看来我自己的Nginx的配置,感觉没什么问题!
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| server { listen 80; server_name www.hehe.com; root /data1/htdocs/kaixuan.hehe.com/; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; include fastcgi_params; } location / { index index.html; } }
|
后来网上查了一下,发现如果当所有server的规则都不匹配时,nginx会采用第一条server配置,所以一般第一条server会使用阻止页面。这样的话,就需要在server上边再加一条server,加一条默认的阻挡。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| server { listen 80 default; listen [::]:80 default; server_name _;
return 403; }
server { listen 80; server_name www.hehe.com; root /data1/htdocs/kaixuan.hehe.com/; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; include fastcgi_params; } location / { index index.html; } }
|