有时不需要安装 nginx,带有 gunicorn 的 python 是主管的可行替代方案,但您需要制作很多技巧才能工作
我假设您知道安装主管,然后再安装要求
pip3 install virtualenv
mkdir /home/user/.envpython
virtualenv /home/user/.envpython/bin/activate
source /home/user/.envpython/bin/activate
cd /home/user/python-path/
pip3 install -r requirements
创建一个这样的主管文件
nano /etc/supervisord.d/python-file.conf
并用这个例子编辑,编辑你需要的程序,记住python3在其他端口> 1024运行
;example with path python supervisor in background
[program:python]
environment=HOME="/home/user",USER="user"
user=user
directory = /home/user/python-path
command = python3 /home/user/python-path/main.py
priority = 900
autostart = true
autorestart = true
stopsignal = TERM
;redirect_stderr = true
stdout_logfile = /home/user/.main-python-stdout.log
stderr_logfile = /home/user/.main-python-stderr.log
;example with path python gunicorn supervisor and port 80
[program:gunicorn]
;environment=HOME="/home/user",USER="user"
;user=user
directory = /home/user/python-path
command = bash /home/user/.scripts/supervisor-initiate.sh
priority = 900
autostart = true
autorestart = true
stopsignal = TERM
;redirect_stderr = true
stdout_logfile = /home/user/.main-python-stdout.log
stderr_logfile = /home/user/.main-python-stderr.log
并创建文件
nano /home/user/.scripts/supervisor-initiate.sh
具有以下内容
source /home/user/.envpython/bin/activate
cd /home/user/python-path
gunicorn -w 1 -t 120 -b 0.0.0.0:80 main:app
我假设您在 python 中的文件称为 main 并且您使用名为“app”的烧瓶或 django 启动应用程序
只重启supervisord进程
systemctl restart supervisord
并且您在端口 80 中有带有 gunicorn 的应用程序,我发帖是因为我为这个解决方案找到了很长时间
Waiting works for anyone