控制默认缓存控制:无缓存,通过Laravel Forge服务安装专用Nginx/php-fpm7.4

控制默认缓存控制:无缓存,通过Laravel Forge服务安装专用Nginx/php-fpm7.4,nginx,cache-control,ubuntu-20.04,Nginx,Cache Control,Ubuntu 20.04,是否有任何方法可以更改所有html类型文件上当前设置为no Cache,private的Cache Control头的默认值 我曾尝试通过nginx.conf以及Forge panel来改变这种行为,但似乎没有任何效果 除了实际的html # FORGE CONFIG (DO NOT REMOVE!) include forge-conf/www.example.com/before/*; server { listen 443 ssl http2; listen [::]:4

是否有任何方法可以更改所有
html
类型文件上当前设置为
no Cache,private
Cache Control
头的默认值

我曾尝试通过
nginx.conf
以及Forge panel来改变这种行为,但似乎没有任何效果

除了实际的
html

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/www.example.com/before/*;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name www.example.com;
    server_tokens off;
    root /home/forge/www.example.com/public;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/www.example.com/824182/server.crt;
    ssl_certificate_key /etc/nginx/ssl/www.example.com/824182/server.key;

    ssl_protocols TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;
    
    add_header Last-Modified $date_gmt;
    if_modified_since off;
    etag off;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload' always;

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/www.example.com/server/*;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/www.example.com-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        try_files $query_string/index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
    
    # browser caching of static assets
    location ~* \.(ico|css|js|json|gif|jpeg|jpg|png|woff|ttf|otf|svg|woff2|eot)$ {   
        expires 30d;                                                                                            
        access_log off;
        add_header Pragma public;
        add_header Cache-Control "public, max-age=2592000";
    } 

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/www.example.com/after/*;

您可以尝试以下配置吗

map $uri $cache_control {
    ~\.html$  "public, max-age=2592000";
}

server {
    ...
    location / {
        add_header Cache-Control $cache_control;
        try_files $uri $uri/ /index.php?$query_string;
    }
    ...
    location ~ \.php$ {
        try_files $query_string/index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_hide_header Cache-Control;
        include fastcgi_params;
    }
    ...

它所做的只是在现有的
缓存控件中添加了额外的
public,max age=2592000
,因此现在它看起来是
无缓存,private,public,max age=2592000
您是否试图更改从上游返回的
缓存控件
头?正确,我不需要默认行为,我需要尽可能长时间地缓存它need@AlexB添加
fastcgi\u hide\u头缓存控件指令到您的FastCGI
位置
块,请查看更新的答案。现在尝试它将在一分钟后报告,而且我已将
~\.html$
更改为
~\.*$
,因为我不特别提供带有
.html
的页面