<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Heck's  Blog]]></title> 
<link>https://www.heckjj.com/index.php</link> 
<description><![CDATA[一瞬间的决定，往往可以改变很多，事实上，让自己成功的往往不是知识，是精神！ 如果你总是为自己找借口，那只好让成功推迟。执行力，今天！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Heck's  Blog]]></copyright>
<item>
<link>https://www.heckjj.com/nginx-normal-filter-html/</link>
<title><![CDATA[nginx常用的请求过滤]]></title> 
<author>Heck &lt;@hecks.tk&gt;</author>
<category><![CDATA[编程杂谈]]></category>
<pubDate>Sun, 26 Sep 2010 03:01:45 +0000</pubDate> 
<guid>https://www.heckjj.com/nginx-normal-filter-html/</guid> 
<description>
<![CDATA[ 
	<span style="font-family: 微软雅黑;"><strong><span style="color: #4169E1;">以下为字符串匹配操作符：</span></strong><br/>~&nbsp;&nbsp;为区分大小写匹配<br/>~* 为不区分大小写匹配<br/>!~和!~*分别为区分大小写不匹配及不区分大小写不匹配<br/><br/><strong><span style="color: #4169E1;">1: 限制某些类型的客户端的访问</span></strong></span><br/><textarea name="code" class="python" rows="15" cols="100"> 
location / &#123;
if ($http_user_agent ~ MSIE) &#123;
return 503;
&nbsp;&nbsp;&#125;
&#125;#限制IE访问
</textarea><span style="font-family: 微软雅黑;">如果把MSIE改成 Mozilla 就基本上把IE和firefox这样pc浏览器限制了<br/>2和3主要是针对盗链做处理</span><br/><br/><span style="font-family: 微软雅黑;"><strong><span style="color: #4169E1;">2:针对不同的文件类型</span></strong></span><textarea name="code" class="python" rows="15" cols="100"> 
location ~ .*&#92;.(wma&#124;wmv&#124;asf&#124;mp3&#124;mmf&#124;zip&#124;rar&#124;jpg&#124;gif&#124;png&#124;swf&#124;flv)$ &#123;
&nbsp;&nbsp;&nbsp;&nbsp; if ($http_referer ~* hecks.tk) &#123;
&nbsp;&nbsp;&nbsp;&nbsp; #rewrite ^/ http://www.hecks.tk/403.html;
&nbsp;&nbsp;&nbsp;&nbsp; return 403;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&#125;
</textarea><span style="font-family: 微软雅黑;"><br/><strong><span style="color: #4169E1;">3:针对不同的目录</span></strong></span><textarea name="code" class="python" rows="15" cols="100"> 
location /img/ &#123;
&nbsp;&nbsp;&nbsp;&nbsp;root /data/img/;
&nbsp;&nbsp; if ($http_referer ~* hecks.tk) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rewrite&nbsp;&nbsp;^/&nbsp;&nbsp;http://www.hecks.tk/images/error.gif
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #return&nbsp;&nbsp; 403;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&#125;</textarea><br/><span style="font-family: 微软雅黑;"><br/><strong><span style="color: #4169E1;">另外的一个nginx配置例子</span></strong><br/><br/>worker_processes 2; #工作进程数，在网上看到说最优是cpu的二倍</span><textarea name="code" class="python" rows="15" cols="100">
error_log&nbsp;&nbsp; current_path/log/nginx.error.log debug;
pid&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shared_path/pids/nginx.pid;

events &#123;
&nbsp;&nbsp;worker_connections 1024;#最大连接数
&#125;

http &#123;
&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /usr/local/nginx/conf/mime.types;#content type 文件
&nbsp;&nbsp;default_type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;application/octet-stream;

&nbsp;&nbsp;log_format&nbsp;&nbsp;main&nbsp;&nbsp;&#039;$remote_addr - $remote_user [$time_local] $status &#039;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;&quot;$request&quot; $body_bytes_sent &quot;$http_referer&quot; &#039;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;&#039;;

&nbsp;&nbsp;access_log&nbsp;&nbsp;current_path/log/nginx.access.log main;#log文件存放地方

&nbsp;&nbsp;sendfile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on;
&nbsp;&nbsp;tcp_nopush&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on;
&nbsp;&nbsp;tcp_nodelay&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; on;
&nbsp;&nbsp;keepalive_timeout 70;

&nbsp;&nbsp;gzip&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on;
&nbsp;&nbsp;gzip_min_length&nbsp;&nbsp; 1000;
&nbsp;&nbsp;gzip_buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4 8k;
&nbsp;&nbsp;gzip_comp_level&nbsp;&nbsp; 9;
&nbsp;&nbsp;gzip_proxied&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;any;
&nbsp;&nbsp;gzip_types&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;application/xml application/javascript application/x-javascript application/atom+xml application/rss+xml;
&nbsp;&nbsp;gzip_types&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text/css text/html text/javascript text/js text/plain text/xml;

&nbsp;&nbsp;upstream mongrel &#123;#proxy 负载均衡配置
&nbsp;&nbsp;&nbsp;&nbsp;server 127.0.0.1:8000;#服务器1
&nbsp;&nbsp;&nbsp;&nbsp;server 127.0.0.1:8001;#服务器2
&nbsp;&nbsp;&#125;

&nbsp;&nbsp;server &#123;
&nbsp;&nbsp;&nbsp;&nbsp;listen 80;
&nbsp;&nbsp;&nbsp;&nbsp;server_name hecks.tk www.hecks.tk;
&nbsp;&nbsp;&nbsp;&nbsp;root current_path/public;
&nbsp;&nbsp;&nbsp;&nbsp;index index.html index.htm;

&nbsp;&nbsp;&nbsp;&nbsp;location / &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_set_header&nbsp;&nbsp;X-Real-IP&nbsp;&nbsp;$remote_addr;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_set_header&nbsp;&nbsp;X-Forwarded-For $proxy_add_x_forwarded_for;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_set_header Host &quot;www.hecks.tk&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_redirect false;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_max_temp_file_size 0;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# rewrite &#039;hecks.tk&#039; -&gt; &#039;www.hecks.tk&#039;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($host = &#039;hecks.tk&#039; ) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rewrite&nbsp;&nbsp;^/(.*)$&nbsp;&nbsp;http://www.hecks.tk/$1&nbsp;&nbsp;permanent;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp; #如果静态文件存在服务器，则跳过rewrite规则
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (-f $request_filename) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expires max;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# redirect feed requests to feedburner, unless its the feedburner agent
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($http_user_agent !~ FeedBurner) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rewrite ^/feed/atom.xml$ http://feeds.feedburner.com/hecks;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (-f $request_filename/index.html) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expires 7d;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rewrite (.*) $1/index.html break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# support rails page caching
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (-f $request_filename.html) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rewrite (.*) $1.html break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# pass it onto upstream mongrel cluster
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!-f $request_filename) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_pass http://www.hecks.tk;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;

&nbsp;&nbsp;&nbsp;&nbsp;location ~* ^.+&#92;.(jpg&#124;jpeg&#124;gif&#124;png&#124;ico&#124;css&#124;zip&#124;tgz&#124;gz&#124;rar&#124;bz2&#124;doc&#124;xls&#124;exe&#124;pdf&#124;ppt&#124;txt&#124;tar&#124;mid&#124;midi&#124;wav&#124;bmp&#124;rtf&#124;js&#124;mov).*?$ &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root current_path/public;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!-f $request_filename) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proxy_pass http://www.hecks.tk;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;error_page 500 502 503 504 /50x.html;
&nbsp;&nbsp;&nbsp;&nbsp;location = /50x.html &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root current_path/public;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&#125;
&#125;</textarea><br/>Tags - <a href="https://www.heckjj.com/tags/nginx/" rel="tag">nginx</a>
]]>
</description>
</item><item>
<link>https://www.heckjj.com/nginx-normal-filter-html/#blogcomment</link>
<title><![CDATA[[评论] nginx常用的请求过滤]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://www.heckjj.com/nginx-normal-filter-html/#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>