美文网首页我用 Linux
计划任务WebCron之nginx部署(4)

计划任务WebCron之nginx部署(4)

作者: _简_述_ | 来源:发表于2017-04-24 19:27 被阅读0次

我们使用nginx 将django的web端代理出去,这样就不需要一直使用python manage.py runserver 0.0.0.0:80

安装nginx

###1.增加nginx的yum源
vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

直接执行

yum -y install nginx

或者

yum --enablerepo=nginx install nginx
```
###2.安装uwsgi

```
pip install uwsgi
``` 
* crontab.ini

```
vim /data/crontab/conf/crontab.ini

[uwsgi]
; set the http port
;http-socket=:8001
; set socket port
socket=127.0.0.1:8000
;change to django project directory
chdir=/data/crontab
;load django
module=crontab.wsgi:application
daemonize = /data/crontab/logs/crontab.log
procname-prefix=crontab_
procname-master=master
processes=5
harakiri=200
max-request=5000
pythonpath=/data/crontab
wsgi-file=/data/crontab/crontab/wsgi.py
master=true
pidfile=/data/crontab/conf/crontab.pid

```

###3.uwsgi启动脚本
* webcron

```
vim /etc/init.d/webcron
#!/bin/bash
# chkconfig: 2345 10 90 
# description: webcron ....
if [ ! -n "$1" ]
then
    echo "Usages: sh uwsgi.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 --ini /data/crontab/conf/crontab.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
    /usr/bin/uwsgi --ini /data/crontab/conf/crontab.ini
    echo "Restart uwsgi service [OK]"

else
    echo "Usages: sh uwsgiserver.sh [start|stop|restart]"
fi
```
* 添加自启动

```
chkconfig --add webcron
chkconfig webcron on
```

###4.nginx配置

```
vim /home/nginx/conf/conf.d/webcron.conf

server {
    listen 80;
    server_name  172.88.0.122;

    location / {
        uwsgi_pass 127.0.0.1:8000;
        include uwsgi_params;
    }
}
```

相关文章

网友评论

    本文标题:计划任务WebCron之nginx部署(4)

    本文链接:https://www.haomeiwen.com/subject/jczdpttx.html