鍍金池/ 問答/Linux  HTML/ vue-cli的pwa模板,生產(chǎn)環(huán)境的nginx配置該怎么寫?

vue-cli的pwa模板,生產(chǎn)環(huán)境的nginx配置該怎么寫?

vue-router的history模式要求寫成

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

vue-cli的pwa模板的文檔要求配置一些有關(guān)緩存的選項(xiàng)

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;
}

對(duì)nginx并不熟悉,我把這兩個(gè)都寫上的時(shí)候,似乎只能生效一個(gè),求指點(diǎn)應(yīng)該怎么寫

回答
編輯回答
心沉

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;
}
2018年8月8日 21:57