ps:
#项目目录 /opt/mtrop/ #项目静态文件地址 /opt/mtrop/statics
一,安装uwsgi
pip install uwsgi
二,安装nginx
groupadd www && useradd www -g wwwyum -y install pcre-devel openssl openssl-devel wget gcc-c++ wget net-toolswget http://nginx.org/download/nginx-1.14.0.tar.gzmkdir /usr/local/nginxtar -zxf nginx-1.14.0.tar.gz && cd nginx-1.14.0./configure --prefix=/usr/local/nginx/ --user=www --group=wwwmake && make installecho 'PATH="/usr/local/nginx/sbin:$PATH"'>> /etc/profile;source /etc/profilemkdir /usr/local/nginx/conf/vhost
nginx 启动文件(/etc/init.d/nginx)
#! /bin/sh# chkconfig: 2345 55 25# Author: xiaoer# website: https://www.cnblogs.com/xiao2er/PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binNAME=nginxNGINX_BIN=/usr/local/nginx/sbin/$NAMECONFIGFILE=/usr/local/nginx/conf/$NAME.confPIDFILE=/usr/local/nginx/logs/$NAME.pidcase "$1" in start) echo -n "Starting $NAME... " if netstat -tnpl | grep -q nginx;then echo "$NAME (pid `pidof $NAME`) already running." exit 1 fi $NGINX_BIN -c $CONFIGFILE if [ "$?" != 0 ] ; then echo " failed" exit 1 else echo " done" fi ;; stop) echo -n "Stoping $NAME... " if ! netstat -tnpl | grep -q nginx; then echo "$NAME is not running." exit 1 fi $NGINX_BIN -s stop if [ "$?" != 0 ] ; then echo " failed. Use force-quit" exit 1 else echo " done" fi ;; status) if netstat -tnpl | grep -q nginx; then PID=`pidof nginx` echo "$NAME (pid $PID) is running..." else echo "$NAME is stopped" exit 0 fi ;; force-quit) echo -n "Terminating $NAME... " if ! netstat -tnpl | grep -q nginx; then echo "$NAME is not running." exit 1 fi kill `pidof $NAME` if [ "$?" != 0 ] ; then echo " failed" exit 1 else echo " done" fi ;; restart) $0 stop sleep 1 $0 start ;; reload) echo -n "Reload service $NAME... " if netstat -tnpl | grep -q nginx; then $NGINX_BIN -s reload echo " done" else echo "$NAME is not running, can't reload." exit 1 fi ;; configtest) echo -n "Test $NAME configure files... " $NGINX_BIN -t ;; *) echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}" exit 1 ;;esac
添加配置文件(/usr/local/nginx/conf/vhost/mtrops.conf)
server { listen 8080; server_name 127.0.0.1 192.168.1.126; location / { include uwsgi_params; uwsgi_pass 127.0.0.1:9000; } location /static{ alias /opt/mtrop/statics; }}
三,配置uwsgi(/opt/mtrop/uwsgi.ini)
[uwsgi]# 通过uwsgi访问django需要配置成http# 通过nginx请求uwsgi来访问django 需要配置成socket# 9000 是django的端口号socket = :9000# web项目根目录chdir = /opt/mtrop# module指定项目自带的的wsgi配置文件位置module = mtrops_v2.wsgi# 允许存在主进程master = true# 开启进程数量processes = 3# 服务器退出时自动清理环境vacuum = true
四,启动
nohup /opt/venv/bin/uwsgi --ini uwsgi.ini &service nginx start