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

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

如何在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"        }    ]}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4908775.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存