nginx下禁止某些ip访问web服务器的配置
2012-10-29 16:14
429 查看
nginx的ngx_http_access_module 模块可以用来设置允许/禁止哪些ip或ip段访问,可以设置一个文件内容类似下面的:
deny IP;
deny subnet;
allow IP;
allow subnet;
# block all ips
deny all;
# allow all ips
allow all;
其中网段的写法是这样的:192.168.1.0/24这样的形式。
然后编辑nginx.conf,加入一行:
include blockips.conf;
这样设置以后,该服务器上所有的网站都会按照这个设置来拒绝或允许访问。如果想只针对某个网站,可以在具体的网站的配置中加入:
location / {
allow 192.168.0.0/24;
deny all;
}
这样就只允许192.168.0.0网段的ip访问,其他ip访问会返回一个403错误。
如果写多个deny 需要一个一个的写
还可以自定义一个403错误的页面,可以在/usr/local/nginx/html下新建个error403.html文件,里面按照html的语法写个文档,写上一些说明文字。
然后编辑nginx.conf,加入:
error_page 403 /error403.html;
location = /error403.html {
root html;
}
deny IP;
deny subnet;
allow IP;
allow subnet;
# block all ips
deny all;
# allow all ips
allow all;
其中网段的写法是这样的:192.168.1.0/24这样的形式。
然后编辑nginx.conf,加入一行:
include blockips.conf;
这样设置以后,该服务器上所有的网站都会按照这个设置来拒绝或允许访问。如果想只针对某个网站,可以在具体的网站的配置中加入:
location / {
allow 192.168.0.0/24;
deny all;
}
这样就只允许192.168.0.0网段的ip访问,其他ip访问会返回一个403错误。
如果写多个deny 需要一个一个的写
还可以自定义一个403错误的页面,可以在/usr/local/nginx/html下新建个error403.html文件,里面按照html的语法写个文档,写上一些说明文字。
然后编辑nginx.conf,加入:
error_page 403 /error403.html;
location = /error403.html {
root html;
}
相关文章推荐
- 配置Nginx防止直接用IP访问Web服务器
- Nginx 禁止直接使用IP或未绑定的域名访问Web服务器
- nginx 禁止ip直接访问web服务器
- 配置Nginx防止直接用IP访问Web服务器
- 配置Nginx防止直接用IP访问Web服务器
- nginx上设置禁止通过ip访问服务器,只能通过域名访问
- 在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解
- Nginx禁止通过IP,未绑定域名访问服务器
- Nginx禁止通过IP,未绑定域名访问服务器
- nginx配置实例:只允许内部IP访问 禁止外部访问
- Nginx 安装配置 禁止使用IP访问 rewrite重写 别名设置 日志轮询
- 在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解
- apache环境下web站点禁止用服务器ip访问
- Nginx防止直接用IP访问Web服务器的设置方法
- nginx反向代理后web服务器显示真实访问IP
- Nginx设置禁止通过IP访问服务器并且只能通过指定域名访问
- nginx配置禁止ip访问,只能域名访问
- apache配置,禁止ip访问web站点
- Nginx禁止通过IP,未绑定域名访问服务器
- 在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解