您的位置:首页 > 编程语言 > Go语言

django + ngxin + uwsgi 站点部署

2016-04-07 16:10 525 查看
第一步 创建项目启动脚本

# 创建项目启动脚本 vi /etc/init.d/project_name
#!/bin/bash
# Description: uwsgi manager scripts
# chkconfig: - 65 45
#
# Get function from functions library
. /etc/init.d/functions

pidfile='/var/www/run/project_name.pid'
conf='/var/www/config/project_name.ini'

startcmd="/usr/bin/uwsgi --pidfile $pidfile -i $conf"
stopcmd="/usr/bin/uwsgi --stop $pidfile"
reloadcmd="/usr/sbin/uwsgi --reload $pidfile"
start() {
if ps -ef |grep -v grep |grep -q $pidfile;then
echo -n "uwsgi aleardy running ... "
echo
else
echo -n "Starting uwsgi: "
$startcmd &> /dev/null
if [ $? -eq 0 ];then
### Create the lock file ###
success $"uwsgi startup"
echo
else
failure $"uwsgi startup"
echo && exit 1
fi
fi
}
stop() {
echo -n "Stopping uwsgi: "
### Stop
$stopcmd
if [ $? -eq 0 ];then
### Now, delete the lock file ###
success $"uwsgi shutdown"
echo
else
rm -f $lockfile
failure $"uwsgi shutdown"
echo && exit 1
fi
}

reload() {
echo -n "Reloading uwsgi: "
$reloadcmd
if [ $? -eq 0 ];then
success $"uwsgi reload"
echo
else
failure $"uwsgi reload"
echo && exit 1
fi
}

status() {
if ps -ef |grep -v grep |grep -q $pidfile;then
pidnum=$(cat $pidfile)
echo "uwsgi (pid $pidnum) is running..."
else
echo "uwsgi is stoped."
exit 1
fi
}
### main logic ###
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
sleep 1
start
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|status}"
exit 1
esac
exit 0


第二步 配置uwsgi

$ pip install uwsgi # 如未安装则先安装uwsgi

# vi /var/www/config/pad_math2_api.ini
[uwsgi]
;http-socket = :9101
socket = 127.0.0.1:9101
chdir = /var/www/pad_math2_api/esms/
pythonpath = /var/www/pad_math2_api/
env = DJANGO_SETTINGS_MODULE=esms.custom_settings
#module = django.core.handlers.wsgi:WSGIHandler()
module = django.core.wsgi:get_wsgi_application()
workers = 4
max-request = 1000
listen = 100
harakiri = 60
enable-threads = true
master = true
daemonize = /var/www/logs/pad_math2_api.uwsgi.log


第三步 配置nginx

# server {}
# include /usr/local/nginx/conf/pythonapp/*;

server {
listen       8101;
#server_name  192.168.0.76;
#access_log   logs/pad_math2_api.log main;
#error_log    logs/pad_math2_api_error.log;

location / {
include    uwsgi_params;
uwsgi_pass 127.0.0.1:9101;
}
}


server {
listen   80;
server_name  domain.cn www.domain.cn 101.201.48.0;
access_log  /data/logs/www.domain.cn_access.log;
error_log   /data/logs/www.domain.cn_error.log;

server_name_in_redirect off;
if ($host != www.domain.cn) {
rewrite ^(.*)$ http://www.domain.cn$1 permanent;
}

location ^~/site_media/ {
alias /data/www/yj_web/cms/site_media/;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov) {
access_log   off; # po co mi logi obrazk¨®w :)
expires      30d;
}

location ^~/ {
root   /data/www/yj_web/cms/templates/html;
index  index.html index.htm;
}

}


.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: