配置Django的,Apache和Nginx的 [英] Configuration for Django, Apache and Nginx

查看:174
本文介绍了配置Django的,Apache和Nginx的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置在Apache + mod_wsgi的我Django应用程序。为了满足我使用Nginx的静态文件,在Django的项目网站的建议。 <一href=\"http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/\">http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/

I've setup my Django application on Apache+mod_wsgi. To serve the static files I'm using Nginx, as suggested on Django's project website. http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/

Apache是​​在端口8081和Nginx的运行是在80端口现在有些人提出,我的配置是错误的,我应该反向Apache和Nginx的角色。我不知道为什么,应该是。而如果确实是我的配置是错误的,为什么会Django的网站显示错误的方法?

Apache is running on port 8081 and nginx is on port 80. Now some people have suggested that my configuration is wrong and I should reverse the roles of Apache and Nginx. I'm not sure why that should be. And if indeed my configuration is wrong, why would django website suggest the wrong method?

推荐答案

您挂不建议你使用Apache作为反向代理Django文档。他们只是建议你使用一个单独的Web服务器,所以我想说的文档是不是在这个问题上明确的 - 他们没有任何提示的错误

The django docs you linked to do not suggest you use apache as a reverse proxy. They simply suggest you use a separate web server, so I'd say the docs are not clear on that subject -- they are not suggesting anything wrong.

我最初的回答假设你有nginx的作为反向代理,因为80端口的HTTP端口,当浏览器试图去一个URL,没有指定的端口中使用的。

My initial answer was assuming you had nginx as a reverse proxy because port 80 is the HTTP port, the one used when a browser attempts to go to a url with no port specified.

有许多完整的指南,通过快速谷歌搜索设置的nginx + apache的,但这里的要点设立nginx的:

There are numerous complete guides to setting up nginx + apache via a quick google search but here is the gist for setting up nginx:

location / {
        # proxy / requests to apache running django on port 8081
        proxy_pass         http://127.0.0.1:8081/;
        proxy_redirect     off;
    } 

location /media/ { 
        # serve static media directly from nginx
        root   /srv/anuva_project/www/;
        expires 30d;
        break;
    }

所有你需要做的是从你的Apache配置中删除代理线,并添加委托书你nginx.conf来代替。

All you need to do is remove the proxy lines from your apache configuration and add the proxy statements to your nginx.conf instead.

如果你真的想从端口8081为你的网站,你可能有nginx的监听端口8081的Apache不同的端口上侦听。

If you really want to serve your site from port 8081, you could potentially have nginx listen on port 8081 and have apache listen on a different port.

问题的关键是,阿帕奇坐镇在一些不起眼的港口,只提供从nginx的发送给它的请求,而静态文件服务是由nginx的处理。

The point is, apache sits in some obscure port, only serving requests sent to it from nginx, while static file serving is handled by nginx.

这篇关于配置Django的,Apache和Nginx的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆