计划任务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

直接执行

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;
    }
}
```
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容