配置 python(django)+nginx+uwsgi
2011-12-23 14:01
766 查看
uWSGI is a fast, self-healing and developer/sysadmin-friendly application container server coded in pure C。
先到官网下载所需软件
下载uwsgi
http://wiki.nginx.org/Install
下载django
https://www.djangoproject.com/download/
1、安装uwsgi
系统必须先安装libxml2-dev python-dev
ubuntu下
centOS
下面就可以安装uwsgi
2、配置
1)打开nginx配置文件
2)在django项目主目录下创建 django_wsgi.py
3)在django项目主目录下创建 django.xml
接下来运行
OK,输入127.0.0.1就能看到 django worked!
不过每次重启服务器都需要输上面那行代码比较麻烦,可以将代码复制到 /etc/init.d/rc.local ,这样开机就自动启动
从网上找了段代码也可以试试,或者将下面代码copy到 /etc/init.d/uwsgi
先到官网下载所需软件
下载uwsgi
wget http://projects.unbit.it/downloads/uwsgi-0.9.9.3.tar.gz下载nginx(>0.8)
http://wiki.nginx.org/Install
下载django
https://www.djangoproject.com/download/
1、安装uwsgi
系统必须先安装libxml2-dev python-dev
ubuntu下
sudo apt-get libxml2-dev python-dev
centOS
yum -i libxml2-devel python-devel
下面就可以安装uwsgi
tar zxvf uwsgi-0.9.9.2.tar.gz cd uwsgi-0.9.9.2 make -f Makefile.Py26 #和你安装PYTHON版本一致 cp uwsgi /usr/sbin/uwsgi
2、配置
1)打开nginx配置文件
server { listen 80; server_name example.com; access_log /var/log/nginx/example.com-access.log ; error_log /var/log/nginx/example.com-error.log ; location / { uwsgi_pass 127.0.0.1:3031; include uwsgi_params; } }
2)在django项目主目录下创建 django_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['DJANGO_SETTINGS_MODULE'] = 'settings' from django.core.handlers.wsgi import WSGIHandler application = WSGIHandler()
3)在django项目主目录下创建 django.xml
<uwsgi> <socket>127.0.0.1:3031</socket> <chdir>/home/hysia/website/blog</chdir> <pythonpath>..</pythonpath> <module>wsgi</module> <daemonize>/var/log/uwsgi/uwsgi.log</daemonize> </uwsgi>
接下来运行
uwsgi -x /home/example/django.xml
OK,输入127.0.0.1就能看到 django worked!
不过每次重启服务器都需要输上面那行代码比较麻烦,可以将代码复制到 /etc/init.d/rc.local ,这样开机就自动启动
从网上找了段代码也可以试试,或者将下面代码copy到 /etc/init.d/uwsgi
#!/bin/bash PORT=3031 PROCESSES=4 LOG=/var/log/uwsgi PID=`pidof -o %PPID /usr/bin/uwsgi` . /etc/rc.conf . /etc/rc.d/functions case "$1" in start) stat_busy "Starting uwsgi" if [ -n "$PID" ]; then stat_busy "uwsgi is already running" stat_die else uwsgi -s ":$PORT" -M -p $PROCESSES -d $LOG &> /dev/null add_daemon uwsgi stat_done fi ;; stop) stat_busy "Stopping uwsgi" killall -QUIT uwsgi &> /dev/null rm_daemon uwsgi stat_done ;; restart) $0 stop sleep 1 $0 start ;; *) echo "usage: $0 {start|stop|restart}" esac exit 0
相关文章推荐
- 在Debian下配置Python+Django+Nginx+uWSGI+MySQL的教程
- Ubuntu 上配置Python3 + django + Nginx + uwsgi
- Python-Django Nginx+uwsgi 安装配置
- python+uwsgi+django+nginx配置与…
- centos7 nginx配置httpsCenos(6.6/7.1)下从源码安装Python+Django+uwsgi+nginx环境部署(二)
- Debian环境 Python + Django + Nginx + uWSGI + MySQL 配置备忘
- python Django Nginx+ uWSGI 安装配置
- Debian环境 Python + Django + Nginx + uWSGI + MySQL 配置
- Nginx+Python+uwsgi+Django的web开发环境安装及配置
- ubuntu初始化python3+postgresql+uwsgi+nginx+django
- 快速部署Python应用:Nginx+uWSGI配置详解
- 转:配置Nginx+uwsgi更方便地部署python应用
- linux+nginx+python+django环境配置
- django+nginx+uwsgi 部署配置
- Nginx + uWSGI + Django 配置
- Django Nginx+uwsgi 安装配置
- linux+nginx+python+django环境配置
- nginx + django + uwsgi 安装配置
- python3环境搭建(uWSGI+django+nginx+python+MySQL)
- 转一篇NGINX+UWSGI+PYTHON+DJANGO部署文档