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 :)

  • Someone told me that I need to disable the caching for logged in uses. How do I do it?
    – Moshe
    Jun 30, 2019 at 21:06

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.