Using FastCGI cache on Joomla site

I’m trying to get the FastCGI cache working on a domain that hosts a Joomla site. There is obviously a problem because it tries to cache pages like login pages and doesn’t seem to recognize when a user is logged in at all. The administrator pages are, correctly, not cached.

I have the following statements in my template file (which gets copied to the domain’s nginx.conf file), but they don’t seem to have any effect:

		if ($request_uri ~* "/user/")
	{
	    set $no_cache 1;
	}

	#Don't cache if there is a cookie called PHPSESSID
	if ($http_cookie = "PHPSESSID")
	{
	    set $no_cache 1;
	}

	if ($cookie_joomla_user_state = "logged_in")
	{
	    set $no_cache 1;
	}

These statements are placed with the other “no_cache” statements, so I presume they are in the right place.

The login page is at domain.com/user/login-page, so I would have thought that the first condition would prevent caching that page, but it doesn’t — the page is still cached (as can be seen from the response headers).

I have checked that $cookie_joomla_user_state does have the value “logged_in” by setting a header which confirms this when the user is logged in. However, the above if-statement doesn’t cause the cache to be bypassed.

I would be grateful for any guidance on this question. Also, is there a way of checking whether these statements are actually executed? I’ve tried add_header inside the {…} of the if-statement, but this gives an error.

Thank you in advance!