python 配置uwsgi 启动Django框架的详细教程
作者:高压锅_1220 发布时间:2022-10-29 06:11:15
标签:python,uwsgi,Django
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 类的魔法属性用法。分享给大家供大家参考,具体如下:魔法属性无论人或事物往往都有不按套路出牌的情况,Python的
- 看看下面这个刚才提到的下拉列表的例子,就是将Application Object作为一个变量用来存储下拉列表的菜单项的:<%=&nbs
- 在MySQL经历了2008年Sun的收购和2009年Oracle收购Sun的过程中,基本处于停滞发展的情况,在可以预见的未来,MySQL是肯
- 本文实例讲述了python网络编程之文件下载实现方法。分享给大家供大家参考。具体如下:真是越看越喜欢python啊,想要了解它提供的http
- 今天写爬虫偶然想到了初学正则表达式时候,看过一篇文章非常不错。检索一下还真的找到了。re模块re.search经常用match = re.s
- Golang有很多第三方包,其中的 viper 支持读取多种配置文件信息。本文只是做一个小小demo,用来学习入门用的。1、安装go get
- 我见到有的网站好像可以把数据库的记录读到表格里去,是这样的吗?如何做到的?可能是这样的,因为我们确实能把数据库里的记录用表格来储存,看看下面
- JavaScript 中的并没有提供像 VBScript 里的 DateAdd 方法用于日
- Python not equal operator returns True if two variables are of same ty
- 当服务器必须提供与两个或更多个网络或网络子网的连接时,典型的方案是使用多宿主计算机。此计算机通常位于外围网络(也称为 DMZ、外围安全区域或
- 本文为大家分享了Python遗传算法解决最大流问题,供大家参考,具体内容如下Generate_matrixdef Generate_matr
- 最近设计一个优惠券列表,有个属性是有效日期,因为空间有限,必须要把开始日期和结束日期在一行显示,这样就出现一排的数字,日期有好几种我们习惯的
- 代码如下:<% sql="select * from serr where
- 我想要的结果无非是去掉URL路径中的index.php首先是配置.htaccess<IfModule mod_rewrite.c>
- 介绍今天有个不正经的需求,就是要快速做一个restful api的性能测试,要求测试在海量作业数据的情况下客户端分页获取所有作业的性能。因为
- 一、备份数据库 1、打开SQL企业管理器,在控制台根目录中依次点开Microsoft SQL Server
- 本文实例讲述了Python实现按特定格式对文件进行读写的方法。分享给大家供大家参考,具体如下:#! /usr/bin/env python#
- 从字节码角度看描述器在前面的内容当中我们已经详细分析了描述器的使用和其相关的应用,我们通常使用描述器都是将其作为类的一个类属性使用,而使用的
- 很久之前曾经总结过一篇博客“MySQL如何找出未提交事务信息”,现在看来,这篇文章中不少知识点或观点都略显肤浅,或者说不够深入,甚至部分结论