django + gunicorn + nginx 部署

来源:互联网 发布:怎么查看淘宝积分 编辑:程序博客网 时间:2024/05/23 15:48

部署准备

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
0 0
原创粉丝点击