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

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

问题描述

我已经在Apache + mod_wsgi上设置了我的Django应用程序。为了提供静态文件,我正在使用Nginx,就像Django的项目网站上的建议一样。 http://docs.djangoproject.com/en/dev/howto/deployment/ modwsgi /



Apache在端口8081上运行,nginx在端口80上。现在有些人建议我的配置错误,我应该扭转角色的Apache和Nginx。我不知道为什么会这样。如果确实我的配置是错误的,为什么django网站建议使用错误的方法?

解决方案

你链接的django文档不建议您使用apache作为反向代理。他们只是建议你使用一个单独的网络服务器,所以我会说文档在这个问题上是不清楚的 - 他们没有提出任何错误。



我的初始答案是假设你将nginx作为反向代理,因为端口80是HTTP端口,当浏览器尝试去没有指定端口的URL时使用。



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

  location / {
#proxy / request to apache running django on port 8081
proxy_pass http://127.0.0.1:8081/;
proxy_redirect关闭;
}

位置/媒体/ {
#直接从nginx提供静态媒体
root / srv / anuva_project / www /;
到期30d;
break;
}

所有您需要做的是从您的apache配置中删除代理行,并添加如果你真的想从8081端口提供你的站点,你可能可以在8081端口上看到nginx,并且有apache听在不同的端口。关键是,apache位于某些晦涩的端口,只提供从nginx发送给它的请求,而静态文件服务由nginx处理。


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 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?

解决方案

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.

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.

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;
    }

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

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.

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天全站免登陆