在manage.py 同目录下(项目根目录),新建一个目录uwsgi_conf用来放置uwsgi.ini配置文件
[uwsgi]
#地址和端口号
socket=127.0.0.1:9001
#指定运行目录
chdir=/wwwroot/backend/
#载入wsgi-file
wsgi-file=application/wsgi.py
#开启的进程数量
processes=4
#运行线程
threads=2
#允许主进程存在
master=True
#使进程在后台运行,并将日志打到指定的日志文件
logto=/wwwroot/backend/uwsgi_conf/uwsgi.log
uwsgi开机自启
vi /etc/systemd/system/uwsgi.service
[Unit]
Description=Uwsgi Server
After=syslog.target
[Service]
KillSignal=SIGQUIT
ExecStart=/usr/bin/uwsgi --ini /wwwroot/backend/uwsgi_conf/uwsgi.ini
Restart=always
Type=notify
NotifyAccess=all
StandardError=syslog
[Install]
WantedBy=multi-user.target
将该服务加入到systemd中
systemctl enable /etc/systemd/system/uwsgi.service
配置nginx
vi /etc/nginx/conf.d/default.conf
upstream backend {
server 127.0.0.1:9001;
}
server {
listen 443 ssl;
server_name gbkh.jycollege.cn;
access_log /var/log/nginx/access_web.log;
error_log /var/log/nginx/error_web.log;
location / {
root /wwwroot/web;
index index.html;
}
}
server {
listen 80;
server_name www.sample.com;
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 8443 ssl;
server_name www.sample.com;
access_log /var/log/nginx/access_backend.log;
error_log /var/log/nginx/error_backend.log;
location / {
# nginx转发动态请求到uWSGI
include uwsgi_params;
uwsgi_connect_timeout 20;
uwsgi_pass backend;
}
# 如果写成/static/,nginx无法找到项目静态文件路径
location /static {
alias /wwwroot/backend/static;
}
# 如果写成/media/,nginx无法找到项目媒体文件路径
location /media {
alias /wwwroot/backend/media;
}
}