<?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>泛城科技技术博客python &#187; 泛城科技技术博客</title>
	<atom:link href="http://tech.lezi.com/archives/tag/python/feed" rel="self" type="application/rss+xml" />
	<link>http://tech.lezi.com</link>
	<description></description>
	<lastBuildDate>Fri, 04 Jan 2013 09:18:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>用python flup调试nginx fastcgi配置错误造成404的问题</title>
		<link>http://tech.lezi.com/archives/238</link>
		<comments>http://tech.lezi.com/archives/238#comments</comments>
		<pubDate>Tue, 27 Sep 2011 08:16:34 +0000</pubDate>
		<dc:creator>neilxp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[flup]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://tech.lezi.com/?p=238</guid>
		<description><![CDATA[最近几年php服务器都倾向于使用nginx+fastcgi/php-fpm。 但是配置nginx fastcgi遇到最棘手的问题，就是配置失败时，没有调试手段，不知道哪里有错误，怎么去修改nginx的配置。以前都是盲目尝试，直至配置成功。费时，没有线索。 特别是fastcgi有一堆变量，例如SCRIPT_FILENAME、PATH_INFO、QUERY_STRING、DOCUMENT_URI，如果在配置失败时能看到这些变量的值，对调整配置文件是很有指导意义的。 发现python的flup库有fastcgi的协议解析。用它写了一个小工具，能够打印出fastcgi的所有参数，方便诊断问题。flup的安装不介绍了，脚本内容如下： #!/bin/env python def myapp(environ, start_response): r = '' for x in environ: r+="%s\t%s\n" % (x, environ[x]) print r start_response('200 OK', [('Content-Type', 'text/plain')]) return ['Hello World!\n'] if __name__ == '__main__': from flup.server.fcgi import WSGIServer WSGIServer(myapp,bindAddress=('0.0.0.0', 9999)).run() 使用 用python 前台运行这个脚本 将你的nginx配置里面fastcgi_pass 改成9999端口，重启nginx。 用浏览器触发一个到nginx fastcgi路径的请求 这时python的终端会打印出所有的fastcgi参数 [jw@localhost sk]$ python fastcgi-debug.py wsgi.multiprocess False HTTP_COOKIE [...]]]></description>
			<content:encoded><![CDATA[<p>最近几年php服务器都倾向于使用nginx+fastcgi/php-fpm。</p>
<p>但是配置nginx fastcgi遇到最棘手的问题，就是配置失败时，没有调试手段，不知道哪里有错误，怎么去修改nginx的配置。以前都是盲目尝试，直至配置成功。费时，没有线索。</p>
<p>特别是fastcgi有一堆变量，例如SCRIPT_FILENAME、PATH_INFO、QUERY_STRING、DOCUMENT_URI，如果在配置失败时能看到这些变量的值，对调整配置文件是很有指导意义的。</p>
<p><span id="more-238"></span></p>
<p>发现python的flup库有fastcgi的协议解析。用它写了一个小工具，能够打印出fastcgi的所有参数，方便诊断问题。flup的安装不介绍了，脚本内容如下：</p>
<pre class="brush:python">#!/bin/env python
def myapp(environ, start_response):
    r = ''
    for x in environ:
        r+="%s\t%s\n" % (x, environ[x])
    print r
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return ['Hello World!\n']

if __name__ == '__main__':
    from flup.server.fcgi import WSGIServer
    WSGIServer(myapp,bindAddress=('0.0.0.0', 9999)).run()</pre>
<p>使用</p>
<ol>
<li>用python 前台运行这个脚本</li>
<li>将你的nginx配置里面fastcgi_pass 改成9999端口，重启nginx。</li>
<li>用浏览器触发一个到nginx fastcgi路径的请求</li>
</ol>
<p>这时python的终端会打印出所有的fastcgi参数</p>
<pre class="brush:bash">[jw@localhost sk]$ python fastcgi-debug.py
wsgi.multiprocess	False
HTTP_COOKIE	vvsid=msaI0VbycTSLWFLF0zKmvRZA; orderby=time; last_login=neilxp
REDIRECT_STATUS	200
SERVER_SOFTWARE	nginx/1.0.4
SCRIPT_NAME	index.php
REQUEST_METHOD	GET
PATH_INFO	/xhprof/index.php
SERVER_PROTOCOL	HTTP/1.1
QUERY_STRING
CONTENT_LENGTH
HTTP_ACCEPT_CHARSET	ISO-8859-1,utf-8;q=0.7,*;q=0.3
HTTP_USER_AGENT	Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1
HTTP_CONNECTION	keep-alive
SERVER_NAME	127.0.0.1
REMOTE_PORT	1309
wsgi.url_scheme	http
SERVER_PORT	80
SERVER_ADDR	192.168.7.114
DOCUMENT_ROOT	/home/www/nginx/html
SCRIPT_FILENAME	/home/www/xhprof_html/index.php
DOCUMENT_URI	/xhprof/index.php
wsgi.input
HTTP_HOST	192.168.7.114
wsgi.multithread	True
HTTP_CACHE_CONTROL	max-age=0
REQUEST_URI	/xhprof/index.php
HTTP_ACCEPT	text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
wsgi.version	(1, 0)
GATEWAY_INTERFACE	CGI/1.1
wsgi.run_once	False
wsgi.errors
REMOTE_ADDR	192.168.7.101
HTTP_ACCEPT_LANGUAGE	de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
CONTENT_TYPE
HTTP_ACCEPT_ENCODING	gzip,deflate,sdch</pre>

	<h2>您也许会对以下文章感兴趣</h2>
	<ul class="st-related-posts">
	<li>No related posts.</li>
	</ul>

]]></content:encoded>
			<wfw:commentRss>http://tech.lezi.com/archives/238/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
