我正在使用 WebTest 和 PageSpeed 进行优化。但两者都说没有实现缓存控制,尽管我在配置中已经实现了缓存控制。
配置如下:
server {
#listen 80;
root /var/www/html/public;
index index.html index.htm index.php;
server_name thewebsite.com; # managed by Certbot
location ~* \.(js|css|png|jpg|webp)$ {
expires 1M;
add_header Cache-Control "max-age=2629746, public";
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
location = /livewire/livewire.js {
expires off;
try_files $uri $uri/ /index.php?$query_string;
}
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
# Expires map
map $sent_http_content_type $expires {
default off;
text/html epoch;
text/css max;
application/javascript max;
~image/ epoch;
}
server {
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
listen 80 ;
server_name thewebsite.com;
return 404; # managed by Certbot
expires $expires;
}
答案1
我怀疑100万。 请尝试30 天代替100万并改变添加标题行到此。也语用向旧客户端提供缓存标头,一些在线工具可能会考虑它们:
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";