概述:
百度一下,基本就知道部署需要安装哪些东西了。部署的整个过程其实不复杂,容易搞不明白的是,配置的路径怎么填写。因为很多帖子写的都是某某 demo 路径,非全路径,按照帖子配置往往跑不起来。
参考帖子:
原理(图片引用于:Nginx+uWSGI+Django原理)
uwsgi 部署
工程所在目录
/home/python/xox_server_mgr
工程配置完成后的文件目录:
[root@server python]# tree xox_server_mgr/ -L 2
xox_server_mgr/
├── manage.py
└── xox_server_mgr
├── __init__.py
├── resources
├── settings.py
├── templates
├── urls.py
├── uwsgi.ini
├── uwsgi.log
├── uwsgi.pid
├── views.py
├── wsgi.py
uwsgi 命令
启动:
uwsgi --ini uwsgi.ini
停止:
uwsgi --stop uwsgi.pid
重新加载配置:
uwsgi --reload uwsgi.pid
uwsgi.ini 配置
[uwsgi]
chdir=/home/python/xox_server_mgr
module=xox_server_mgr.wsgi:application
socket = 192.168.1.163:9000
master=true
workers=2
pidfile=/home/python/xox_server_mgr/xox_server_mgr/uwsgi.pid
vacuum=true
thunder-lock=true
enable-threads=true
harakiri=30
post-buffering=4096
daemonize=/home/python/xox_server_mgr/xox_server_mgr/uwsgi.log
wsgi.py
# # -*- coding: utf-8 -*-
import os
import sys
reload(sys)
sys.setdefaultencoding('utf8')
root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, root_path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xox_server_mgr.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
nginx 部署
nginx 相关命令
启动:/etc/init.d/nginx start
停止:/etc/init.d/nginx stop
重新加载配置:
nginx -s reload
[root@server etc]# tree /etc/nginx/
/etc/nginx/
├── conf.d
│ ├── default.conf
│ ├── ssl.conf
│ └── virtual.conf
├── default.d
│ └── default.conf
nginx 配置文件内容
/etc/nginx/default.d/default.conf
/etc/nginx/default.d 该目录是 nginx 的子配置目录,如果没有配置文件,得新建一个 *.conf 文件,填充下面内容。
server_name 192.168.1.163;
#uwsgi 配置
location / {
include uwsgi_params;
uwsgi_pass 192.168.1.163:9000;
}
#缓存资源文件
location ~ .*.(gif|jpg|png|htm|html|css|js|flv|ico|swf)(.*) {
root /home/python/xox_server_mgr/xox_server_mgr/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_cache_valid 200 302 1h;
proxy_cache_valid 301 1d;
proxy_cache_valid any 1m;
expires 30d;
}
运行 uwsgi:
cd /home/python/xox_server_mgr/xox_server_mgr/
uwsgi --ini uwsgi.ini
错误日志:
/home/python/xox_server_mgr/xox_server_mgr/uwsgi.log
运行 nginx:
/etc/init.d/nginx start
错误日志:
根据 nginx.conf 查看错误日志路径,通过该文件查看错误内容。
跑起来了^_^
nginx 默认的 http 端口是
80

本文详细介绍了使用Django搭配Nginx和uWSGI进行实际部署的过程,包括配置文件示例及命令操作,适用于希望了解具体部署步骤的读者。
5102

被折叠的 条评论
为什么被折叠?



