django + gunicorn + nginx 部署

部署準備

1. 在django的settings.py中設置

DEBUG = False

ALLOWED_HOSTS = [‘*’]

STATIC_ROOT = ‘/var/www/html/xxx/static’

2. 收集靜態文件

##在部署的服務器中執行以下命令
$ python manage.py collectstatic

安裝配置nginx

yum install nginx

配置文件:

server {
        listen       10080 default_server;
        # listen       [::]:10080 default_server;

        access_log  /var/log/nginx/xxx.log;

        # Load configuration files for the default server block.

        location / {
            proxy_pass http://127.0.0.1:8000;
            proxy_set_header Host $host:10080;   #注意這裏,listen如果不是80,要指定端口號
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location /static/ {
            root /var/www/html/xxx; 
        }
}

啓動

1. 啓動gunicorn

nohup gunicorn --worker-class=gevent sysops.wsgi:application --reload &

2. 啓動nginx

service nginx start
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章