<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[nginx下禁止某些ip访问web服务器的配置]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[服务器技术]]></category>
<pubDate>Tue, 28 Dec 2010 02:05:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	nginx的ngx_http_access_module 模块可以用来设置允许/禁止哪些ip或ip段访问，可以设置一个文件内容类似下面的：<br/><div class="code"><br/>deny IP; <br/>deny subnet; <br/>allow IP; <br/>allow subnet; <br/># block all ips <br/>deny&nbsp;&nbsp;&nbsp;&nbsp;all; <br/># allow all ips <br/>allow&nbsp;&nbsp;&nbsp;&nbsp;all;<br/></div><br/>其中网段的写法是这样的：192.168.1.0/24这样的形式。<br/><br/>然后编辑nginx.conf，加入一行： <br/>include blockips.conf;<br/><br/>这样设置以后，该服务器上所有的网站都会按照这个设置来拒绝或允许访问。如果想只针对某个网站，可以在具体的网站的配置中加入： <br/><div class="code"><br/>location / &#123; <br/>&nbsp;&nbsp;allow&nbsp;&nbsp; 192.168.0.0/24; <br/>&nbsp;&nbsp;deny&nbsp;&nbsp;&nbsp;&nbsp;all; <br/>&#125; <br/></div><br/>这样就只允许192.168.0.0网段的ip访问，其他ip访问会返回一个403错误。<br/><br/>还可以自定义一个403错误的页面，可以在/usr/local/nginx/html下新建个error403.html文件，里面按照html的语法写个文档，写上一些说明文字。 <br/>然后编辑nginx.conf，加入： <br/><div class="code"><br/>error_page&nbsp;&nbsp; 403&nbsp;&nbsp;/error403.html; <br/>location = /error403.html &#123; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; root&nbsp;&nbsp; html; <br/>&#125;<br/></div><br/>iptables 参考规则<br/><br/><div class="code">iptables -I INPUT -p tcp –dport 80 -m –mac-soruce$MAC -j DROP</div>基于ｍａｃ地址的<br/><br/><div class="code">iptables -I INPUT -p tcp –dport 80 -s $IP -j DROP</div>基于ｉｐ地址的<br/><br/><br/>Tags - <a href="http://www.dzhope.com/tags/nginx/" rel="tag">nginx</a>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论] nginx下禁止某些ip访问web服务器的配置]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>