gpt4 book ai didi

nginx - nginx proxy_pass 中的变量导致 MIME 类型问题

转载 作者:行者123 更新时间:2023-12-05 03:54:09 26 4
gpt4 key购买 nike

我整个晚上都在谷歌上详细搜索了这个主题,但似乎无法理解这一点。我的情况如下:我的网络上有一个 NAS(主机名 MYHOSTNAME),我在另一台机器上也有一个 nginx 反向代理。我想为我的配置文件的 proxy_pass 部分使用一个变量,以防代理启动时 NAS 离线,它不会崩溃。基本上:

location /MYNAS {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://MYHOSTNAME:1234/;

工作正常。但是以下内容:

location /MYNAS {
set $VAR_HOSTNAME MYHOSTNAME;
resolver 192.168.x.x;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://$VAR_HOSTNAME:1234/;

给我带来麻烦。该网页加载了一个空白页面,在浏览器控制台中,我可以看到:

Refused to execute script from 'something' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
mydynamicdns/:1 Refused to execute script from 'somethingelse' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
desktop.js?v=1562143318:3 Uncaught TypeError: Cannot read property 'diskless' of undefined
at _S (desktop.js?v=xxx:x)
at aa.defaultCSSSelectors (desktop.js?v=xxx:x)
at desktop.js?v=xxx:x
at ext-all.js?v=xxx:x
at b (ext-all.js?v=xxx:x)

我对如何进行这项工作的新想法不知所措......在此先感谢大家,我们将不胜感激。

最佳答案

我认为我无法完全解释原因的技术细节,但通过在 nginx 中打开调试并与有效的用例进行比较,我最终认为我需要取消/MYNAS/部分。关键是下面的重写行:

location /MY_NAS/ {
set $MY_NAS http://MYNAS:1234;
resolver 192.168.x.x;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
rewrite /MY_NAS/(.*) /$1 break;
proxy_pass $MY_NAS;
}

希望有一天这能对其他人有所帮助,让您不再头疼。

关于nginx - nginx proxy_pass 中的变量导致 MIME 类型问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61238426/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com