【问题标题】:Nginx reverse proxy didnt load site correctlyNginx 反向代理没有正确加载站点
【发布时间】:2018-07-13 09:17:43
【问题描述】:

我有一个nginx 配置,它监听任何子域*.mydomain.com, 我想使用子域作为变量,将请求代理到其他站点。 这是我的nginx配置

server {

    listen 80;
    server_name "~^(?<subdomain>.*).mydomain.com";

    location / {
            resolver 1.1.1.1 1.0.0.1 ipv6=off;
            proxy_pass http://hosting.mydomain.com/$subdomain/;
            proxy_redirect off;
            access_log /var/log/nginx/proxy.log;
    }

}

当我直接请求该网站时,它会完美加载

Site placed on AWS S3, and bucket static website address cnamed to mydomain

但是,当我尝试通过user1.mydomain.com, the page didn't load images, and css访问时

This is the same site

并在浏览器网络面板中显示

Difference between direct and proxy access

这个问题是因为我有很多站点存储在 S3 存储桶中并且位于不同的文件夹中(文件夹名称用作子域)。 我想使用单个域通过子域访问所有这些。

提前致谢

【问题讨论】:

    标签: variables nginx static proxypass server-name


    【解决方案1】:

    您忘记代理传递 URI,您为每个请求提供 user1/index.html,包括 JS 和 CSS 请求,这就是为什么所有响应的大小都相同(2kb,user1/index.html 的大小),并且这也是为什么你在Enterprise_skeleton.bundle.js 的第一行中得到Uncaught SyntaxError: Unexpected token &lt; 的原因,因为它返回的是一个以&lt;!doctype html&gt; 开头的HTML 文档,而不是实际的JS 包。

    改变

    location / {
      proxy_pass http://hosting.mydomain.com/$subdomain/;
    }
    

    location / {
      proxy_pass http://hosting.mydomain.com/$subdomain$uri;
    }
    

    【讨论】:

      猜你喜欢
      • 2022-11-10
      • 2014-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-03
      • 1970-01-01
      相关资源
      最近更新 更多