2

To be more performant, we'd like to allow nginx to catch 404s before passing it off to the upstream apache server. Both servers have the same files.

More Info

We have a popular setup of serving static content on nginx and using apache upstream to serve dynamic content. We currently sync php along with static files to the nginx nodes from the upstream apache nodes. The same files are located on both layers. We simply serve only static files from nginx.

Currently, all non-static requests go upstream to the apache server (as previously intended). However, I realized nginx should be able to check for the existence of a .php file before deciding to pass it on upstream. That would mean handling a request much more efficiently.

I've been tinkering with a combination of try_files, then eventually if blocks to find a solution, but I haven't been successful. Please advise.

Thanks!

comb
  • 143
  • 1
  • 6

1 Answers1

1

There is a pretty simple solution:

server {
    listen      0.0.0.0;
    server_name fooo.org;
    access_log  /var/log/nginx/access.log main;

    root /var/www/fooo.org;

    location / {
        # If the file exists as a static file serve it directly without
        # running all the other rewite tests on it
        if (-f $request_filename) { 
            break; 
        }

        proxy_pass http://127.0.0.1:8080;
    }
}

please +1 if it helped ;) thanks

Franz Bettag
  • 897
  • 8
  • 7