centos7使用nginx+uwsgi部署python django项目
2023-06-13 09:11:17 时间
在django框架中,我们一般直接通过python manage.py runserver来启动提供服务,但是如果生产环境此方法不可行,而且容易导致异常退出,于是需要借助uwsgi来作为守护进程。
操作思路:
- 服务器中安装uwsgi插件
- 新建uwsgi.ini文件,写入uwsgi需要的参数
- 安装nginx,并配置
uwsgi_pass 127.0.0.1:9496
代理转发 - 启动nginx、uwsgi
安装uwsgi插件
pip install uwsgi
新建uwsgi.ini文件,写入uwsgi需要的参数
可直接在代码根目录中创建uwsgi.ini
文件,参考如下:
[uwsgi]
socket = 127.0.0.1:9496
chdir = /home/dengzhixu/crawl_data
wsgi-file = /home/dengzhixu/crawl_data/yibo_crawl_data/wsgi.py
processes = 4
threads = 2
#stats = 0.0.0.0:9496
buffer-size = 65536
#daemonize = /var/log/uwsgi.log
安装nginx,配置uwsgi_pass
转发
安装nginx步骤省略,可直接去lnmp.org
下载集成nginx
nginx添加vhost配置文件,参考如下
server
{
listen 9495;
#listen [::]:;
server_name crawl.com ;
index index.html index.htm default.html default.htm;
root /home/dengzhixu/crawl_data;
include rewrite/other.conf;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9496;
uwsgi_param UWSGI_SCRIPT ./yibo_crawl_data/demosite.wsgi;
uwsgi_param UWSGI_CHDIR /home/dengzhixu/crawl_data;
index index.html index.htm;
client_max_body_size 35m;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/crawl.com.log;
启动nginx、uwsgi
nginx
uwsgi -d --ini /home/dengzhixu/crawl_data/uwsgi.ini
配置systemd
自启动
创建一个systemd服务文件/lib/systemd/system/uwsgi.service
[Unit]
Description=uWSGI Emperor
#After=syslog.target
After=network.target
[Service]
#PIDFile=/run/uwsgi.pid
ExecStart=/usr/local/bin/uwsgi --ini /home/dengzhixu/crawl_data/uwsgi.ini
#ExecStop=/usr/local/bin/uwsgi --stop $MAINPID
#ExecReload=/usr/local/bin/uwsgi -d --reload $MAINPID
# Requires systemd version 211 or newer
#RuntimeDirectory=uwsgi
Restart=always
KillSignal=SIGQUIT
Type=notify
#Type=forking
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target
开启自启动,并启动
systemctl start uwsgi.service
systemctl enable uwsgi.service
参考文献:
https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html
相关文章
- OpenCV—python 颜色直方图与直方图均衡化[通俗易懂]
- Python获取时间戳_python爬虫时间戳
- Python&R语言-python和r相遇
- python教程:用简单的Python编写Web应用程序
- python基础系列教程——Python的安装与测试:python解释器、PyDev编辑器、pycharm编译器
- python按位取反_python赋值运算符
- python pkl文件_Python字符串格式化输出的方式包括
- python中zipfile的使用_python调用winrar解压
- python+appium自动化_python dict
- Python 反转字符串_python输出字符串
- python的三方库_py第三方库有哪些
- python 傅里叶变换画图_傅里叶变换图像处理
- 树莓派python编程指南_树莓派python软件
- wrf-python库插值到指定离地高度层并绘图
- 1行Python代码,把PPT转成图片,python-office功能更新~
- Python 内置界面开发框架 Tkinter入门篇 甲
- Python 自动化指南(繁琐工作自动化)第二版:六、字符串操作
- pycharm下载图文教程:pycharm和python的区别
- Python学习:6.python内置函数详解编程语言
- CentOS7启动MySQL服务的方法(centos7重启mysql)
- 从Python连接Oracle数据库介绍(python连接oracle)
- Python实现快速连接Redis数据库(python连接redis)
- 手把手|20行Python代码教你批量将PDF文件转为Word格式(包教包会)
- 《Python官方文档》5.数据结构
- python从MSSQL到Python:一段跨语言的旅程(mssql除以)
- 从 Python 连接到 MySQL:实现更多强大的数据库应用(python和mysql)
- Linux下从系统卸载Python(linux下卸载python)
- 决策树的python实现方法
- Python正则表达式(转义问题)
- Python对小数进行除法运算的正确方法示例
- Python中的自定义函数学习笔记