ssl - How to properly configure Nginx to enable HTTPS-enabled websites to prohibit direct access using the server IP address
淡淡烟草味
淡淡烟草味 2017-05-16 17:10:23
0
1
478

The following is the official configuration of nginx:

server {
    listen      80;
    server_name "";
    return      444;
}

https://nginx.org/en/docs/htt...
But it seems that it only supports http. If https is used, the domain name will be used regardless of where it is configured and whether it is configured default_server Access and IP direct access 444.

server {
    listen 80;
    listen [::]:80;
    server_name example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com;

    if ( $host = $server_addr ) {
        return 444;
    }
    # ...
}

https://paste.ubuntu.com/2340...

This is how I configure it now. http request 301 jumps to https, and then use if to detect if the request is made using the server IP address, it will be 444. But this is not a good configuration (https://www.nginx.com/resourc..., is there a better configuration practice?

淡淡烟草味
淡淡烟草味

reply all(1)
phpcn_u1582

server {

listen 80 default;  
rewrite ^(.*) https://域名;  

}

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template