Контроль над Cache-Control по умолчанию: no-cache, private Nginx / php -fpm7.4 установка через Laravel Forge service - PullRequest
0 голосов
/ 21 июня 2020

Есть ли способ изменить значение по умолчанию заголовка Cache-Control, которое в настоящее время установлено на no-cache, private для всех файлов типа html?

Я попытался изменить это поведение с помощью nginx.conf as а также через панель Forge, но у меня ничего не работает.

Все остальные файлы кэшируются, как и предполагалось, за исключением фактического 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/*;

1 Ответ

1 голос
/ 21 июня 2020

Можете ли вы попробовать следующую конфигурацию?

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