安装环境: ubuntu8.04
首先确定有了python的头文件(/usr/include/python2.5),没有的话apt一下:)
sudo apt-get install python2.5-dev
1.nginx安装
$ ./configure --add-module=/path/to/mod_wsgi/ --prefix=/usr/local/nginx
$ make && make install
2.mod_wsgi安装
$ cd mod_wsgi-0.0.6/
$ sudo python setup.py --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf --sbin-path=/usr/local/nginx/sbin
3.打开/usr/local/nginx/conf/nginx.conf
user nobody; #工作进程属主 worker_processes 2; #工作进程,一般的等于CPU核数 daemon off; master_process on; error_log logs/error.log info; pid logs/nginx.pid; events { use epoll; #linux2.6+ worker_connections 1024; # 每个工作进程允许最大的同时连接数 } env HOME; #可以将你的project加入python的sys.path env PYTHONPATH=/path/to/your/project; #解决python执行egg包的权限问题 env PYTHON_EGG_CACHE=/tmp; http { include conf/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_port - $remote_user [$time_local] $request ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; gzip off; #ssl on; #ssl_certificate conf/server.crt; #ssl_certificate_key conf/server.key; wsgi_python_optimize 2; wsgi_python_executable /usr/bin/python; #wsgi_python_home /usr; #wsgi_enable_subinterpreters on; server { listen 80; server_name localhost; include conf/wsgi_vars; #wsgi_middleware wsgiref.validate validator; #wsgi_middleware paste.lint; location / { #client_body_buffer_size 50; #你的 module path 和 WSGI application 的名称,默认是application, 我这里用的是mod_wsgi自带的examples。 wsgi_pass /your/path/to/examples/nginx.py; wsgi_pass_authorization off; wsgi_script_reloading on; wsgi_use_main_interpreter on; } location /wsgi { #client_body_buffer_size 50; wsgi_var TEST test; wsgi_var FOO bar; wsgi_var EMPTY ""; # override existing HTTP_ variables wsgi_var HTTP_USER_AGENT "nginx"; wsgi_var HTTP_COOKIE $http_cookie; wsgi_pass /your/path/to/examples/nginx-2.py main; wsgi_pass_authorization on; wsgi_script_reloading off; wsgi_use_main_interpreter on; } } }
4.启动nginx:
$ cd /usr/local/nginx
$ sudo sbin/nginx -c conf/nginx.conf
5.打开浏览器,输入http://127.0.0.1/wsgi/ 输出如下内容:
Environment:
{'FOO': 'bar',
'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_CHARSET': 'gb2312,utf-8;q=0.7,*;q=0.7',
'HTTP_ACCEPT_ENCODING': 'gzip,deflate',
'HTTP_ACCEPT_LANGUAGE': 'zh-cn,zh;q=0.5',
'HTTP_CONNECTION': 'keep-alive',
'HTTP_HOST': '127.0.0.1',
'HTTP_KEEP_ALIVE': '300',
'HTTP_USER_AGENT': 'nginx',
'PATH_INFO': '/',
'SCRIPT_NAME': '/wsgi',
'TEST': 'test',
'wsgi.errors':
'wsgi.input':
'wsgi.multiprocess': True,
'wsgi.multithread': False,
'wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0)}
sys.argv:
sbin/nginx
-c
conf/nginx.conf
sys.path:
/usr/local/nginx/sbin
/usr/lib/python2.5/site-packages/ipython-0.8.4-py2.5.egg
/usr/lib/python2.5/site-packages/flup-1.0-py2.5.egg
/usr/lib/python2.5/site-packages/DBUtils-0.9.4-py2.5.egg
/usr/lib/python2.5/site-packages/zope.interface-3.4.1-py2.5-linux-i686.egg
/usr/lib/python2.5/site-packages/mercurial-1.0.1-py2.5-linux-i686.egg
/usr/lib/python2.5/site-packages/python_memcached-1.43-py2.5.egg
/usr/lib/python2.5/site-packages/bsddb3-4.7.1-py2.5-linux-i686.egg
/home/bob/projects/passport/trunk/country_cn/apps
/usr/lib/python25.zip
/usr/lib/python2.5
/usr/lib/python2.5/plat-linux2
/usr/lib/python2.5/lib-tk
/usr/lib/python2.5/lib-dynload
/usr/local/lib/python2.5/site-packages
/usr/lib/python2.5/site-packages
/usr/lib/python2.5/site-packages/Numeric
/usr/lib/python2.5/site-packages/PIL
/usr/lib/python2.5/site-packages/gst-0.10
/var/lib/python-support/python2.5
/usr/lib/python2.5/site-packages/gtk-2.0
/var/lib/python-support/python2.5/gtk-2.0
/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode
sys.stderr:
pid:
6384