Python WeChat applet server-side Django+Ngnix+uwsgi

Article Directory


foreword

Environment: ubuntu18, python3
Use python to write the WeChat applet backend, the applet domain name needs https and record, so django+ngnix+uwsgi is used to build the environment.


1. uwsgi

pip3 install uwsgi

[uwsgi]
#socket负责nginx和uwsgi通信
socket = /home/ubuntu/wx_test/uwsgi.sock
#指定项目路径
chdir = /home/ubuntu/wx_test
#django项目wsgi
wsgi-file = /home/ubuntu/wx_test/wx_test/wsgi.py
#pid端口文件
pidfile = /home/ubuntu/wx_test/uwsgi.pid
#后台运行,打印日志输出
daemonize = /home/ubuntu/wx_test/uwsgi.log
#主进程
master = true
#退出、重启时清理文件
vacuum = true
#配置进程
processes = 6
#配置线程
threads = 100
#序列化接受的内容
thunder-lock = true
#启用线程
enable-thread = true
#设置中断时间
harakiri = 30
#设置缓冲
post-buffering = 4096
#python更改自动重启uwsgi
py-autoreload = 1

uwsgi --ini wx_test.ini

2. Nginx

sudo apt-get install nginx
cd /etc/nginx
modify nginx user vi nginx.conf modify the first line to user root;
cd conf.d
sudo touch wx_test.conf
sudo vi wx_test.conf

server {
    
    
    #SSL 访问端口号为 443
    listen 443 ssl; 
 #填写绑定证书的域名
    server_name xmueye.com; 
 #证书文件名称
    ssl_certificate /etc/nginx/conf.d/1_xmueye.com_bundle.crt; 
 #私钥文件名称
    ssl_certificate_key /etc/nginx/conf.d/2_xmueye.com.key; 
    ssl_session_timeout 5m;
 #请按照以下协议配置
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
 #请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; 
    ssl_prefer_server_ciphers on;

    charset UTF-8;

    client_max_body_size 75M;

#指定项目路径uwsgi
	location / {
    
    
	    #nginx和uwsgi的通信协议
	    include /etc/nginx/uwsgi_params;
	    #nginx对应uwsgi socket
	    uwsgi_pass unix:/home/ubuntu/wx_test/uwsgi.sock;
	}
#指定静态文件目录
	location /static/ {
    
    
	    alias /home/ubuntu/wx_test/static_all;
	    index index.html index.htm;
	}
}

Restart the nginx server
sudo service nginx restart

Summarize

Refer to the following articles
https://blog.csdn.net/qq_43467898/article/details/83187698
https://cloud.tencent.com/document/product/400/35244
https://www.runoob.com/django/django -nginx-uwsgi.html
https://www.jb51.net/article/160820.htm

Guess you like

Origin blog.csdn.net/weixin_42748604/article/details/115203073