nginx 配置禁止IP 访问网站

9年前 ( 07-06 ) 3641阅读 0评论
这篇文章最后更新于3214天前,您需要注意相关的内容是否还可用,如有疑问请联系作者!

由于国内备案严格要求。很多童鞋都不会设置

在这里我 把我的实战过程分享给大家

错误一:

QQ截图20150706155742.jpg
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
[root@localhost conf]# /usr/local/nginx/sbin/nginx -s reload
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
[root@localhost conf]# /usr/local/nginx/sbin/nginx -s reload
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
[root@localhost conf]# /usr/local/nginx/sbin/nginx -s reload
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
[root@localhost conf]# /usr/local/nginx/sbin/nginx -s stop
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
重启nginx  或者停止都报错  

解决办法:

  /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

即可修复

然后使用  /usr/local/nginx/sbin/nginx -s reload

平滑重启nginx

 问题2:禁止IP 空主机头直接打开网站

方法

打开 nginx.conf

vi /usr/local/nginx/conf/nginx.conf  

找到http  段

在开头加入

server {
listen 80 default_server;
server_name _;
return 444;
}


即可实现 禁止未绑定域名解析的解析访问问  。


文章版权声明:除非注明,否则均为IT技术交流分享 IDC管理计费系统 私有云管理系统 PVE管理系统 私有云系统原创文章,转载或复制请以超链接形式并注明出处。
取消
支付宝二维码
支付宝二维码
微信二维码