广告
返回顶部
首页 > 资讯 > 后端开发 > Python >python 配置uwsgi 启动Django框架的详细教程
  • 602
分享到

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

python  uwsgi 配置python启动Django框架 2022-12-28 18:12:29 602人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

目录1. 安装pip32. 安装python34devel3. pip3 安装依赖4. 安装uwsgi5. uwsgi 配置 (simp)6. Nginx的配置6.1 uwsgi 后

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

--结束END--

本文标题: python 配置uwsgi 启动Django框架的详细教程

本文链接: https://www.lsjlt.com/news/176113.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作