-
利用 pip 工具,安裝 supervisor 套件:
#pip install supervisor
-
利用 supervisor 工具,產生 supervisor 設定檔:
#echo_supervisord_conf > /etc/supervisord.conf
-
編輯 supervisor 設定檔:
#vim /etc/supervisord.conf
(在檔案最尾端,加上下列幾行設定:)
[program:mysite]
command=/bin/uwsgi --http :8081 --chdir /usr/share/nginx/html/mysite --module mysite.wsgi
directory=/usr/share/nginx/html/mysite
startsecs=0
stopwaitsecs=0
autostart=true
autorestart=true
-
啟動 supervisor 服務:
#supervisord -c /etc/supervisord.conf
-
動新啟動 mysite 站台運作:
#supervisorctl -c /etc/supervisord.conf restart mysite
※其他操作 supervisorctl 的指令:supervisorctl -c /etc/supervisord.conf [start|stop|restart] [program-name|all]
-
開啟防火牆設定:
#firewall-cmd --permanent --add-port=8081/tcp
#firewall-cmd --reload
-
利用 ini 文件來結合 nginx 運作:
#vim /usr/share/nginx/html/mysite/mysite.ini
[uwsgi]
socket = /tmp/mysite.sock
chdir=/usr/share/nginx/html/mysite
wsgi-file = mysite/wsgi.py
touch-reload=/usr/share/nginx/html/mysite/reload
processes = 1
threads = 2
chmod-socket = 664
chown-socket=nginx:nginx
-
重新編輯 supervisor 設定檔:
#vim /etc/supervisord.conf
:
:(略過...)
[program:mysite]
command=/bin/uwsgi --ini /usr/share/nginx/html/mysite/mysite.ini
directory=/usr/share/nginx/html/mysite
startsecs=0
-
動新啟動 mysite 站台運作:
#supervisorctl -c /etc/supervisord.conf restart mysite
-
在 Nginx 上,新增 mysite 設定檔:
#vim /etc/nginx/conf.d/mysite.conf
server {
listen 8081;
server_name 192.168.5.104;
charset utf-8;
client_max_body_size 75M;
location /media {
alias /usr/share/nginx/html/mysite/media;
}
location /static {
alias /usr/share/nginx/html/mysite/static;
}
location / {
uwsgi_pass unix:///tmp/mysite.sock;
include /etc/nginx/uwsgi_params;
}
}
-
重新啟動 Nginx :
#systemctl restart nginx