nginx + uwsgi 部署python django web服务

2 篇文章 0 订阅
2 篇文章 0 订阅

1、nginx 配置

在nginx.conf中添加下面配置

server 
	{
			listen       80;
			server_name  webchat.com;
			
			location / {           
				root /var/www/webchat;					#django项目路径
				include  uwsgi_params;
				uwsgi_pass  127.0.0.1:9090;				#必须和uwsgi中的设置一致
				uwsgi_param UWSGI_SCRIPT webchat.wsgi;	#入口文件,即wsgi.py相对于项目根目录的位置,“.”相当于一层目录
				uwsgi_param UWSGI_CHDIR /var/www/webchat;	#项目根目录
				index  index.html index.htm;
				client_max_body_size 35m;
			}
	}

server {
	listen       80;
	server_name webchat.com;
	#charset koi8-r;

	#access_log  logs/host.access.log  main;

	location / {
			include        uwsgi_params;
			uwsgi_pass     127.0.0.1:8000;
			uwsgi_read_timeout 300;
	}

	location /static/ {
			alias  /var/www/webchat/static/;
			index  index.html index.htm;
	}

	location /media/ {
			 alias  /var/www/webchat/media/;
	}
	#error_page  404              /404.html;

	# redirect server error pages to the static page /50x.html
	#
	error_page   500 502 503 504  /50x.html;
	location = /50x.html {
		root   html;
	}
}


2、uwsgi配置

在项目/var/www/webchat下面创建uwsgi9090.ini,内容如下:

[uwsgi]
socket=:9090
chdir=/var/www/webchat
module=webchat.wsgi
master=true
processes=4
threads=2
py-autoreload=1
daemonize=/var/log/uwsgi9090.log


3、编写uwsgi启动、停止脚本uwsgi9090.sh,内容如下:

#!/bin/bash
### BEGIN INIT INFO
# Provides:             uwsgi9090
# Required-Start:       $network $remote_fs $syslog
# Required-Stop:        $network $remote_fs $syslog
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    uwsgi
# Description:          uwsgi is a high-performance web and proxy server
### END INIT INFO
if [ ! -n "$1" ]
then
    echo "Usages: sh uwsgiserver.sh [start|stop|restart]"
    exit 0
fi

if [ $1 = start ]
then
    psid=`ps aux | grep "uwsgi" | grep -v "grep" | wc -l`
    if [ $psid -gt 4 ]
    then
        echo "uwsgi is running!"
        exit 0
    else
        uwsgi /var/www/webchat/uwsgi9090.ini
        echo "Start uwsgi service [OK]"
    fi
elif [ $1 = stop ]; then
    killall -9 uwsgi
    echo "Stop uwsgi service [OK]"
elif [ $1 = restart ]; then
    killall -9 uwsgi
    uwsgi --ini /var/www/webchat/uwsgi9090.ini
    echo "Restart uwsgi service [OK]"
else

4、启动及停止

/bin/bash  uwsgi9090.sh start //启动

/bin/bash  uwsgi9090.sh stop //停止

/bin/bash  uwsgi9090.sh restart //重启




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值