Welcome! Log In Create A New Profile

Advanced

Conditional proxy

Posted by pshah 
Conditional proxy
February 24, 2010 11:21PM
Hi,

Thanks for creating this amazing product :) I'm using nginx as a proxy and apache as the backend webserver. This is what I'm trying to do:

Cache everything for guest users for 2 minutes. If user is logged in, do not cache at all and just pass the request to the backend server. Logged in users always users have a cookie loggedin=yes. I sort of have a working setup with some problems. Below is the snippet of my nginx.conf file.

# If login.php do not cache
location = /login.php
{
proxy_pass http://127.0.0.1:81;

}

location /
{
set $cache 1;
set $myvar 0;
# Is loggedin cookie set?
if ($http_cookie ~* "loggedin=yes(;|$)")
{
set $myvar $remote_addr;
}
proxy_pass http://127.0.0.1:81;
proxy_cache main;
proxy_cache_key $scheme$proxy_host$uri$is_args$args$myvar;
proxy_cache_valid 200 2m;
proxy_cache_valid 404 1m;
proxy_cache_use_stale error timeout invalid_header;
}

I'm also sending header('X-Accel-Expires: 0'); in my php app if a user is logged in.

With the above setup, nginx doesn't cache pages for logged in users (yeah that works!), but the problem is, nginx won't pass any cookie headers to the browser for any pages other than login.php even for logged in users. Is there a way to make nginx just behave like login.php for all pages if a user is logged in?

In essence, can nginx just pass the request to the backend server if a user is logged in?


Thanks a lot.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 280
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready