apache 和nginx 的禁止IP 访问设置
2011-07-20 17:33
375 查看
1. httpd/apache
apache 配置此操作还是比较方便,因为 httpd 的默认的主机是配置文件中第一个VirtualHost,所以把第一虚拟主机作为 403 forbidden 的响应更为合适(此前这个默认的是主web服务器)。
修改配置文件如下:
NameVirtualHost *:80
<VirtualHost xxx.xxx.xxx.xxx:80>
ServerName xxx.xxx.xxx.xxx
DocumentRoot /xxx/xxx
<Directory /xxx/xxx >
Order Allow,Deny
Deny from all
</Directory>
</VirtualHost>
--或者----------------
NameVirtualHost *:80
<VirtualHost *:80>
ServerName xxx.xxx.xxx.xxx
<Location / >
Order Allow,Deny
Deny from all
</Location>
</VirtualHost>
两种表示方式一样,第二种方式简单些,不用指定路径了。关键是把第一个虚拟机的服务名字设定为 ip 地址
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. 判定设置是否生效:
[root@test ]# 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.
[root@test ]# 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
apache 配置此操作还是比较方便,因为 httpd 的默认的主机是配置文件中第一个VirtualHost,所以把第一虚拟主机作为 403 forbidden 的响应更为合适(此前这个默认的是主web服务器)。
修改配置文件如下:
NameVirtualHost *:80
<VirtualHost xxx.xxx.xxx.xxx:80>
ServerName xxx.xxx.xxx.xxx
DocumentRoot /xxx/xxx
<Directory /xxx/xxx >
Order Allow,Deny
Deny from all
</Directory>
</VirtualHost>
--或者----------------
NameVirtualHost *:80
<VirtualHost *:80>
ServerName xxx.xxx.xxx.xxx
<Location / >
Order Allow,Deny
Deny from all
</Location>
</VirtualHost>
两种表示方式一样,第二种方式简单些,不用指定路径了。关键是把第一个虚拟机的服务名字设定为 ip 地址
2. nginx
nginx 的设定和httpd类似,都是第一个服务器作为默认的服务器,除非明确指定某个服务器的状态为 defaultserver {
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. 判定设置是否生效:
[root@test ]# 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.
[root@test ]# 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
相关文章推荐
- 如何防恶意解析,禁止用IP访问网站的Apache设置?
- nginx禁止某个IP或者IP段访问站点的设置方法
- nginx上设置禁止通过ip访问服务器,只能通过域名访问
- Apache和Nginx下文件和目录禁止访问安全设置
- 设置nginx禁止IP直接访问,只能通过指定的域名访问
- Apache设置禁止使用IP访问网站的方法
- 设置nginx禁止通过IP访问服务器的方法
- 设置nginx禁止通过IP访问服务器的方法
- 禁止通过ip直接访问网站来防止恶意解析-(apache,nginx,iis)
- nginx禁止某个IP访问站点的设置方法
- nginx与apache限制ip并发访问 限制ip连接的设置方法
- nginx上设置禁止通过ip访问服务器,只能通过域名访问
- 防恶意解析,禁止用IP访问网站的Apache设置
- Nginx设置禁止某个/某段IP访问
- nginx与apache限制ip并发访问 限制ip连接的设置方法
- 防恶意解析,禁止用IP访问网站的Apache设置
- Nginx 安装配置 禁止使用IP访问 rewrite重写 别名设置 日志轮询
- Linux环境下,apache设置禁止恶意域名绑定和直接ip访问方法
- apache设置禁止IP直接访问