首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >nginx :如何让nginx指向django

nginx :如何让nginx指向django
EN

Stack Overflow用户
提问于 2013-12-08 15:10:49
回答 2查看 331关注 0票数 0

我是nginx的新手。

我已经配置了nginx,gunicorn和django。

当我启动nginx时,它给出一个错误,因为,404 Not Found nginx/1.1.19

因为它没有指向django。

现在我需要在conf文件中使用location或root将nginx指向django(使用gunicorn作为中间件)。

谁能告诉我怎么向django指出nginx。

谢谢

EN

回答 2

Stack Overflow用户

发布于 2013-12-08 17:02:44

我有很多应用都是这样运行的:

代码语言:javascript
运行
复制
server {
    # listen, statics, media, etc

    location / {
        proxy_pass http://127.0.0.1:8000; # Gunicorn Server
    }
}
票数 0
EN

Stack Overflow用户

发布于 2013-12-08 17:06:52

首先,您需要实际运行gunicorn进程。手动完成此操作,最好使用supervisord等进程管理工具。以下是在django项目上运行gunicorn进程的示例supervisord脚本:

代码语言:javascript
运行
复制
[program:example]
user=ubuntu
group=ubuntu
directory=/home/ubuntu/dev/example
command=python manage.py run_gunicorn -c gunicorn_config.py
autostart=true
autorestart=true
redirect_stderr=True

然后你需要一个合适的nginx conf。下面是一个基于在生产环境中运行的站点的最小示例:

代码语言:javascript
运行
复制
server {
    listen 80;
    listen [::]:80 default_server ipv6only=on;
    server_name example.com;

    location / {
        proxy_pass http://localhost:8000;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    # use this if you're serving static assets locally
    location /static/ {  # make sure this is your STATIC_ROOT
        alias /home/ubuntu/dev/example/static/;
        access_log off;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20450839

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档