如何将uWSGI注册为系统服务

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

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

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

vi /etc/systemd/system/server_uwsgi.service

 文件内容设置如下:

[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、注册系统服务

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

  

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

[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

from FlaskAPI import create_app

app = create_app()

 

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

 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 @ 2022-03-09 22:15  无边无忌  阅读(394)  评论(0)    收藏  举报