【问题标题】:Django REST framework absolute urls with nginx always return 127.0.0.1带有 nginx 的 Django REST 框架绝对 URL 始终返回 127.0.0.1
【发布时间】:2013-11-09 06:23:45
【问题描述】:

我有一个在 nginx 后面的 gunicorn / django(使用 django-rest-framework)上运行的应用程序,使用 hyperlinkedmodelserializer 时,其余框架返回的 url 有点问题。他们总是返回 http://127.0.0.1/ 之类的东西,而不是我的主机名。

你能帮忙吗?

【问题讨论】:

  • 您的settings.py 文件是什么样的?
  • 您好,我发现了问题——nginx配置错误——我没有设置proxy_set_header Host $host;也不是 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;。从我在代码中找到的关于绝对 url 生成的内容来看,django 可以同时使用这两种方法。

标签: python django rest nginx


【解决方案1】:

没关系,我发现我忘了放

proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

在我的 nginx 配置中。现在工作正常。

【讨论】:

    猜你喜欢
    • 2020-07-09
    • 2018-08-06
    • 2019-10-29
    • 1970-01-01
    • 2017-08-21
    • 2014-10-16
    • 2017-01-30
    • 2019-05-01
    • 2015-05-10
    相关资源
    最近更新 更多