vue-cli的pwa模板,生产环境的nginx配置该怎么写?

vue-router的history模式要求写成

location / {
  try_files $uri $uri/ /index.html;
}

vue-cli的pwa模板的文档要求配置一些有关缓存的选项

location ~ (index.html|service-worker.js)$ {
  # ...
  add_header Last-Modified $date_gmt;
  add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
  if_modified_since off;
  expires off;
  etag off;
}

对nginx并不熟悉,我把这两个都写上的时候,似乎只能生效一个,求指点应该怎么写

阅读 4.3k
1 个回答

try_files $uri $uri/ /index.html;写到server块就行
比如

try_files $uri $uri/ /index.html;

location / {
  try_files $uri $uri/ /index.html;
}

location ~ (index.html|service-worker.js)$ {
  # ...
  add_header Last-Modified $date_gmt;
  add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
  if_modified_since off;
  expires off;
  etag off;
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题