admin管理员组文章数量:1420966
I have an issue with wordpress admin bar and nginx-fastcgi configuration. When I enable the fastcgi caching then the admin bar dissapear on some pages and in addition, there are few other issues with login. It appears that it's reasonable since this is how the caching works but I would like to solve it somehow since this type of caching really speeds up the site loading.
Here is the configuration I added to nginx.conf:
`# creates a FastCGI cache`
`fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=phpcache:100m max_size=10g inactive=60m use_temp_path=off;`
`# defines the key for cache lookup`
`fastcgi_cache_key "$scheme$request_method$host$request_uri";`
And in the sites-enabled:
location ~ \.php$ {
`fastcgi_cache phpcache;`
`fastcgi_cache_valid 200 301 302 60m;`
`fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503;`
`fastcgi_cache_min_uses 1;`
`fastcgi_cache_lock on;`
`add_header X-FastCGI-Cache $upstream_cache_status;`
}
Hope you will be able to help me.
Thanks :)
I have an issue with wordpress admin bar and nginx-fastcgi configuration. When I enable the fastcgi caching then the admin bar dissapear on some pages and in addition, there are few other issues with login. It appears that it's reasonable since this is how the caching works but I would like to solve it somehow since this type of caching really speeds up the site loading.
Here is the configuration I added to nginx.conf:
`# creates a FastCGI cache`
`fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=phpcache:100m max_size=10g inactive=60m use_temp_path=off;`
`# defines the key for cache lookup`
`fastcgi_cache_key "$scheme$request_method$host$request_uri";`
And in the sites-enabled:
location ~ \.php$ {
`fastcgi_cache phpcache;`
`fastcgi_cache_valid 200 301 302 60m;`
`fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503;`
`fastcgi_cache_min_uses 1;`
`fastcgi_cache_lock on;`
`add_header X-FastCGI-Cache $upstream_cache_status;`
}
Hope you will be able to help me.
Thanks :)
Share Improve this question edited Jun 30, 2019 at 22:47 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Jun 30, 2019 at 20:53 MosheMoshe 135 bronze badges 1- Someone told me that I need to disable the caching for logged in uses. How do I do it? – Moshe Commented Jun 30, 2019 at 21:06
1 Answer
Reset to default 2What you're looking for is to set a variable that determines whether a user is logged in (and other circumstances where you don't want caching), then pass that variable to fastcgi_cache_bypass
and fastcgi_no_cache
:
So in your server{}
block you want something like this:
set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
}
if ($query_string != "") {
set $skip_cache 1;
}
# Don't cache uris containing the following segments
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $skip_cache 1;
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}
And then add these to your php location {}
block where you also have your fastcgi_cache
setting:
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
See this for more info: https://easyengine.io/wordpress-nginx/tutorials/single-site/fastcgi-cache-with-purging/
Doing just that worked for me, but if you follow the full guide and set up conditional purging that will probably get you the best results.
本文标签: nginxfastcgi caching causes admin bar to dissapear
版权声明:本文标题:nginx-fastcgi caching causes admin bar to dissapear 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745338922a2654169.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论