nginx+gunicorn运行django

本文介绍如何使用Gunicorn部署Django应用,并配置Nginx作为反向代理服务器。包括安装Gunicorn和Django,以及Nginx的配置示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

运行django的有fast_cgi、uwsgi和gunicorn等 其中uwsgi效能最好 但配置稍复杂 而gunicorn配置简单

在windows下通过源码安装gunicorn报错 缺少fcntl模块  最好在linux环境下使用


首先安装gunicorn 和django

 

gunicorn_django -D -b 127.0.0.1:8000

 

然后配下nginx

server {

        listen       80;

        server_name 域名;

 

        root django项目目录 ;

 

        location /static/ {

            if ($query_string) {

                expires max;

#               log_not_found off;

             }

         }

 

    location / {

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;

        proxy_redirect off;

 

        if (!-f $request_filename) {

            proxy_pass http://127.0.0.1:8000;

            break;

        }

    }

 

        #error_page  404              /404.html;

 

        # redirect server error pages to the static page /50x.html

        #

        error_page 500 502 503 504 /media/50x.html;

        }


参考网站(http://gunicorn.org/, )

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值