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 配置内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Python实现小黑屋游戏的完整实例

    Python实现小黑屋游戏的完整实例

    这篇文章主要给大家介绍了关于Python实现小黑屋游戏的完整实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-01-01
  • 一篇文章带你自学python Django

    一篇文章带你自学python Django

    这篇文章主要为大家详细介绍了Python利用Django完整的开发一个博客系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-09-09
  • Python3 循环语句(for、while、break、range等)

    Python3 循环语句(for、while、break、range等)

    这篇文章主要介绍了Python3 循环语句(for、while、break、range等),大家把下面的文章看完就基本上就可以了解了python的循环实现方式了
    2017-11-11
  • Python游戏推箱子的实现

    Python游戏推箱子的实现

    这篇文章主要介绍了Python游戏推箱子的实现,推箱子游戏是一款可玩性极高的策略解谜手游,游戏中玩家将扮演一名可爱Q萌的角色,下面我们就看看看具体的实现过程吧,需要的小伙伴可以参考一下
    2021-12-12
  • PyQt转换路径中的斜杠(斜杠(/)与反斜杠(\)转换)

    PyQt转换路径中的斜杠(斜杠(/)与反斜杠(\)转换)

    本文主要介绍了PyQt转换路径中的斜杠(斜杠(/)与反斜杠(\)转换),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-07-07
  • python3发送request请求及查看返回结果实例

    python3发送request请求及查看返回结果实例

    这篇文章主要介绍了python3发送request请求及查看返回结果实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-04-04
  • python+OpenCV人脸识别考勤系统实现的详细代码

    python+OpenCV人脸识别考勤系统实现的详细代码

    作为一个基于人脸识别算法的考勤系统的设计与实现教程,以下内容将提供详细的步骤和代码示例。本教程将使用 Python 语言和 OpenCV 库进行实现,需要的朋友可以参考下
    2023-05-05
  • Python3中str、bytes、bytearray转化

    Python3中str、bytes、bytearray转化

    本文主要介绍了Python3中str、bytes、bytearray转化,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-04-04
  • Python使用pyecharts绘制世界地图,省级地图,城市地图实例详解

    Python使用pyecharts绘制世界地图,省级地图,城市地图实例详解

    这篇文章主要介绍了如何使用Python中的pyecharts库绘制世界地图、中国地图、省级地图、市级地图,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起动手试一试
    2022-02-02
  • Python实现堆排序的方法详解

    Python实现堆排序的方法详解

    这篇文章主要介绍了Python实现堆排序的方法,结合实例形式详细分析了堆排序的原理,实现方法与相关注意事项,需要的朋友可以参考下
    2016-05-05

最新评论