python 配置uwsgi 启动Django框架的详细教程
作者:高压锅_1220 时间:2022-10-29 06:11:15
1. 安装pip3
yum install python34-pip
2. 安装python34devel
yum install python34-devel
3. pip3 安装依赖
pip3 install -r requirements
4. 安装uwsgi
pip3 install uwsgi
编写test.py测试uwsgi
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"] # python3
#return ["Hello World"] # python2
uwsgi --http :9090 --wsgi-file test.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191
5. uwsgi 配置 (simp)
编写uwsgi.ini,以wsgi方式启动uwsgi,此时无法通过web访问的方式测试是否启动,
#uwsgi配置文件
[uwsgi]
# 转发给nginx 的端口
socker=:9000
#http=:9000
# 项目目录
master=true
chdir = /home/oper/simp/Weekreport
wsgi-file = Weekreport/wsgi.py
# 进程数
workers = 5
processes = 5
threads = 2
buffer-size = 130000
# 设置日志目录
daemonize = /home/oper/simp/Weekreport/log/uwsgi.log
stats=%(chdir)/uwsgi/uwsgi.status
pidfile=%(chdir)/uwsgi/uwsgi.pid
uwsgi启动的linux shell命令,项目在/home/oper/simp/Weekreport下
# 启动
uwsgi --ini /home/oper/Weekreport/uwsgi.ini
# 停止
uwsgi --stop /home/oper/Weekreport/uwsgi/uwsgi.pid
# 启动
uwsgi --ini /home/oper/Weekreport/uwsgi.ini
# 停止
uwsgi --stop /home/oper/Weekreport/uwsgi/uwsgi.pid
如控制台出现以下提示,八成是成功了
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x12b9fa0 pid: 2402 (default app)
mountpoint already configured. skip.
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 2402, cores: 1)
启动uwsgi服务,设置开机启动
systemctl start uwsgi
systemctl enable uwsgi
6. nginx的配置
6.1 uwsgi 后端nginx 配置
在/etc/nginx/conf.d下新建一个uwsgi.conf
```bash
# mysite_nginx.conf
# configuration of the server
server {
# the port your site will be served on
listen 80 default_server;
server_name localhost;
charset utf-8;
access_log /applog/nginx/logs/access.log main;
proxy_set_header Host $host;
proxy_set_header X-Real_ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_read_timeout 300
location / {
include uwsgi_params;
uwsgi_pass 28.106.81.81:9000
}
location /api/{
proxy_pass http://28.106.81.81:8080/;
}
location /collection/{
proxy_pass http://localhost:9999/;
}
location /api-collection/{
proxy_pass http://localhost/collection/api/;
}
}
6.2 nginx 前端nginx 配置
在/etc/nginx/conf.d下新建一个uwsgi.conf
# mysite_nginx.conf
# configuration of the server
server {
# the port your site will be served on
listen 80 default_server;
# the domain name it will serve for
server_name simp;
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location / {
proxy_pass http://28.106.81.81; # 此处是uwsgi 对应的后端Nginx
# uwsgi_pass localhost:5000; # 此处与uwsgi.ini的socket是对应的
}
location /static {
alias /root/hujun_app/ocv-simp/Weekreport/static; # your Django project's static files - amend as required
}
location /api-collection/{
proxy_pass http://localhost/collection/api/;
}
location /collection/{
proxy_pass http://localhost:9999/;
}
}
来源:https://blog.csdn.net/u014651560/article/details/128419846
标签:python,uwsgi,Django
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
微信小程序学习笔记之表单提交与PHP后台数据交互处理图文详解
2023-11-22 19:29:44
![](https://img.aspxhome.com/file/2023/7/111307_0s.png)
Anaconda安装pytorch和paddle的方法步骤
2021-04-17 18:21:59
![](https://img.aspxhome.com/file/2023/5/102785_0s.jpg)
使用python生成杨辉三角形的示例代码
2023-04-03 18:42:31
![](https://img.aspxhome.com/file/2023/7/134587_0s.png)
python中not not x 与bool(x) 的区别
2021-04-27 03:50:17
![](https://img.aspxhome.com/file/2023/1/120371_0s.png)
8段用于数据清洗Python代码(小结)
2023-10-01 06:04:25
python实现证件照换底功能
2021-07-02 03:57:01
基于JavaScript实现弹幕特效
2024-04-22 22:30:23
![](https://img.aspxhome.com/file/2023/3/135703_0s.gif)
解决python中os.listdir()函数读取文件夹下文件的乱序和排序问题
2022-10-24 05:34:54
![](https://img.aspxhome.com/file/2023/7/67727_0s.jpg)
Python3.6正式版新特性预览
2023-11-02 09:27:09
js实现的全国省市二级联动下拉选择菜单完整实例
2023-09-09 05:21:01
![](https://img.aspxhome.com/file/2023/4/56304_0s.jpg)
Asp.net清空控件值的方法(可自定义控件类型)
2023-07-22 23:23:16
14道基础Python练习题(附答案)
2023-07-23 02:27:41
![](https://img.aspxhome.com/file/2023/8/110238_0s.png)
Vue父组件和子组件之间数据传递和方法调用
2023-07-02 17:01:57
Python3从零开始搭建一个语音对话机器人的实现
2023-11-15 05:52:12
![](https://img.aspxhome.com/file/2023/5/64715_0s.jpg)
浅析BootStrap模态框的使用(经典)
2023-08-20 02:21:19
总结Python编程中函数的使用要点
2021-03-15 01:49:52
vscode 远程调试python的方法
2021-09-07 23:00:59
![](https://img.aspxhome.com/file/2023/7/83717_0s.png)
Python实现批量转换文件编码的方法
2023-06-02 20:03:49
es6函数之严格模式用法实例分析
2023-08-09 06:15:40
JS获取网页中HTML元素的几种方法分析
2007-10-12 13:08:00