django+uwsgi+nginx部署

前端之家收集整理的这篇文章主要介绍了django+uwsgi+nginx部署前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<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_version=Nginx-1.12 [ -f Nginx....//Nginx.org/download/Nginx_version.tar.gz [ -f Nginx_version.tar.gzNginx_version下载完毕!Nginx依赖包......++ gcc openssl-devel pcre-devel zlib-devel -Nginx·......Nginx_version.tar.gz echo Nginx_version ./configure --prefix=/usr/local/Nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-&&Nginx 安装完毕!

启动与停止Nginx

/usr/local/Nginx/sbin/Nginx -c /usr/local/Nginx/conf/Nginx.conf

<span style="color: #008000;">#<span style="color: #008000;">###停止
/usr/local/Nginx/sbin/Nginx -s stop

官方文档:http://uwsgi-docs-zh.readthedocs.io/zh_CN/latest/Configuration.html

安装:

方法一 方法二: python3 -m pip install uwsgi

 配置uwsgi:uwsgi可支持命令行启动、json格式配置文件启动、ini格式配置文件启动、xml配置文件启动

命令行启动:可以使用uwsgi --help查看启动选项

uwsgi --http :8000 --chdir /opt/app/devops --wsgi-file /opt/app/devops/devops/wsgi.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191

ini配置文件启动:

常用配置参数

http : 数量 数量,等同于processes(官网的说法是spawn the specified number ofworkers / processes) -file : 后台运行,并将日志打到指定的日志文件或者udp服务器(daemonize uWSGI)。实际上最常用的,还是把运行记录输出到一个本地文件上。 文件的位置,记录主进程的pid号。 退出的时候自动清理环境,删除unix socket文件和pid文件(try to remove all of the generated file/sockets)
log-maxsize :
logto :输出日志到文件logto = /tmp/uwsgi.log

在django项目中与manage.py同级目录创建配置文件,这里命名为uwsgi.ini

配置文件 socket = :8000 绝对路径 chdir = /opt/app/名称.wsgi)可以理解为wsgi.py的位置 module = master = processes = 4 退出时候回收pid文件 vacuum = log-maxsize = 500000000 logto = /tmp/uwsgi.log

启动uwsgi服务

uwsgi --ini /opt/app/devops/uwsgi.ini --daemonize /tmp/uwsgi.log

<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

worker_processes 2<span style="color: #008000;">#<span style="color: #008000;">error_log logs/error.log;<span style="color: #008000;">

<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;"&gt;50x.html;
    location </span>= /<span style="color: #000000;"&gt;50x.html {
        root   html;
    }
  }
server {
listen         </span>80<span style="color: #000000;"&gt;; 
server_name    </span>10.193.15.50<span style="color: #000000;"&gt;;
charset UTF</span>-8<span style="color: #000000;"&gt;;
error_log       logs</span>/<span style="color: #000000;"&gt;devops_error.log;

client_max_body_size 75M;

location </span>/<span style="color: #000000;"&gt; { 
    include uwsgi_params;
    uwsgi_pass </span>127.0.0.1:8000<span style="color: #000000;"&gt;;
    uwsgi_read_timeout </span>5<span style="color: #000000;"&gt;;
}   
location </span>/<span style="color: #000000;"&gt;static {
    expires 30d;
    autoindex on; 
    add_header Cache</span>-<span style="color: #000000;"&gt;Control private;
    alias </span>/opt/app/devops/static/<span style="color: #000000;"&gt;;
 }
   }    

}

启动Nginx,访问项目url若出现

重启脚本centos6.x

[ ! -n <span style="color: #0000ff;">if [ $1 =<span style="color: #000000;"> start ]
then
psid
=ps aux | grep <span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;uwsgi</span><span style="color: #800000;"&gt;"</span> | grep -v <span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;grep</span><span style="color: #800000;"&gt;"</span> | wc -<span style="color: #000000;"&gt;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

猜你在找的Nginx相关文章