黑帽联盟

 找回密码
 会员注册
查看: 211|回复: 0

[建站教程] discuz配置游客默认缓存(针对固定页面)

[复制链接]

908

主题

38

听众

3383

积分

管理员

Rank: 9Rank: 9Rank: 9

  • TA的每日心情
    郁闷
    2026-8-13 18:28
  • 签到天数: 1705 天

    [LV.Master]伴坛终老

    nginx.conf里面配置:
    fastcgi_cache_path /usr/local/nginx/data/cache levels=1:2 keys_zone=discuz:100m max_size=2g inactive=7d use_temp_path=off;

    enable-php.conf内配置:
            location ~ [^/]\.php(/|$)
            {
                try_files $uri =404;
                fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_index index.php;
                include fastcgi.conf;

                set $skip_cache 1;

                  if ($request_uri ~* "^/(thread-\d+-\d+-\d+\.html|forum-\d+-\d+\.html)$"){
                            set $skip_cache 0;
                  }

                      if ($cookie_8skG_2132_auth){
                      set $skip_cache 1;
                  }

                  if ($request_method = POST){
                      set $skip_cache 1;
                  }

                    fastcgi_cache discuz;
                    fastcgi_cache_key "$request_method$host$request_uri";
                    fastcgi_cache_valid 200 3m;
                    fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
                    fastcgi_cache_bypass $skip_cache;
                    fastcgi_no_cache $skip_cache;
                    fastcgi_cache_use_stale error timeout updating http_500 http_503;
                    fastcgi_cache_lock on;
                    add_header X-Cache-Status $upstream_cache_status;
            }


    观察浏览器响应头内是否有X--Cache-Status,且值为HIT

    您需要登录后才可以回帖 登录 | 会员注册

    发布主题 !fastreply! 收藏帖子 返回列表 搜索
    回顶部