惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
宝玉的分享
宝玉的分享
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
量子位
Blog — PlanetScale
Blog — PlanetScale
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
D
Docker
罗磊的独立博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
IT之家
IT之家
MyScale Blog
MyScale Blog
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - 大豆男生

C# 和 OpenResty 中进行 CRC32 Linq分组后,再对分组后的每组数据进行排序,获取每组的第一条记录 WebClient 指定安全协议(Tls1.1,Tls1.2,Tls1.3) .Net Core 中的 MurmurHash VS2019 .Net Core 3.0 Web 项目启用动态编译 IIS 上部署 ASP.NET Core 应用程序 IIS (安装SSL证书后) 实现 HTTP 自动跳转到 HTTPS 使用浏览器自定义协议启动本地程序(.EXE文件) 再谈 C# 对象二进制序列化,序列化并进行 AES 加密 腾讯防水墙(滑动验证码)的简单使用 https://007.qq.com C# 使用 PerformanceCounter 获取 CPU 和 硬盘的使用率 .Net 控制台中文(简体/繁体)乱码问题 .Net Core 使用 System.Drawing.Common 部署到CentOS上遇到的问题 .Net Core 读取配置文件 appsettings.json JavaScript 获取按键,并屏蔽系统 Window 事件 frp 初探 .NET MVC JSON JavaScriptSerializer 字符串的长度超过 maxJsonLength 值问题的解决 async,await,Task 的一些用法 Newtonsoft.Json(Json.net) 的使用
nginx 禁止未绑定的域名访问
大豆男生 · 2018-04-15 · via 博客园 - 大豆男生

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