如何将uWSGI注册为系统服务

1、检查确保用uWSGI命令行的方式可以成功运行服务

1
/usr/local/bin/uwsgi --ini /root/flask-api/uw.ini

2、创建系统服务描述问题

1
vi /etc/systemd/system/server_uwsgi.service

 文件内容设置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
Description=HTTP Interface Server
After=syslog.target
 
[Service]
KillSignal=SIGQUIT
ExecStart=/usr/local/bin/uwsgi --ini /root/flask-api/uw.ini
Restart=always
Type=notify
NotifyAccess=all
StandardError=syslog
 
[Install]
WantedBy=multi-user.target

 

3、注册系统服务

1
2
systemctl enable /etc/systemd/system/server_uwsgi.service
systemctl daemon-reload

  

4、完成之后,就可以启动,关闭服务了

1
2
3
4
systemctl start server_uwsgi.service
systemctl restart server_uwsgi.service
systemctl stop server_uwsgi.service
systemctl status server_uwsgi.service

  

附1:uWSGI的配置, 文件位置:/root/flask-api/uw.ini

1
2
3
4
5
6
7
8
9
10
[uwsgi]
socket = 127.0.0.1:8090
home = /root/flask-api/venv
wsgi-file = /root/flask-api/app.py
callable = app
processes = 1
threads = 1
buffer-size = 32768
master = true
virtualenv = /root/flask-api/venv/

  

附2:flask启动程序app.py。 文件位置: /root/flask-api

1
2
3
from FlaskAPI import create_app
 
app = create_app()

 

附3: Nginix配置程序, 文件位置:/etc/nginx/nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
server {
       listen       80 default_server;
       listen       [::]:80 default_server;
       server_name  _;
       root         /usr/share/nginx/html;
 
       # Load configuration files for the default server block.
       include /etc/nginx/default.d/*.conf;
 
       location / {
       # fastcgi_index index.php;
       # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include uwsgi_params;
       uwsgi_pass 127.0.0.1:8090;
       }
 
       error_page 404 /404.html;
           location = /40x.html {
       }
 
       error_page 500 502 503 504 /50x.html;
           location = /50x.html {
       }
   }

  

posted @   无边无忌  阅读(237)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示