nginx反向代理返回编码的JavaScript和CSS

huangapple go评论47阅读模式
英文:

nginx reverse proxy returns encoded javascript and css

问题

当通过我的nginx代理访问网站时,只有html加载正确。返回的cssjavascripts是无意义的。但当我直接访问网站时,javascript加载正确。我不知道为什么会得到这种奇怪的响应。

所有请求都是GET请求,它们的响应始终是200。奇怪的是,日志中没有看到任何奇怪的东西。我还尝试关闭GZIP,但没有解决问题。

这是nginx配置:

server {
    listen 80;
    server_name wut.*;

    location / {
        proxy_pass http://10.10.1.60/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
英文:

When accessing the site via my nginx proxy only the html loads in correctly. The css and javascripts that are returned are gibberish. But when I directly access the site the javascript is loaded correctly. I don't Know why I get this weird response.

nginx反向代理返回编码的JavaScript和CSS

All the requests are GET-requests and their responses are always 200. Weird thing is I don't see anything strange in the logs. I also tried turning of GZIP but that did not solve it

This is the nginx conf:

server {
    listen 80;
    server_name wut.*;

    location / {
        proxy_pass http://10.10.1.60/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

答案1

得分: 0

"我已经打开了gzip,但仍然无法正常工作。原来需要将HTTP版本从1.0升级到1.1

通过在location块中添加以下行,问题就解决了:proxy_http_version 1.1;"

英文:

i had gzip turned on and still it did not work. turns out that you need to upgrade the http version from 1.0 --> 1.1

by adding this line in the location block the problem dissapears: proxy_http_version 1.1;

huangapple
  • 本文由 发表于 2023年4月17日 20:50:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76035348.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定