最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

nginx-fastcgi caching causes admin bar to dissapear

programmeradmin0浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 2

What 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.

发布评论

评论列表(0)

  1. 暂无评论