python 配置uwsgi 启动Django框架的详细教程

 更新时间:2022年12月28日 15:08:39   作者:高压锅_1220  
这篇文章主要介绍了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/;
  	}
}

到此这篇关于python 配置uwsgi 启动Django框架的文章就介绍到这了,更多相关python  uwsgi 配置内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Blender Python编程实现程序化建模生成超形示例详解

    Blender Python编程实现程序化建模生成超形示例详解

    这篇文章主要为大家介绍了Blender Python编程实现程序化建模生成超形示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-08-08
  • Python中的filter()函数的用法

    Python中的filter()函数的用法

    这篇文章主要介绍了Python中的filter()函数的用法,代码基于Python2.x版本,需要的朋友可以参考下
    2015-04-04
  • python类中super()和__init__()的区别

    python类中super()和__init__()的区别

    这篇文章主要介绍了python类中super()和__init__()的区别,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2016-10-10
  • YOLOv5车牌识别实战教程(二)理论基础

    YOLOv5车牌识别实战教程(二)理论基础

    这篇文章主要介绍了YOLOv5车牌识别实战教程(二)理论基础,在这个教程中,我们将一步步教你如何使用YOLOv5进行车牌识别,帮助你快速掌握YOLOv5车牌识别技能,需要的朋友可以参考下
    2023-04-04
  • Python 第一步 hello world

    Python 第一步 hello world

    Python 第一步 hello world 入门学习。
    2009-09-09
  • Python Reduce函数的高级用法详解

    Python Reduce函数的高级用法详解

    这篇文章主要介绍了reduce函数的工作原理和应用,同时提供丰富的示例代码,方便更好地理解如何使用reduce函数来轻松解决复杂的数据聚合问题,需要的可以参考下
    2023-11-11
  • Python MongoDB 插入数据时已存在则不执行,不存在则插入的解决方法

    Python MongoDB 插入数据时已存在则不执行,不存在则插入的解决方法

    这篇文章主要介绍了Python MongoDB 插入数据时已存在则不执行,不存在则插入的解决方法,结合实例形式分析了Python基于日志判断数据是否已经插入的相关操作技巧,需要的朋友可以参考下
    2019-09-09
  • 完美解决Django2.0中models下的ForeignKey()问题

    完美解决Django2.0中models下的ForeignKey()问题

    这篇文章主要介绍了完美解决Django2.0中models下的ForeignKey()问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-05-05
  • Python基本知识之datetime模块详解

    Python基本知识之datetime模块详解

    这篇文章主要给大家介绍了关于Python基本知识之datetime模块的相关资料,Python内置的时间模块datetime包含下面的模块包含六个类和两个常数,提供了用于处理日期和时间的类和对应的方法,一般用于处理年、月、日、时、分、秒的统计和计算等需求,需要的朋友可以参考下
    2023-08-08
  • Pandas 解决dataframe的一列进行向下顺移问题

    Pandas 解决dataframe的一列进行向下顺移问题

    今天小编就为大家分享一篇Pandas 解决dataframe的一列进行向下顺移问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-12-12

最新评论