【发布时间】:2021-03-30 15:16:57
【问题描述】:
我已经部署了一个闪亮的应用程序,在 AWS 上运行一个闪亮的服务器。 nginx 服务器将请求重新路由到闪亮服务器的端口 3838。
在检查 Google Page Speed Insights (https://developers.google.com/speed/pagespeed/insights/) 时,我发现我的页面上的某些图像(.webp 格式)没有被缓存,这会减慢我的页面加载速度。
我尝试在 nginx 中设置缓存,如 here 所述,通过在我的 nginx 服务器配置中添加以下行:
location ~* \.(js|webp|png|jpg|jpeg|gif)$ {
expires 365d;
add_header Cache-Control "public, no-transform";
}
但是,这导致访问该网站时不再找到我的图片。
- 我必须在 nginx 中启用缓存而不是在闪亮服务器的某个地方启用缓存是否正确?
- 如果是这样,上面的解决方案有什么问题?
这里是nginx的conf文件,没有任何添加:
server {
listen 80;
listen [::]:80;
# redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
# Reverse proxy
location / {
proxy_pass http://localhost:3838/climate-justice/;
proxy_redirect http://localhost:3838/climate-justice/ $scheme://$host/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
proxy_buffering off;
}
# OCSP stapling
ssl_stapling on;
ssl_stapling_verify on;
}
【问题讨论】:
标签: nginx http-headers shiny-server cache-control