栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Django中资源URL中IP地址之后输出端口?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Django中资源URL中IP地址之后输出端口?

由于这个问题,我终于找到了解决图像URL的方法,这个问题稍有不同。

解决方案1

将端口号添加到nginx配置中的Host标头中,如下所示:

    location / {        proxy_pass http://hello_django;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_set_header Host $host:1337;         <<------- HERE        proxy_redirect off;    }

解决方案2

将nginx配置中的Host标头更改

http_host
如下:

    location / {        proxy_pass http://hello_django;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_set_header Host $http_host;         <<------- HERE        proxy_redirect off;    }

无论哪种情况,DURL(图像链接)现在都按以下方式返回图像URL 。

HTTP 200 OKAllow: GET, HEAD, OPTIONSContent-Type: application/jsonVary: Accept{    "count": 1,    "next": null,    "previous": null,    "results": [        { "id": 2, "user": 1, "title": "First post", "slug": "first", "image_url": "http://0.0.0.0:1337/mediafiles/publisher/background.gif",    <----HERE "content": "Second post content.", "draft": false, "publish": "2019-05-22", "updated": "2019-05-22T09:41:36.257605Z", "timestamp": "2019-05-22T07:58:01.471534Z"        }    ]}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371893.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号