“nginx”目录存档

用nginx屏蔽非法信息的url

2011年05月16日,星期一

去年写的一个小脚本,当时需求是为了及时屏蔽掉非法信息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 <mrhaigui@gmail.com>
#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 "url is illegality"
	#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 = "'
	line1_end = '"){'
	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+"\n"+line2+"\n"+line3+"\n")
	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 "Match"
		return True
	else:
		print "Not Match"
		return False

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

if __name__ == '__main__':
	main()

debian时间设置

2010年12月2日,星期四

在/etc/timezone里面写上中国的时区,Asia/Shanghai,

在 /etc/default/rcS里面把UTC设成yes,也就是用 utc,这是Debian推荐做法。

最后也是最重要的,把/etc/localtime删除,再从/usr/share/zoneinfo/Asia里面 拷贝Shanghai这个文件到/etc下,名字还是localtime。

这样做完,不需重启,过会就自己生效了。

nginx的内置变量

2010年11月29日,星期一

HTTP核心模块支持一些内置变量,变量名与apache里的对应。比如 $http_user_agent,$http_cookie等表示HTTP请求信息的变量。
更多变量:
(全文 …)

关于nginx的proxy_set_header

2010年11月29日,星期一

上周搭建nginx proxy
出现了莫名的错误:squid收到了错误的请求header
最后这样修改nginx的proxy设置才得以解决

proxy_set_header Host $host:80;

proxy_temp_path

2010年03月8日,星期一

proxy_temp_path

syntax: proxy_temp_path dir-path [ level1 [ level2 [ level3 ]  ;

default: $NGX_PREFIX/proxy_temp controlled by –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级目录,导致一段时间以后这个目录下文件数量巨多,

(全文 …)

wp-admin 404的问题

2010年01月15日,星期五

vps上的原来有LNMP环境(Linux+nginx+Mysql+PHP),因为wuseclub.com跑在上面;

WP迅速搭建起来后,决定URL搞成静态化下:

wp后台——设置——固定连接 里面可以设置

不过web 服务器要支持rewrite,在nginx中很简单在location{} 中加一段:

if (!-f $request_filename){
rewrite (.*) /index.php;
}

不过现在是支持静态了,但是wp-admin,管理后台进不去了:

(全文 …)