nginx 只配置了一个域名,结果另一个域名也能访问

2021-01-05  本文已影响0人  Darker_坤

今天自己在部署业务的时候, 一个同事说他用另一个域名访问到了我这个域名下的网页, 看来我自己的Nginx的配置,感觉没什么问题!

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,加一条默认的阻挡。

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;
           }
}
上一篇 下一篇

猜你喜欢

热点阅读