求助:关于使用 FastCGI 缓存 WordPress 的问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
dcd
V2EX    NGINX

求助:关于使用 FastCGI 缓存 WordPress 的问题

  •  
  •   dcd 2016-10-14 22:11:57 +08:00 3961 次点击
    这是一个创建于 3355 天前的主题,其中的信息可能已经有所发展或是发生改变。

    WordPress 安装了一个 WPTouch 插件,同一个网址,当移动设备和 PC 访问的时候会显示不同的页面。

    Nginx 启用了 FastCGI 缓存,根据 UA 生成不同的缓存文件。

    现在的问题是,当 A 手机访问的时候会生成缓存文件 A , B 手机访问的时候会生成缓存文件 B ;而我希望所有的移动设备只生成一个缓存文件 A , PC 端访问生成文件 B 。

    Nginx 配置如下:

    fastcgi_cache_path /home/www/wp-content/cache levels=1:2 keys_zOne=WORDPRESS:250m inactive=7d max_size=1G; #fastcgi_temp_path /home/www/wp-content/temp; fastcgi_cache_key "$scheme$request_method$host$request_uri$mobile_request"; fastcgi_cache_use_stale error timeout invalid_header http_500; fastcgi_ignore_headers Cache-Control Expires Set-Cookie; server { listen 80; server_name abc.com; index index.html index.htm index.php; root /home/www; set $skip_cache 0; set $mobile_request 0; if ($http_user_agent ~* '(iPhone|iPod|incognito|webmate|Android|dream|CUPCAKE|froyo|BlackBerry|webOS|s8000|bada|IEMobile|Googlebot\-Mobile|AdsBot\-Google)') { set $mobile_request 1; } if ($request_method = POST) { set $skip_cache 1; } if ($query_string != "") { set $skip_cache 1; } if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") { set $skip_cache 1; } if ($http_cookie ~* "wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { set $skip_cache 1; } location / { try_files $uri $uri/ /index.php?$args; rewrite /wp-admin$ $scheme://$host$uri/ permanent; } location ~ [^/]\.php(/|$) { try_files $uri =404; fastcgi_pass unix:/dev/shm/php-fpm.sock; #fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; fastcgi_cache WORDPRESS; fastcgi_cache_valid 200 301 302 7d; add_header X-UA-Detect $scheme$request_method$host$request_uri$mobile_request; add_header X-Frame-Options deny; add_header X-Content-Type-Options nosniff; add_header X-Cache "$upstream_cache_status From $host"; } location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { access_log off; log_not_found off; expires max; } location ~ /\. { deny all; access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } access_log /home/www/wp-content/logs/access.log; error_log /home/www/wp-content/logs/error.log; } 

    求各位大能帮忙看看该如何配置,感激不尽!

    8 条回复    2016-10-15 00:25:17 +08:00
    allenhu
        1
    allenhu  
       2016-10-14 22:36:04 +08:00 via Android
    你不累吗?我只用了 supercache
    dcd
        2
    dcd  
    OP
       2016-10-14 22:38:00 +08:00
    @allenhu 嘿嘿,不折腾成功誓不罢休!
    qwer1234asdf
        3
    qwer1234asdf  
       2016-10-14 22:57:17 +08:00
    我啥 cache 也没用。。
    qwer1234asdf
        4
    qwer1234asdf  
       2016-10-14 22:57:38 +08:00
    顺便说下,一个插件也没装。。。
    Technetiumer
        5
    Technetiumer  
       2016-10-14 23:08:18 +08:00
    拿 CDN 缓存整个网站,包括 HTML ,不是更好

    CloudFlare 设置页面规则缓存全部,包括 HTML 和 Ajax 请求,把 CloudFlare 当服务器,然而大陆访问 CloudFlare 并不快,如果百度云加速有页面规则,可以参考。

    另外,自适应的模板大法好
    dcd
        6
    dcd  
    OP
       2016-10-14 23:14:13 +08:00
    @qwer1234asdf
    @Technetiumer

    其实缓不缓存都无所谓,只是奇怪那里配置出错,使得`httpGETabc.com/11`在不同 UA 散列值会不同。
    hahasong
        7
    hahasong  
       2016-10-15 00:02:44 +08:00
    现在是 2016 年了,大家都在用 fpm
    wdlth
        8
    wdlth  
       2016-10-15 00:25:17 +08:00
    现在是 2016 年了,大家都在用 lua
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2646 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 29ms UTC 00:31 PVG 08:31 LAX 16:31 JFK 19:31
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86