<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>XuRui &#187; nginx</title>
	<atom:link href="http://www.xurui.tk/category/nginx/feed" rel="self" type="application/rss+xml" />
	<link>http://www.xurui.tk</link>
	<description></description>
	<lastBuildDate>Mon, 30 Jan 2012 03:45:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>用nginx屏蔽非法信息的url</title>
		<link>http://www.xurui.tk/2011/05/nginx-deny-some-invalid-url.html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nginx-deny-some-invalid-url</link>
		<comments>http://www.xurui.tk/2011/05/nginx-deny-some-invalid-url.html#comments</comments>
		<pubDate>Mon, 16 May 2011 09:46:51 +0000</pubDate>
		<dc:creator>baobaodaren</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[web.py]]></category>
		<category><![CDATA[restful]]></category>
		<category><![CDATA[urlparse]]></category>
		<category><![CDATA[非法]]></category>

		<guid isPermaLink="false">http://daxuxu.info/?p=10020</guid>
		<description><![CDATA[去年写的一个小脚本，当时需求是为了及时屏蔽掉非法信息url，待客服部门确认后，再解封或者继续封锁，免得网监拔线。 这个是最初的脚本，后来写了一个restful服务（web.py写的），便于公司内部客服管理系统使用，restful服务暂时不贴了 在本脚本中利用到python的urlparse方法来提取出链接的uri,这样方便替换： 关于urlparse的用法： 在这里直接粘贴的是ipython的交互式输入输出，各位看官相信也已了然了， In [1]: from urlparse import urlparse In [2]: out = urlparse('http://daxuxu.info/2011/05/nginx-deny-some-invalid-url.html') In [3]: out Out[3]: ParseResult(scheme='http', netloc='daxuxu.info', path='/2011/05/nginx-deny-some-invalid-url.html', params='', query='', fragment='') In [4]: out[0] Out[4]: 'http' In [5]: out[1] Out[5]: 'daxuxu.info' In [6]: out[2] Out[6]: '/2011/05/nginx-deny-some-invalid-url.html' 该功能脚本程序如下： #!/usr/bin/python # coding: UTF-8 #@author: rui.xu &#60;mrhaigui@gmail.com&#62; #Filename: import os import time import [...]]]></description>
			<content:encoded><![CDATA[<p>去年写的一个小脚本，当时需求是为了及时屏蔽掉非法信息url，待客服部门确认后，再解封或者继续封锁，免得网监拔线。<br />
这个是最初的脚本，后来写了一个restful服务（web.py写的），便于公司内部客服管理系统使用，restful服务暂时不贴了<br />
在本脚本中利用到python的urlparse方法来提取出链接的uri,这样方便替换：<br />
关于urlparse的用法：<br />
在这里直接粘贴的是ipython的交互式输入输出，各位看官相信也已了然了，</p>
<pre class="brush: python; title: ;">
In [1]: from urlparse import urlparse
In [2]: out = urlparse('http://daxuxu.info/2011/05/nginx-deny-some-invalid-url.html')

In [3]: out
Out[3]: ParseResult(scheme='http', netloc='daxuxu.info', path='/2011/05/nginx-deny-some-invalid-url.html', params='', query='', fragment='')

In [4]: out[0]
Out[4]: 'http'

In [5]: out[1]
Out[5]: 'daxuxu.info'

In [6]: out[2]
Out[6]: '/2011/05/nginx-deny-some-invalid-url.html'
</pre>
<p>该功能脚本程序如下：</p>
<pre class="brush: python; title: ;">
#!/usr/bin/python
# coding: UTF-8
#@author: rui.xu &lt;mrhaigui@gmail.com&gt;
#Filename:
import os
import time
import datetime
import sys
import re
from urlparse import urlparse

def update_conf(url):
	out= urlparse(url)
	uri=out[2]
	print uri
	#if tryUri(uri):
	#	print &quot;url is illegality&quot;
	#else:
	startTime = time.localtime()
	strStartTime = time.strftime('%Y%m%d%H%M%S', startTime)
	fileName = '/home/xr/url_filter_rest/'+'deny_'+strStartTime+'.conf'
	#fileName = 'deny_'+strStartTime+'.conf'
	f_ng_conf = open(fileName,'w')
	line1_head = 'if ($request_uri = &quot;'
	line1_end = '&quot;){'
	line1=line1_head+uri+line1_end
	#line2 =  '    return 403;'
	line2 = '    rewrite ^ http://www.domain.com/error.html;'
	line3 = '}'
	print line1
	print line2
	print line3
	f_ng_conf.write(line1+&quot;\n&quot;+line2+&quot;\n&quot;+line3+&quot;\n&quot;)
	f_ng_conf.close()
	return fileName

def tryUri(path):
	orc='css|js|css|png|jpeg|jpg|gif'
	if path == '/':
		return True
	if re.search(orc,path):
		print &quot;Match&quot;
		return True
	else:
		print &quot;Not Match&quot;
		return False

def main():
	inputUrl = sys.argv[1]
	update_conf(inputUrl)

if __name__ == '__main__':
	main()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.xurui.tk/2011/05/nginx-deny-some-invalid-url.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>debian时间设置</title>
		<link>http://www.xurui.tk/2010/12/debian_time_setting.html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=debian_time_setting</link>
		<comments>http://www.xurui.tk/2010/12/debian_time_setting.html#comments</comments>
		<pubDate>Thu, 02 Dec 2010 01:18:09 +0000</pubDate>
		<dc:creator>baobaodaren</dc:creator>
				<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://daxuxu.info/?p=192</guid>
		<description><![CDATA[在/etc/timezone里面写上中国的时区，Asia/Shanghai， 在 /etc/default/rcS里面把UTC设成yes，也就是用 utc，这是Debian推荐做法。 最后也是最重要的，把/etc/localtime删除，再从/usr/share/zoneinfo/Asia里面 拷贝Shanghai这个文件到/etc下，名字还是localtime。 这样做完，不需重启，过会就自己生效了。]]></description>
			<content:encoded><![CDATA[<p>在/etc/timezone里面写上中国的时区，Asia/Shanghai，</p>
<p>在 /etc/default/rcS里面把UTC设成yes，也就是用  utc，这是Debian推荐做法。</p>
<p>最后也是最重要的，把/etc/localtime删除，再从/usr/share/zoneinfo/Asia里面  拷贝Shanghai这个文件到/etc下，名字还是localtime。</p>
<p>这样做完，不需重启，过会就自己生效了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.xurui.tk/2010/12/debian_time_setting.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx的内置变量</title>
		<link>http://www.xurui.tk/2010/11/nginx_inner_vars.html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nginx_inner_vars</link>
		<comments>http://www.xurui.tk/2010/11/nginx_inner_vars.html#comments</comments>
		<pubDate>Mon, 29 Nov 2010 06:58:20 +0000</pubDate>
		<dc:creator>baobaodaren</dc:creator>
				<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://daxuxu.info/?p=161</guid>
		<description><![CDATA[HTTP核心模块支持一些内置变量，变量名与apache里的对应。比如 $http_user_agent，$http_cookie等表示HTTP请求信息的变量。 更多变量： $args, 请求中的参数; $content_length, HTTP请求信息里的”Content-Length”; $content_type, 请求信息里的”Content-Type”; $document_root, 针对当前请求的根路径设置值; $document_uri, 与$uri相同; $host, 请求信息中的”Host”，如果请求中没有Host行，则等于设置的服务器名; $limit_rate, 对连接速率的限制; $request_method, 请求的方法，比如”GET”、”POST”等; $remote_addr, 客户端地址; $remote_port, 客户端端口号; $remote_user, 客户端用户名，认证用; $request_filename, 当前请求的文件路径名 $request_body_file, ?? $request_uri, 请求的URI，带参数; $query_string, 与$args相同; $scheme, 所用的协议，比如http或者是https，比如rewrite ^(.+)$ $scheme://example.com$1 redirect; $server_protocol, 请求的协议版本，”HTTP/1.0″或”HTTP/1.1″; $server_addr, 服务器地址，如果没有用listen指明服务器地址，使用这个变量将发起一次系统调用以取得地址(造成资源浪费); $server_name, 请求到达的服务器名; $server_port, 请求到达的服务器端口号; $uri, 请求的URI，可能和最初的值有不同，比如经过重定向之类的。 $request_time 请求处理的时间 $upstream_response_time 后端响应时间]]></description>
			<content:encoded><![CDATA[<p>HTTP核心模块支持一些内置变量，变量名与apache里的对应。比如 $http_user_agent，$http_cookie等表示HTTP请求信息的变量。<br />
更多变量：<br />
<span id="more-161"></span><br />
$args, 请求中的参数;</p>
<p>$content_length, HTTP请求信息里的”Content-Length”;</p>
<p>$content_type, 请求信息里的”Content-Type”;</p>
<p>$document_root, 针对当前请求的根路径设置值;</p>
<p>$document_uri, 与$uri相同;</p>
<p>$host, 请求信息中的”Host”，如果请求中没有Host行，则等于设置的服务器名;</p>
<p>$limit_rate, 对连接速率的限制;</p>
<p>$request_method, 请求的方法，比如”GET”、”POST”等;</p>
<p>$remote_addr, 客户端地址;</p>
<p>$remote_port, 客户端端口号;</p>
<p>$remote_user, 客户端用户名，认证用;</p>
<p>$request_filename, 当前请求的文件路径名</p>
<p>$request_body_file, ??</p>
<p>$request_uri, 请求的URI，带参数;</p>
<p>$query_string, 与$args相同;</p>
<p>$scheme, 所用的协议，比如http或者是https，比如rewrite ^(.+)$ $scheme://example.com$1 redirect;</p>
<p>$server_protocol, 请求的协议版本，”HTTP/1.0″或”HTTP/1.1″;</p>
<p>$server_addr, 服务器地址，如果没有用listen指明服务器地址，使用这个变量将发起一次系统调用以取得地址(造成资源浪费);</p>
<p>$server_name, 请求到达的服务器名;</p>
<p>$server_port, 请求到达的服务器端口号;</p>
<p>$uri, 请求的URI，可能和最初的值有不同，比如经过重定向之类的。</p>
<p>$request_time  请求处理的时间<br />
$upstream_response_time 后端响应时间</p>
]]></content:encoded>
			<wfw:commentRss>http://www.xurui.tk/2010/11/nginx_inner_vars.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>关于nginx的proxy_set_header</title>
		<link>http://www.xurui.tk/2010/11/about_nginx_proxy_set_header.html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=about_nginx_proxy_set_header</link>
		<comments>http://www.xurui.tk/2010/11/about_nginx_proxy_set_header.html#comments</comments>
		<pubDate>Mon, 29 Nov 2010 06:38:34 +0000</pubDate>
		<dc:creator>baobaodaren</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://daxuxu.info/?p=153</guid>
		<description><![CDATA[nginx  proxy_set_header]]></description>
			<content:encoded><![CDATA[<p>上周搭建nginx proxy<br />
出现了莫名的错误：squid收到了错误的请求header<br />
最后这样修改nginx的proxy设置才得以解决</p>
<pre class="brush: bash; title: ;">
proxy_set_header Host $host:80;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.xurui.tk/2010/11/about_nginx_proxy_set_header.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>proxy_temp_path</title>
		<link>http://www.xurui.tk/2010/03/proxy_temp_path.html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=proxy_temp_path</link>
		<comments>http://www.xurui.tk/2010/03/proxy_temp_path.html#comments</comments>
		<pubDate>Mon, 08 Mar 2010 04:42:46 +0000</pubDate>
		<dc:creator>baobaodaren</dc:creator>
				<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://daxuxu.info/?p=88</guid>
		<description><![CDATA[proxy_temp_path syntax: proxy_temp_path dir-path [ level1 [ level2 [ level3 ]  ; default: $NGX_PREFIX/proxy_temp controlled by &#8211;http-proxy-temp-path at ./configure stage context: http, server, location This directive works like client_body_temp_path to specify a location to buffer large proxied requests to the filesystem. 因为业务需要用nginx的proxy_store做了部分图片的cache 但是后来发现proxy_temp_path的目录巨大，这个临时目录当时没有设置2级目录，导致一段时间以后这个目录下文件数量巨多， 这样会照成每次stat目录和find文件都会耗费大量io 改正之： &#8220;proxy_temp_path /data/ngxtemp$date_now 1 2 ;&#8221; 今天在例会中经老大提示，才明白这里也是一个优化的地方， 在这里是没注意这个变量，对nginx配置应该算是很熟悉了，自动化的配置脚本也写过， 就是不敢于去推翻以前的东西，才导致在优化提速的历程中裹足不前。]]></description>
			<content:encoded><![CDATA[<h2>proxy_temp_path</h2>
<p><strong>syntax:</strong> <em>proxy_temp_path dir-path [ level1 [ level2 [ level3  ]     ;</em></p>
<p><strong>default:</strong> <em>$NGX_PREFIX/proxy_temp controlled by  &#8211;http-proxy-temp-path at ./configure stage</em></p>
<p><strong>context:</strong> <em>http, server, location</em></p>
<p>This directive works like <a title="NginxHttpCoreModule" href="http://wiki.nginx.org/NginxHttpCoreModule#client_body_temp_path">client_body_temp_path</a> to specify a  location to buffer large proxied requests to the filesystem.</p>
<p>因为业务需要用nginx的proxy_store做了部分图片的cache</p>
<p>但是后来发现proxy_temp_path的目录巨大，这个临时目录当时没有设置2级目录，导致一段时间以后这个目录下文件数量巨多，</p>
<p><span id="more-88"></span></p>
<p>这样会照成每次stat目录和find文件都会耗费大量io</p>
<p>改正之：</p>
<p>&#8220;proxy_temp_path /data/ngxtemp$date_now 1 2 ;&#8221;</p>
<p>今天在例会中经老大提示，才明白这里也是一个优化的地方，</p>
<p>在这里是没注意这个变量，对nginx配置应该算是很熟悉了，自动化的配置脚本也写过，</p>
<p>就是不敢于去推翻以前的东西，才导致在优化提速的历程中裹足不前。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.xurui.tk/2010/03/proxy_temp_path.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>wp-admin 404的问题</title>
		<link>http://www.xurui.tk/2010/01/wp-admin-404.html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wp-admin-404</link>
		<comments>http://www.xurui.tk/2010/01/wp-admin-404.html#comments</comments>
		<pubDate>Fri, 15 Jan 2010 08:18:28 +0000</pubDate>
		<dc:creator>baobaodaren</dc:creator>
				<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://daxuxu.info/?p=27</guid>
		<description><![CDATA[vps上的原来有LNMP环境（Linux+nginx+Mysql+PHP），因为wuseclub.com跑在上面； WP迅速搭建起来后，决定URL搞成静态化下： wp后台——设置——固定连接 里面可以设置 不过web 服务器要支持rewrite，在nginx中很简单在location{} 中加一段： if (!-f $request_filename){ rewrite (.*) /index.php; } 不过现在是支持静态了，但是wp-admin，管理后台进不去了： 但是输入index.php可以进， 好吧定义下这个wp-admin的规则吧： server{}中加入： location /wp-admin/ { root   /path/to/wordpress; index  index.html index.htm index.php; } 各位看官又没有更好的办法呢？]]></description>
			<content:encoded><![CDATA[<p>vps上的原来有LNMP环境（Linux+nginx+Mysql+PHP），因为wuseclub.com跑在上面；</p>
<p>WP迅速搭建起来后，决定URL搞成静态化下：</p>
<p>wp后台——设置——固定连接 里面可以设置</p>
<p>不过web 服务器要支持rewrite，在nginx中很简单在location{} 中加一段：</p>
<p>if (!-f $request_filename){<br />
rewrite (.*) /index.php;<br />
}</p>
<p>不过现在是支持静态了，但是wp-admin，管理后台进不去了：</p>
<p><span id="more-27"></span></p>
<p>但是输入index.php可以进，</p>
<p>好吧定义下这个wp-admin的规则吧：</p>
<p>server{}中加入：</p>
<p>location /wp-admin/ {<br />
root   /path/to/wordpress;<br />
index  index.html index.htm index.php;<br />
}</p>
<p>各位看官又没有更好的办法呢？</p>
]]></content:encoded>
			<wfw:commentRss>http://www.xurui.tk/2010/01/wp-admin-404.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

