linux下nginx+uwsgi部署python应用

nginx的安装和配置:http://blog.csdn.net/cjh6311882/article/details/7693575

1.获取uwsgi

wget http://projects.unbit.it/downloads/uwsgi-1.0.2.1.tar.gz
2.安装

tar zxvf uwsgi-1.0.2.1.tar.gz
cd uwsgi-1.0.2.1/
python uwsgiconfig.py --build

3.配置

cp nginx/uwsgi_params /usr/local/nginx/conf/
vi /usr/local/nginx/conf/nginx.conf

编辑Nginx配置文件添加,uWSGI监听9090端口:

server {  
	listen 80;  
	root   /var/www/django1.23;  
	index  index.html index.htm;  
	server_name uwsgiadmin.django.obmem.info;  
	access_log  /var/log/nginx/django.access.log;  
	location /media/ {  
		root /var/www/django1.23/adminmedia;  
		rewrite ^/media/(.*)$ /$1 break;  
	}  
	location / {  
		include uwsgi_params;  
		uwsgi_pass 127.0.0.1:9090;  
	}  
}

4.在项目根目录下创建wsgi.py文件:

import os,sys
  
if not os.path.dirname(__file__) in sys.path[:1]:
      sys.path.insert(0, os.path.dirname(__file__))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "workf.settings")
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
5.然后运行uwsgi监听9090,其中-w后跟模块名,也就是刚才配置的wsgi
uwsgi -s :9090 -w myapp 
运行网站发现已经部署完成了。

posted @ 2012-10-16 22:08  jianhong  阅读(305)  评论(0编辑  收藏  举报