Nginx drop when server_name does not match

孤街醉人 提交于 2019-11-27 07:11:30

问题


I have two vhosts : one on domain.tld port 80, the other on sub.domain.tld port 443 with SSL on. I added a CNAME entry on my DNS server that redirects my sub subdomain to domain.tld.. Everything works as expected, but going to http://sub.domain.tld does the same as going to http://domain.tld, and https://domain.tld the same as https://sub.domain.tld. How can I prevent this ?

My configuration :

server {
    listen *:443;
    listen [::]:443;

    server_name www.sub.domain.tld;

    ssl on;
    ssl_certifiate ...;
    ssl_certifiate_key ...;

    root /var/www/sub.domain.tld;
    ...
}

server {
    listen *:80;
    listen [::]:80;

    server_name www.domain.tld;

    root /var/www/domain.tld;
    ...
}

回答1:


If these are your only server blocks, then they are also your defacto default server blocks for port 443 and port 80 respectively. See this document for details.

If you do not want this, you need to declare a default server block. A minimalist definition might be:

server {
    listen 80 default_server;
    listen 443 default_server;
    deny all;
}


来源:https://stackoverflow.com/questions/36182968/nginx-drop-when-server-name-does-not-match

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!