使 Apache 服务器中的缓存无效以使用 GatsbyJS

Invalidate cache in a Apache server to use GatsbyJS

我正在尝试使用 Gatsby 在 Apache 服务器中生成的网站来部署我的网站。根据 Gatsby docspublic/page-data

的缓存控制应该这样设置

The cache-control header should be cache-control: public, max-age=0, must-revalidate1

所以我在 public/page-data 文件夹中添加了一个 .htaccess 文件。出于某种原因,文件仍被缓存并出现错误,http 代码 409 冲突。

这是 .htaccess 文件的内容。

<FilesMatch "\.(html|htm|js|css|php|json)>
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</FilesMatch>

我做错了什么吗?有什么方法可以使 /public/page-data

的缓存无效

更新

我得到 409 的页面是这个

import React from 'react';
import PageContent from '../components/UI/PageContents';
import Layout from '../components/layout';
import SEO from '../components/seo';

const Contact = () => (
  <Layout innerPage="nk-contact" headerText="Contact us">
    <SEO title="Contact us" />
    <PageContent>
      <div className="row">
        <div className="col-md-6">
          <section className="mb-2">
            <h2 data-aos="fade-right">Contact us at</h2>
            {[
              '+91 1111111',
              '+91 2222222',
              '+91 2222222',
              '+91 2222222',
            ].map((number, index) => (
              <span key={`call-${index}`}>
                <a href={`tel:${number}`}>{number}</a>
                <br />
              </span>
            ))}

            <div className="py-1 mb-4">
              <h3 className="pt-3 pb-1 d-block">Email</h3>
              
              
            </div>
          </section>
        </div>
        <div className="col-md-6">
          <section className="mb-1">
            <h3 data-aos="fade-right">Our Timing</h3>
            <p>Office timings: 9.00 am - 6.00 pm.</p>
          </section>
        </div>
      </div>
      <hr />
      <h3 data-aos="fade-left" className="mb-3">
        Our Sales address
      </h3>
      <div className="row">
        <div className="col-md-6">
          <address>
            <strong> xxxxx</strong>
            <br />
            xxxxx
          </address>
        </div>
      </div>
    </PageContent>
  </Layout>
);

export default Contact;

public 文件夹在每次代码编译 (gatsby build) 中重做,所以很可能,您的 .htaccess 在每次代码部署中都被删除了。

这么说,你至少有两种方法:

  • 使用像gatsby-plugin-htaccess
  • 这样的插件
  • static folder 中创建 .htaccess。放置在项目根目录中的静态文件夹正在以相同的内部结构(并且没有 Gatsby 的处理或由其转换器处理)转译到 /public,所以如果你的位置是 /static/.htaccess(或 /static/page-data/.htaccess,如果需要)将在编译后出现在 public 文件夹中。