Linux配置uwsgi环境
1.进入虚拟环境
source /envs/django_-shop-system/bin/activate
2.安装uwsgi
pip install uwsgi
3.基于uwsgi运行项目 – 基于配置文件
在项目目录下创建配置文件
#socket= 0.0.0.0:8005 http= 0.0.0.0:8005 # http=120.55.47.111:8005 chdir=/opt/www/django_-shop-system/ wsgi-file = /opt/www/django_-shop-system/JiXuShopSystem/wsgi.py #callable = application processes = 2 threads = 2 virtualenv = /envs/django_-shop-system/ master=True pidfile=uwsgi.pid uid = 2001 gid = 1001 buffer-size = 65536 static-map = /static=/opt/www/django_-shop-system/static/
进入项目目录激活虚拟环境
cd /opt/www/django_-shop-system
source /envs/django_-shop-system/bin/activate
运行uwsgi
uwsgi --ini django_-shop-system_uwsgi.ini uwsgi --stop uwsgi.121339
后台运行
uwsgi --ini django_-shop-system_uwsgi.ini &
针对运行比较麻烦我们可以穿件shell脚本
shell脚本
reboot.sh
#!/usr/bin/env bash echo -e "\033[34m--------------------wsgi process--------------------\033[0m" ps -ef|grep nb_uwsgi.ini | grep -v grep sleep 0.5 echo -e '\n--------------------going to close--------------------' ps -ef |grep nb_uwsgi.ini | grep -v grep | awk '{print $2}' | xargs kill -9 sleep 0.5 echo -e '\n----------check if the kill action is correct----------' /envs/nb/bin/uwsgi --ini nb_uwsgi.ini & >/dev/null echo -e '\n\033[42;1m----------------------started...----------------------\033[0m' sleep 1 ps -ef |grep nb_uwsgi.ini | grep -v grep
chmod 755 reboot.sh ./reboot.sh
stop.sh
#!/usr/bin/env bash echo -e "\033[34m--------------------wsgi process--------------------\033[0m" ps -ef |grep nb_uwsgi.ini | grep -v grep sleep 0.5 echo -e '\n--------------------going to close--------------------' ps -ef |grep nb_uwsgi.ini | grep -v grep | awk '{print $2}' | xargs kill -9 sleep 0.5
赋予可执行权限
chmod 755 reboot.sh chmod 755 stop.sh