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知识库 -> Flask uwsgi与nginx部署(详细配置) -> 正文阅读

[Python知识库]Flask uwsgi与nginx部署(详细配置)

环境

  • python2或3都支持
  • linux

uwsgi

UWSGI 下载

pip install uwsgi

UWSGI 配置

[uwsgi]
# 外部访问地址,可以指定多种协议,现在用http便于调试,之后用socket
# socket方式
socket=0.0.0.0:7777
# http方式
http=0.0.0.0:7777
# http与socket通用方式
http-socket=0.0.0.0:7777
# 项目路径
# chdir=/home/ubuntu/apt
pythonpath=/home/ubuntu/apt_epiboly
# 虚拟环境的目录路径
# virtualenv = /rasa/zndhjqr_nlp/venv
# 主程序文件
wsgi-file=/home/ubuntu/apt_epiboly/run.py
#wsgi-file=./run.py
# flask项目创建的application
callable=app_main
#主线程
master=true
# 处理器数
processes = 1
# 线程数
threads = 10
buffer-size = 65536

stats=/home/ubuntu/apt_epiboly/config/uwsgi.status
pidfile=/home/ubuntu/apt_epiboly/config/uwsgi.pid

# 网上查询说是防止假死的参数
reload-mercy = 1
worker-reload-mercy = 1

enable-threads = true

harakiri=180
#自动移除unix Socket 和 Pid 文件 当服务停止的时候
vacuum = true

# plugins=python

lazy-apps = true

pythonpath=/usr/lib/python2.7/dist-packages
#home=/home/ubuntu/hjy/python2
pythonpath=/usr/local/lib/python2.7/dist-packages

nginx

nginx 配置

该配置适用uwgi采用socket方式
该配置支持部署多个项目


user  root;
worker_processes 1;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;
    access_log /var/log/nginx/access.log;  # 成功日志存储路径
    error_log /var/log/nginx/error.log;  # 失败日志存储路径

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    client_max_body_size 500M;

    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        #
        proxy_connect_timeout    600;
        proxy_read_timeout       600;
        proxy_send_timeout       600;

        location / {
            try_files $uri $uri/ /index.html;
            root  /home/ubuntu/apt/dist;  # 参考前端打包的dist文件目录位置
            index  index.html index.htm;
            #add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Origin *;
            #add_header Access-Control-Allow-Credentials true
            add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
            add_header Access-Control-Allow-Headers X-Requested-With;
            if ($request_method = OPTIONS){
                    return 200;
                }
            }

        location /api/ {
            include uwsgi_params;
            uwsgi_pass  127.0.0.1:8888;

            uwsgi_send_timeout 600;
            uwsgi_connect_timeout 600;
            uwsgi_read_timeout 600;

            #proxy_pass  http://127.0.0.1:8888/api/;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    server {
        listen       82;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        #
        proxy_connect_timeout    600;
        proxy_read_timeout       600;
        proxy_send_timeout       600;

        location / {
            try_files $uri $uri/ /index.html;
            root  /home/ubuntu/apt_epiboly/dist;
            index  index.html index.htm;
            #add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Origin *;
            #add_header Access-Control-Allow-Credentials true
            add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
            add_header Access-Control-Allow-Headers X-Requested-With;
            if ($request_method = OPTIONS){
                    return 200;
                }
            }

        location /api/ {
            include uwsgi_params;
            uwsgi_pass  127.0.0.1:7777;

            uwsgi_send_timeout 600;
            uwsgi_connect_timeout 600;
            uwsgi_read_timeout 600;

            #proxy_pass  http://127.0.0.1:7777/api/;
            #proxy_set_header Host $host;
            #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    server {
        listen       81;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        #
        proxy_connect_timeout    600;
        proxy_read_timeout       600;
        proxy_send_timeout       600;

        location / {
            try_files $uri $uri/ /index.html;
            root  /home/ubuntu/apt_probe/dist;
            index  index.html index.htm;
            #add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Origin *;
            #add_header Access-Control-Allow-Credentials true
            add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
            add_header Access-Control-Allow-Headers X-Requested-With;
            if ($request_method = OPTIONS){
                    return 200;
                }
            }

        location /api/ {
            include uwsgi_params;
            uwsgi_pass  127.0.0.1:6666;

            uwsgi_send_timeout 600;
            uwsgi_connect_timeout 600;
            uwsgi_read_timeout 600;

            proxy_pass  http://127.0.0.1:6666/api/;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
}

启动

启动uwsgi

路径参考自己的uwsgi.ini配置文件

nohup uwsgi --ini /home/apt/config/uwsgi.ini  >/home/apt/apt.log 2>&1  &

启动nginx

systemctl start nginx

访问

浏览器输入部署服务器ip和端口号

  Python知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2022-01-29 23:02:34  更:2022-01-29 23:04:56 
 
开发: 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年11日历 -2024/11/16 1:50:02-

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