加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

django+uwsgi+nginx部署

发布时间:2020-12-13 21:42:26 所属栏目:Nginx 来源:网络整理
导读:table style="height: 30px; background-color: #afeeee; width: 1266px; ; width: 1266px;" border="0" tr tdspan style="font-size: 16px;" 一、nginx安装部署 /td /tr /table 官方文档:http://nginx.org/ 安装当前稳定版本:1.12.2 安装步骤: nginx_vers
<tr>
<td><span style="font-size: 16px;">一、nginx安装部署</td>
</tr></table>

官方文档:http://nginx.org/

安装当前稳定版本:1.12.2

安装步骤:

nginx_version=nginx-1.12 [ -f //nginx.org/download/ [ -f ++ gcc openssl-devel pcre-devel zlib-devel -/configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-&&

启动与停止nginx:

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

<table style="height: 30px; background-color: #afeeee; width: 1266px; ; width: 1266px;" border="0">

官方文档: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 : -file :
log-maxsize :
logto :

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

socket = :8000 chdir = /opt/app/ module = master = processes = 4 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 502 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读