IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Python知识库 -> python 配置uwsgi 启动Django框架 -> 正文阅读

[Python知识库]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

如控制台出现以下提示,八成是成功了

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知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2022-12-25 11:04:55  更:2022-12-25 11:08:26 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年4日历 -2024/4/27 3:16:54-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码