nginx - JHipster 应用程序中的浏览器缓存(NGINX + Spring Boot + VueJs)
问题描述
我使用 JHipster(Spring Boot 和 VueJS)开发了一个应用程序,并将其放在 NGINX 后面,以将所有传入的 80 和 443 请求反向代理到端口 8080。配置文件“prod”使用哈希码对所有资源进行后缀,因此只有最新的加载的版本。我的问题是,每次部署后,页面都会显示混乱,看起来浏览器尝试加载旧的 css 和 js 文件但没有成功。硬重置 (Shift+F5) 后,所有资源都将被加载并正确显示页面。但是一旦我部署了服务器,我就不能要求每个用户都按 Shift+F5。
任何帮助解决我的严重问题都非常感谢。
解决方案
我最终得到了这个配置:
upstream api {
server 127.0.0.1:9000;
}
server {
server_name myserver.com www.myserver.com;
access_log /var/log/nginx/reverse-access.log;
error_log /var/log/nginx/reverse-error.log;
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
gzip_comp_level 9;
etag on;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location /content {
proxy_pass http://api/content;
add_header Cache-Control max-age=31536000;
}
location /i18n {
proxy_pass http://api/i18n;
add_header Cache-Control max-age=31536000;
}
location /app {
proxy_pass http://api/app;
add_header Cache-Control max-age=31536000;
}
location /index.html {
proxy_pass http://api/index.html;
add_header Cache-Control no-cache;
}
location ^~ /.well-known/acme-challenge/ {
alias /var/www/acme-challenge/;
}
location / {
proxy_pass http://api;
try_files $uri $uri/ /index.html;
}
}
推荐阅读
- python - 在 sklearn 中 predict() 之后使用 score() 而无需重新计算
- c++ - 在主线程中工作时暂停后台线程?
- javascript - 错误:找不到迁移方法:向上
- android - java.lang.RuntimeException:执行doInBackground()时出错?
- reactjs - 在本地尝试此代码框时,我收到此错误缺少 index.htm 文件
- javascript - 如何使用 JS 知道特定键盘位置上的字符
- flutter - Flutter/Dart 如何选择日期并使用选择填充文本字段
- html - src 指向文件夹而不是文件?
- graphql - gatsby-source-ghost 无法在 Gatsby 中创建 Ghost 模式
- git - git push 错误 - 无法写入包文件