博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Django + uWSGI + Nginx
阅读量:5264 次
发布时间:2019-06-14

本文共 3258 字,大约阅读时间需要 10 分钟。

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

 

转载于:https://www.cnblogs.com/xiao2er/p/10314443.html

你可能感兴趣的文章
D3.js 之 d3-shap 简介(转)
查看>>
制作满天星空
查看>>
类和结构
查看>>
CSS3选择器(二)之属性选择器
查看>>
adidas crazylight 2018 performance analysis review
查看>>
typeset shell 用法
查看>>
python 之 循环语句
查看>>
心得25--JDK新特性9-泛型1-加深介绍
查看>>
[转]ceph网络通信模块_以monitor模块为例
查看>>
HDOJ 1754 I Hate It(线段树基本操作)
查看>>
latex tree
查看>>
安装NVIDIA驱动时禁用自带nouveau驱动
查看>>
HDU-1255 覆盖的面积 (扫描线)
查看>>
css3学习01
查看>>
【USACO】 奶牛会展
查看>>
ActiveMQ笔记之点对点队列(Point-to-Point)
查看>>
继承和多态
查看>>
Dijkstra+计算几何 POJ 2502 Subway
查看>>
修复IE不能执行JS的方法
查看>>
程序员究竟该如何提高效率zt
查看>>