[Unit]
Description=DMS 设备管理系统
After=network.target
[Service]
Type=simple
WorkingDirectory=/home/wwwroot/dms
ExecStart=/usr/bin/python3 /home/wwwroot/dms/app.py
Restart=on-failure
RestartSec=5
User=dms # 如果运行用户不是 www-data,请改成实际用户
Group=dms
[Install]
WantedBy=multi-user.target
---在正式的生产环境,用Gunicorn托管Flask 程序
[Unit]
Description=Gunicorn service for Flask app (DMS)
After=network.target
[Service]
User=dms
Group=dms
WorkingDirectory=/home/wwwroot/dms
ExecStart=/usr/bin/gunicorn -w 4 -b 0.0.0.0:5000 app:app
Restart=always
RestartSec=5
Environment="PATH=/usr/bin"
[Install]
WantedBy=multi-user.target
重新加载,
systemctl daemon-reload
systemctl enable Gunicorn.service --加入自启动。
systemctl start Gunicorn.service
systemctl status Gunicorn.service
--更改NGINX配置
server
{
listen 80;
#listen [::]:80;
server_name dms.rongyi.site ;
include rewrite/other.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php.conf;
location / {
proxy_pass http://127.0.0.1:5000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
access_log /home/wwwlogs/dms.rongyi.site.log;
}
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name dms.rongyi.site ;
ssl_certificate /usr/local/nginx/conf/ssl/dms.rongyi.site/fullchain.cer;
ssl_certificate_key /usr/local/nginx/conf/ssl/dms.rongyi.site/dms.rongyi.site.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
# openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
include rewrite/other.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php.conf;
location / {
proxy_pass http://127.0.0.1:5000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
access_log /home/wwwlogs/dms.rongyi.site.log;
}
