需要在nginx.conf中增加以下片段,然后重启nginx服务即可
# 禁止通过ip地址访问 http服务
server {
listen 80 default_server;
server_name _;
return 400;
}
# 禁止通过ip地址访问https服务
server {
listen 443 ssl default_server;
ssl_certificate xxx.xxx.com.pem;
ssl_certificate_key xxx.xxx.com.key;
server_name _;
return 400;
}
nginx 禁止通过IP地址访问,只能通过域名访问
最新推荐文章于 2024-07-22 09:44:28 发布
该博客介绍了如何在Nginx配置文件中添加规则,以禁止通过IP地址直接访问HTTP和HTTPS服务,返回400错误码,增强服务器安全性。


5684

被折叠的 条评论
为什么被折叠?



