<table style="height: 30px; background-color: #afeeee; width: 1266px; ; width: 1266px;" border="0">
<tr><td><span style="font-size: 16px;">一、Nginx安装部署</td>
</tr></table>
官方文档:http://Nginx.org/
安装当前稳定版本:1.12.2Nginx.org/en/download.html">
安装步骤:
启动与停止Nginx:
/usr/local/Nginx/sbin/Nginx -s stop
安装:
配置uwsgi:uwsgi可支持命令行启动、json格式配置文件启动、ini格式配置文件启动、xml配置文件启动
命令行启动:可以使用uwsgi --help查看启动选项
ini配置文件启动:
常用配置参数
log-maxsize :
logto :输出日志到文件logto = /tmp/uwsgi.log
在django项目中与manage.py同级目录创建配置文件,这里命名为uwsgi.ini
启动uwsgi服务
<table style="height: 30px; background-color: #afeeee; width: 1266px; ; width: 1266px;" border="0">
<tr><td><span style="font-size: 16px;">三、配置Nginx</td>
</tr></table>
Nginx主要位置是代理转发作用
Nginx.conf
<span style="color: #008000;">error_log logs/error.log notice;
<span style="color: #000000;">
pid logs/<span style="color: #000000;">Nginx.pid;
events {
worker_connections 1024<span style="color: #000000;">;
}
http {
include mime.types;
default_type application/octet-<span style="color: #000000;">stream;
access_log logs/<span style="color: #000000;">access.log ;
sendfile on;
keepalive_timeout 65<span style="color: #000000;">;
gzip on;
server {
listen 80<span style="color: #000000;">;
server_name localhost;
location /<span style="color: #000000;"> {
root html;
index index.html index.htm;
}
error_page </span>500 <a href="/tag/502/" target="_blank" class="keywords">502</a> 503 504 /<span style="color: #000000;">50x.html;
location </span>= /<span style="color: #000000;">50x.html {
root html;
}
}
server {
listen </span>80<span style="color: #000000;">;
server_name </span>10.193.15.50<span style="color: #000000;">;
charset UTF</span>-8<span style="color: #000000;">;
error_log logs</span>/<span style="color: #000000;">devops_error.log;
client_max_body_size 75M;
location </span>/<span style="color: #000000;"> {
include uwsgi_params;
uwsgi_pass </span>127.0.0.1:8000<span style="color: #000000;">;
uwsgi_read_timeout </span>5<span style="color: #000000;">;
}
location </span>/<span style="color: #000000;">static {
expires 30d;
autoindex on;
add_header Cache</span>-<span style="color: #000000;">Control private;
alias </span>/opt/app/devops/static/<span style="color: #000000;">;
}
}
}
启动Nginx,访问项目url若出现
重启脚本centos6.x
then
psid=
ps aux | grep <span style="color: #800000;">"</span><span style="color: #800000;">uwsgi</span><span style="color: #800000;">"</span> | grep -v <span style="color: #800000;">"</span><span style="color: #800000;">grep</span><span style="color: #800000;">"</span> | wc -<span style="color: #000000;">l
<span style="color: #0000ff;">if [ $psid -gt 4<span style="color: #000000;"> ]
then
echo <span style="color: #800000;">"<span style="color: #800000;">uwsgi is running!<span style="color: #800000;">"<span style="color: #000000;">
exit 0
<span style="color: #0000ff;">else<span style="color: #000000;">
uwsgi /xxx/www/uwsgi.ini --daemonize /var/log/uwsgi.log --post-buffering 32768 --buffer-size 32768<span style="color: #000000;">
echo <span style="color: #800000;">"<span style="color: #800000;">Start uwsgi service [OK]<span style="color: #800000;">"<span style="color: #000000;">
fi
<span style="color: #0000ff;">elif [ $1 =<span style="color: #000000;"> stop ];then
killall -9<span style="color: #000000;"> uwsgi
echo <span style="color: #800000;">"<span style="color: #800000;">Stop uwsgi service [OK]<span style="color: #800000;">"
<span style="color: #0000ff;">elif [ $1 =<span style="color: #000000;"> restart ];then
killall -9<span style="color: #000000;"> uwsgi
uwsgi --ini /xxx/www/uwsgi.ini --daemonize /var/log/uwsgi.log --post-buffering 32768 --buffer-size 32768 --touch-reload <span style="color: #800000;">"<span style="color: #800000;">/xxx/www/reload.set<span style="color: #800000;">"<span style="color: #000000;">
echo <span style="color: #800000;">"<span style="color: #800000;">Restart uwsgi service [OK]<span style="color: #800000;">"
<span style="color: #0000ff;">else<span style="color: #000000;">
echo <span style="color: #800000;">"<span style="color: #800000;">Usages: sh uwsgiserver.sh [start|stop|restart]<span style="color: #800000;">"<span style="color: #000000;">
fi