環境:ubuntu18,python3
使用python編寫微信小程序後端,小程序域名需要https和備案,所以采用django+ngnix+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
sudo apt-get install nginx
cd /etc/nginx
修改nginx用戶vi nginx.conf將第一行修改為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;
}
}
重啟nginx服務器
sudo service nginx restart
參考以下文章
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