网站测试阶段暂时禁用缓存的nginx设置

1. 禁用 PHP 页面缓存

nginx
location ~ \.php$ {
    fastcgi_pass php_wordpress1;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
    include fastcgi_params;
    
    fastcgi_param PHP_VALUE "open_basedir=/var/www/html:/tmp";
    fastcgi_param HTTPS on;
    fastcgi_param SERVER_PORT 443;

    # 测试阶段注释掉缓存配置
    # fastcgi_cache WORDPRESS;
    # fastcgi_cache_valid 200 301 302 10m;
    # fastcgi_cache_use_stale error timeout updating http_500 http_503;
    # fastcgi_cache_key "$scheme$request_method$host$request_uri";
    # add_header X-Cache $upstream_cache_status;
    
    # 添加无缓存头用于测试
    add_header Cache-Control "no-cache, no-store, must-revalidate";
    add_header Pragma "no-cache";
    add_header Expires "0";
}

2. 临时禁用静态文件缓存

nginx
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
    # 测试阶段禁用长期缓存
    expires -1;
    add_header Cache-Control "no-cache, no-store, must-revalidate";
    add_header Pragma "no-cache";
    access_log off;
}

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注

滚动至顶部
×
问题求助