I have 2 versions of a web application that I want to server content from. I would like to setup nginx to try the first one, and if it gets a 404 then try the second one. (I mostly have this part working.) But I also want nginx to remember for a certain period of time that a requested URI was not found with web app 1 and try web app 2 first.
We are creating a new version of our application that has an all new code base. We want the webserver to try that one first, it is setup to 404 fast if the route passed isnt implemented yet so I then need the webserver to go back to the old version. That server will handle the error pages as well if it really is a 404.
Here is what i have so far:
server {
listen 80;
server_name domain.com
location @webapp {
include proxy.conf;
proxy_intercept_errors off;
proxy_pass http://webapp;
error_page 403 404 = @webapp2;
}
location @webapp2 {
include proxy.conf;
proxy_intercept_errors off;
proxy_pass http://webapp2;
error_page 403 404 = @error;
}
location / {
proxy_pass http://webapp;
include proxy.conf;
error_page 403 404 = @webapp2;
}
Then I have a file for each of the web apps thats basically:
upstream webapp {
server 127.0.0.1:81;
}
server {
listen 81;
server_name domain.com;
root /var/www/domain.com;
location / {
try_files $uri /index.php$is_args$args;
}
...
}
And the other one uses port 82, this works perfectly for fail over. But i cant get it to remember that web app 2 served a URI and to go straight their for all requests for the next X time.
Any help or advise on better ways to solve this will be greatly appreciated.