計劃任務(wù)WebCron之nginx部署(4)

我們使用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

直接執(zhí)行

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;
    }
}
```
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容