• nginx 禁止未绑定的域名访问


    nginx 禁止未绑定的域名访问

    方法1:

    server {
        listen 80 default_server;
        #不指定 server_name, server_name 默认为""
        return 444;
    }
    
    server {
        listen       80;
        server_name  www.mydomain.com;
        root         /usr/share/nginx/html;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location / {
            proxy_set_header Host $host:$proxy_port;#proxy_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://myserver;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
    

    浏览访问未绑定的域名,访问会这样显示(谷歌浏览器):

    方法2:

    server {
        listen      80 default_server;
        server_name _;
        root        /usr/share/nginx/html;
        location / {
        deny all;   
        }
        error_page 403 /403.html;
            location = /403.html {
        }
    }
    
    server {
        listen       80;
        server_name  www.mydomain.com;
        root         /usr/share/nginx/html;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location / {
            proxy_set_header Host $host:$proxy_port;#proxy_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://myserver;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
    

    浏览访问未绑定的域名,会显示 403.html 的内容:

  • 相关阅读:
    Tomcat配置JNDI
    (转)通过反编译深入理解Java String及intern
    (转)Java8内存模型-永久代(PermGen)和元空间(Metaspace)
    排序算法
    并发编程
    MySQL
    Go语言
    Go语言
    Go语言
    Go语言
  • 原文地址:https://www.cnblogs.com/anjou/p/8846007.html
Copyright © 2020-2023  润新知