您的位置:首页 > 运维架构 > Nginx

django + gunicorn + nginx 部署

2016-12-21 11:11 393 查看

部署准备

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  django nginx gunicorn