apache 和nginx 的禁止IP 访问设置
1. httpd/apacheapache 配置此操作还是比较方便,因为 httpd 的默认的主机是配置文件中第一个VirtualHost,所以把第一虚拟主机作为 403 forbidden 的响应更为合适(此前这个默认的是主web服务器)。
修改配置文件如下:
NameVirtualHost *:80
ServerName xxx.xxx.xxx.xxx
DocumentRoot /xxx/xxx
Order Allow,Deny
Deny from all
--或者----------------
NameVirtualHost *:80
ServerName xxx.xxx.xxx.xxx
Order Allow,Deny
Deny from all
两种表示方式一样,第二种方式简单些,不用指定路径了。关键是把第一个虚拟机的服务名字设定为 ip 地址
2. nginx
nginx 的设定和httpd类似,都是第一个服务器作为默认的服务器,除非明确指定某个服务器的状态为 default
server {
listen 80 default;
server_name _;
location / {
root html;
index 403.html;
}
location ~ //.ht {
deny all;
}
}
有时我们并不希望客户端收到403的禁止信息,可能404更有迷惑性,则可以如下设置:
server {
listen 80 default;
server_name _;
location / {
root html;
#index 403.html;
return 404;
}
location ~ //.ht {
deny all;
}
}
3. 判定设置是否生效:
# wget http://xxx.xx.xxx.11
--11:07:17-- http://xxx.xx.xxx.11/
Connecting to xxx.xx.xxx.11:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
11:07:17 ERROR 403: Forbidden.
# wget http://xxx.xx.xxx.22
--11:06:46-- http://xxx.xx.xxx.22/
Connecting to xxx.xx.xxx.22:80... connected.
HTTP request sent, awaiting response... 400 Bad Request
11:06:46 ERROR 400: Bad Request.
OK
页:
[1]