【问题标题】:django cms - The requested URL /en/ was not found on this server - postgresql, nginx, gunicorndjango cms - 在此服务器上找不到请求的 URL /en/ - postgresql、nginx、gunicorn
【发布时间】:2015-03-31 23:30:00
【问题描述】:

程序版本:

django cms 3.0
python 3.4.2
django 1.7.3

设置:

DEBUG = False
ALLOWED_HOSTS = ['localhost','localhost:8000',]

使用 Sqlite 时,一切正常。
使用 PostgreSQL,我得到:The requested URL /en/ was not found on this server.
(使用 DEBUG - True,使用任一数据库都可以正常工作。)

我做错了什么?

我忘了说:

  • 我在 gunicorn 上运行 django-cms 和
  • 我将 nGinx 用于静态内容

【问题讨论】:

  • 您是否创建了任何页面?如果没有,您将收到 404。如果您已创建并发布了主页,请将您的 urls.py 文件发布到 dpaste.com 或其他地方并发布指向它的链接
  • 我最初没有创建任何页面。在我这样做之后,我得到:错误请求(400)。这是我的 urls.py dpaste.com/228M8KC。我可以在 debug = false 模式下看到我的页面。行为与“runserver”或 gunnicorn 相同。
  • 使用 ALLOWED_HOSTS = ['*',] 可以正常工作,但这不是正确的做法。

标签: python django postgresql django-cms


【解决方案1】:

所以,在我做了一些研究和调试之后,这就是我解决问题的方法:

在 nGinx 配置中,我有这个:

location / {
    proxy_pass http://localhost:8000;
}

当 DEBUG = False ALLOWED_HOSTS = ['.example.com','.example.com.',] 没有工作,因为

get_host() 返回 localhost:8000 并且应该返回 example.com

这解决了它:

location / {
    proxy_pass http://localhost:8000;
    proxy_set_header Host $http_host;
}

【讨论】:

    猜你喜欢
    • 2019-03-01
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-19
    • 2016-12-11
    • 2017-03-21
    • 2010-10-16
    相关资源
    最近更新 更多