Homepage cache and cookies

Ph. Gras ph.gras at worldonline.fr
Fri Mar 25 22:09:01 UTC 2016


Hello John!

I think you can do this better with sessions in NginX.

I've made a script that checks if a client is a bot or not,
by testing if the Google Analytics cookie is here, or not.

If it is, the client can post a comment or login. If not, the
server is giving a fake page.

In my PHP script :
*****************************************************
		$host = $_SERVER['REMOTE_ADDR'];
		$session_id = session_id();
		$session_name = session_name();
		[…]
				if ( '' == $session_name ) {
					$session_name = '0';
					session_start();
					echo '<html><head></head><body><h1>server busy, come back later!</h1></body></html>';
					exit();
				}
		[…]
*****************************************************
All pages are cached ;-)

Regards,

Ph. Gras
Le 25 mars 2016 à 22:33, john_smith77 <nginx-forum at forum.nginx.org> a écrit :

> So I found a solution and it seems like there is unexpected behavior from
> nginx. proxy_hide_header Set-Cookie does not seem to work when the location
> block is set to /
> 
> So:
> 
> location / { 
>     #Lots of other proxy stuff here...... 
>     proxy_hide_header "Set-Cookie"; } 
> 
> does not allow a cookie to ever be set, but: 
> 
> location ~home.html { 
>     #Lots of other proxy stuff here...... 
>     proxy_hide_header "Set-Cookie"; } 
> 
> will allow cache HITS but won't cache Set-Cookie headers. Clients are still
> able to get the cookies from the back end and will never get another users
> session cookies.
> 
> Posted at Nginx Forum: https://forum.nginx.org/read.php?2,265629,265658#msg-265658
> 
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx



More information about the nginx mailing list