【问题标题】:Why is the "last-modified" incorrect on Google Cloud Platform App Engine?为什么 Google Cloud Platform App Engine 上的“最后修改”不正确?
【发布时间】:2020-11-16 03:11:32
【问题描述】:

我多次在 Google Cloud Platform App Engine 上部署我的网站。使用如下设置:

app.yaml

runtime: nodejs10

当我在 localhost 上测试它时,一切正常。 但是当我将它部署到谷歌云平台时。响应标头始终显示last-modified: Tue, 01 Jan 1980 00:00:01 GMT。 我已经通过[my-web].df.r.appspot.com 进行了检查,以确保问题出在 Google Cloud Platform 上。

有人有想法吗?

2020 年 10 月 7 日更新
遇到同样问题的朋友,请随时加入讨论here

【问题讨论】:

    标签: google-app-engine google-cloud-platform


    【解决方案1】:

    显然,这是设计行为,因为所有时间戳在应用引擎部署时均为零。见:https://issuetracker.google.com/issues/168399701

    我自己使用 express 发送静态文件。所以我通过不设置 etag 和 last-modified 头来解决它。例如:

    app.use("/", express.static(root, { etag: false, lastModified: false }));
    

    或者对于单个文件:

    app.get("/*", async (req, res) => {
      return res.sendFile("index.html", { root, lastModified: false, etag: false });
    });
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,即旧 index.html 被送达。问题在于生成的etag。即使文件发生了变化,etag 仍然保持不变。

      这导致文件从浏览器的缓存中提供,状态码为 304。罪魁祸首是我的 app.yaml 文件,它是

      runtime: nodejs10

      将其更改为以下解决了该问题。

      env: standard
      runtime: nodejs10
      default_expiration: '14d'
      
      handlers:
        - url: /static
          static_dir: build/static
          secure: always
      
        - url: /(.*\.(json|ico))$
          static_files: build/\1
          upload: build/.*\.(json|ico)$
          secure: always
      
        - url: .*
          static_files: build/index.html
          upload: build/index.html
          expiration: '5s'
          secure: always
      

      【讨论】:

      • 是那个运行时:nodejs10 导致了这个问题吗?
      • 目前还不清楚您是如何修复过度缓存的。你的 app.yaml 包含 default_expiration: '14d' 相反应该缓存文件 14d。
      【解决方案3】:

      这似乎是缓存引起的问题。为确保部署新的 index.html,您需要运行“gcloud beta app deploy --no-cache”,可能需要添加其他字段,例如 here 中提到的 app.yaml。这将确保与您的版本关联的新 index.html 被推送到容器中。

      【讨论】:

      • 感谢您的回答!我试过你的建议,但没有奏效。 :(
      • 嗨,本杰明,这个问题似乎正在影响更多的人,但是在寻找 GCP 问题跟踪器时,还没有人报告它。我建议您在此处打开问题跟踪器 issuetracker.google.com/issues/… 直接向 GCP 团队报告。
      【解决方案4】:

      我们遇到了同样的问题,即在重新部署 appengine 标准应用程序后,客户会选择旧版本的 index.html。这个问题似乎从 8 月中旬开始。我们最初发现在客户端 HTML 文件中添加一行,例如:似乎可以解决问题。但这不再有效。

      【讨论】:

        猜你喜欢
        • 2019-09-17
        • 1970-01-01
        • 2019-08-05
        • 2017-04-07
        • 1970-01-01
        • 1970-01-01
        • 2017-12-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多