python flask实战订餐系统微信小程序-60nginx + uwsgi 实现多进程访问

wechat 虚幻 574℃ 0评论

uwsgi多进程配置

uwsgi.ini配置

nginx和uwsgi通过配置文件sock配合

[uwsgi]
#源码目录
chdir=/home/www/order
#python 虚拟环境
home=/home/www/xuhss
module=manager
callable=app
master=true
processes=4
http=0.0.0.0:8889
socket=/home/www/logs/order.sock
buffer-size=65535
pidfile=/home/www/logs/order.pid
chmod-socket=777
logfile-chmod=644
daemonize=/home/www/logs/order.log
static-map = /static=/home/www/order/web/static
创建多进程
#激活虚拟环境
source  /home/www/xuhss/bin/activate
# 创建log目录
mkdir /home/www/logs
# 启动uwsgi
cd /home/www/order
uwsgi --ini uwsgi.ini(多进程)

此时通过ps -ef | grep uwsgi,就可以看到多进程启动(注意:开发云主机的8889端口)

20211017114131 - python flask实战订餐系统微信小程序-60nginx + uwsgi 实现多进程访问

创建80端口访问

创建配置文件order.conf
cd /etc/nginx/conf.d
touch order.conf
vim order.conf
输入内容

https配置

server {
    listen 443 default_server;
    server_name food.xuhss.com;

    ssl on;
    ssl_certificate /home/www/ssl/chained.pem;
    ssl_certificate_key /home/www/ssl/domain.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA;
    ssl_session_cache shared:SSL:50m;

    location /.well-known/acme-challenge/ {
        alias /home/www/challenges/;
        try_files $uri =404;
    }

    location /static {
        alias  /home/www/order/web/static/;
    }

    location / {
        try_files $uri @yourapplication;
    }
    location @yourapplication {
      include uwsgi_params;
      uwsgi_pass unix:/home/www/logs/order.sock;
      uwsgi_read_timeout 1800;
      uwsgi_send_timeout 300;
    }
}

server {
    listen 80;
    server_name food.xuhss.com;
    rewrite ^/(.*) https://$server_name$request_uri? permanent;
}

http配置

server {
    listen 80 default_server;
    server_name food.xuhss.com;

    location /static {
        alias  /home/www/order/web/static/;
    }

    location / {
        try_files $uri @yourapplication;
    }
    location @yourapplication {
      include uwsgi_params;
      uwsgi_pass unix:/home/www/logs/order.sock;
      uwsgi_read_timeout 1800;
      uwsgi_send_timeout 300;
    }
}

启动nginx

service nginx start
service nginx stop
ps -ef | grep nginx

查看端口占用

netstat -ltunp

检查问题

nginx -c /etc/nginx/nginx.conf

强行关闭nginx

yum install -y psmisc
fuser -n tcp 80
kill -9 端口号

重启uwsgi

uwsgi --stop /home/www/logs/order.pid

出现500错误

setenforce 0

转载请注明:虚坏叔叔 » python flask实战订餐系统微信小程序-60nginx + uwsgi 实现多进程访问

喜欢 (12)

您必须 登录 才能发表评论!