部署 Tornado
安装supervisor
apt-get install supervisor
vim /etc/supervisor/conf.d/tornado.conf
[group:tornadoes] programs=tornado-8887,tornado-8888,tornado-8889,tornado-8886 [program:tornado-8886] command=/usr/local/python3.10/bin/python3.10 /home/szw/data/server/test_app/app.py --port 8886 directory=/home/szw/data/server/test_app/ user=root autorestart=true redirect_stderr=true stdout_logfile=/var/log/tornado.log stderr_logfile=/var/log/tornado_err.log [program:tornado-8887] command=/usr/local/python3.10/bin/python3.10 /home/szw/data/server/test_app/app.py --port 8887 directory=/home/szw/data/server/test_app/ user=root autorestart=true redirect_stderr=true stdout_logfile=/var/log/tornado.log stderr_logfile=/var/log/tornado_err.log [program:tornado-8888] command=/usr/local/python3.10/bin/python3.10 /home/szw/data/server/test_app/app.py --port 8888 directory=/home/szw/data/server/test_app/ user=root autorestart=true redirect_stderr=true stdout_logfile=/var/log/tornado.log stderr_logfile=/var/log/tornado_err.log [program:tornado-8889] command=/usr/local/python3.10/bin/python3.10 /home/szw/data/server/test_app/app.py --port 8889 directory=/home/szw/data/server/test_app/ user=root autorestart=true redirect_stderr=true stdout_logfile=/var/log/tornado.log stderr_logfile=/var/log/tornado_err.log
启动 如果已经启动可以跳过
supervisord -c /etc/supervisord.conf
使用以下命令重新加载 Supervisor 配置文件:
supervisorctl reread
supervisorctl update
配置nginx
upstream tornadoes { server 127.0.0.1:8886; server 127.0.0.1:8887; server 127.0.0.1:8888; server 127.0.0.1:8889; } upstream websocket { server 127.0.0.1:8000; } server { listen 8885; server_name _; location /static/ { root /home/python/Documents/demo/chat; if ($query_string) { expires max; } } location /chat { proxy_pass http://websocket/chat; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; # 协议 http https proxy_pass http://tornadoes; } }