• 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 的内容:

  • 相关阅读:
    文件上传、下载测试点总结
    selenium+Python(Page Object 设计模式实例)
    Python面向对象
    Python内置函数
    Python异常处理
    Python文件的I/o
    vue-router 二级路由
    vue中如何获取后台数据
    移动端适配问题
    vue中钩子函数的用法
  • 原文地址:https://www.cnblogs.com/anjou/p/8846007.html
Copyright © 2020-2023  润新知