What should my Nginx rewrite rules be for Rails with Passenger for page caching in a subdirectory?
I'm using Nginx 0.7.64, Passenger 2.2.9, Rails 2.3.5.  I have my page caching directory set to /public/cache, and I'd like to be able to serve cached pages when requested over HTTP, but always hit the Rails app when requested over HTTPS.

The bulk of my config looks like this:

    server {
      listen 80;
      server_name website.com www.website.com;
      proxy_set_header X-Forwarded-Proto http;
      root /home/deploy/website/current/public;
      passenger_enabled on;
    
      if (-f $document_root/cache/$request_filename.html) { 
        rewrite (.*) $document_root/cache/$1.html break;
      }
    }
    
    server {
      listen       443;
      server_name website.com www.website.com;
      root /home/deploy/website/current/public;
      passenger_enabled on;
      proxy_set_header X-Forwarded-Proto https;
    
      ssl                  on;
      ssl_certificate      /home/deploy/website/shared/ssl/www.website.com.combined.crt;
      ssl_certificate_key  /home/deploy/website/shared/ssl/www.website.com.key;
    }

I anticipate that when I request website.com/about, I should be served /public/cache/about.html, but instead I hit the Rails server (tailing the log shows it).

Thinking I might have an inappropriate slash (and not seeing `$document_root` in most examples), I've also tried all of the following variations, none of which work:

    if (-f cache$request_filename.html) { 
      rewrite (.*) cache$1.html break;
    }
    
    if (-f /cache$request_filename.html) { 
      rewrite (.*) /cache$1.html break;
    }
    
    if (-f cache/$request_filename.html) { 
      rewrite (.*) cache/$1.html break;
    }
    
    if (-f /cache/$request_filename.html) { 
      rewrite (.*) /cache/$1.html break;
    }

I've also thrown the `root`, `passenger_enabled`, and rewrite rules into a separate `location /` block, but that also does not work.  I've also reordered the statements so that `passenger_enabled` would come at the end.  I've also tried using `$uri`.  Clearly I'm misunderstanding something!

This is a little bit simplified, since I also have an XML api that is cached in places (presumably the rewrite rule will be the same except for the `.html` parts), as well as I'll need to serve `public/cache/index.html` when the root of `website.com` is requested.  I just want to get any single piece of it working. :)

Any help is appreciated!
What should my Nginx rewrite rules be for Rails with Passenger for page caching in a subdirectory?
===

I'm using Nginx 0.7.64, Passenger 2.2.9, Rails 2.3.5.  I have my page caching directory set to /public/cache, and I'd like to be able to serve cached pages when requested over HTTP, but always hit the Rails app when requested over HTTPS.

The bulk of my config looks like this:

    server {
      listen 80;
      server_name website.com www.website.com;
      proxy_set_header X-Forwarded-Proto http;
      root /home/deploy/website/current/public;
      passenger_enabled on;
    
      if (-f $document_root/cache/$request_filename.html) { 
        rewrite (.*) $document_root/cache/$1.html break;
      }
    }
    
    server {
      listen       443;
      server_name website.com www.website.com;
      root /home/deploy/website/current/public;
      passenger_enabled on;
      proxy_set_header X-Forwarded-Proto https;
    
      ssl                  on;
      ssl_certificate      /home/deploy/website/shared/ssl/www.website.com.combined.crt;
      ssl_certificate_key  /home/deploy/website/shared/ssl/www.website.com.key;
    }

I anticipate that when I request website.com/about, I should be served /public/cache/about.html, but instead I hit the Rails server (tailing the log shows it).

Thinking I might have an inappropriate slash (and not seeing `$document_root` in most examples), I've also tried all of the following variations, none of which work:

    if (-f cache$request_filename.html) { 
      rewrite (.*) cache$1.html break;
    }
    
    if (-f /cache$request_filename.html) { 
      rewrite (.*) /cache$1.html break;
    }
    
    if (-f cache/$request_filename.html) { 
      rewrite (.*) cache/$1.html break;
    }
    
    if (-f /cache/$request_filename.html) { 
      rewrite (.*) /cache/$1.html break;
    }

I've also thrown the `root`, `passenger_enabled`, and rewrite rules into a separate `location /` block, but that also does not work.  I've also reordered the statements so that `passenger_enabled` would come at the end.  I've also tried using `$uri`.  Clearly I'm misunderstanding something!

This is a little bit simplified, since I also have an XML api that is cached in places (presumably the rewrite rule will be the same except for the `.html` parts), as well as I'll need to serve `public/cache/index.html` when the root of `website.com` is requested.  I just want to get any single piece of it working. :)

Any help is appreciated!