1、Python manage.py runserver 运行服务只适用于测试和开发阶段
生产上一般使用 Django Nginx + uwsgi搭配提供web server
2、Django Nginx + uwsgi原理如下图:
the web client <-> the web server <-> the socket <-> uWSGI <-> Django
3、Django Nginx + uwsgi安装过程(只是简单的安装完,并未对配置进行细化):
1)基础软件安装:python和pip的安装请自行解决或参照总结文档
yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
2)安装uwsgi
pip install uwsgi
uwsgi --version #验证下是否安装成功
3)安装Django
pip install django
4)安装Nginx
wget http://nginx.org/download/nginx-1.5.6.tar.gz
tar xf nginx-1.5.6
cd nginx-1.5.6
./configure --prefix=/usr/local/nginx \
> --with-http_stub_status_module \
> --with-http_gzip_static_module
make && make install
4、uwsgi配置(简单配置项含义参看):http://www.runoob.com/django/django-nginx-uwsgi.html
vim /etc/uwsgi9090.ini
[uwsgi]
socket = 127.0.0.1:9090
master = true
vhost = true
no-site = true
workers = 2
reload-mercy = 10
vacuum = true
max-requests = 1000
limit-as = 512
buffer-size = 30000
pidfile = /var/run/uwsgi9090.pid
daemonize = /tmp/uwsgi9090.log
pythonpath = /usr/local/python3/lib/python3.5/site-packages/
5、Nginx配置(简单配置项含义参看):http://www.runoob.com/django/django-nginx-uwsgi.html
替换了下面配置文件
vim nginx.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9090;
uwsgi_param UWSGI_SCRIPT HelloWorld.wsgi;
uwsgi_param UWSGI_CHDIR /usr/local/src/djangtest/HelloWorld/;
index index.html index.htm;
client_max_body_size 35m;
}
6、启动uwsgi和nginx
uwsgi --ini /etc/uwsgi9090.ini &
/usr/local/nginx/sbin/nginx
netstat -tulpn #查看9090 和 80端口是否正常运行
注:nginx的配置和使用和uwsgi的配置和使用深入的请自行研究,这里只是搭建好
7、浏览器测试访问:http://10.1.8.34