What should my Nginx rewrite rules for Rails with Passenger for caching pages in a subdirectory?

I am using Nginx 0.7.64, Passenger 2.2.9, Rails 2.3.5. I have a page caching directory installed in / public / cache, and I would like to be able to serve cached pages on request via HTTP, but always click on the Rails application on request via HTTPS.

The main part of my configuration 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 expect that when I ask website.com/about, I should submit /public/cache/about.html, but instead I got to the Rails server (the tail of the log shows it).

I think that I may have the wrong slash (and not seeing $document_rootin most examples), I also tried all of the following options, 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;
}

root, passenger_enabled location /, . , passenger_enabled . $uri. , - !

, XML api, ( , .html), public/cache/index.html, website.com. , - .:)

!

if (-f $document_root/cache$request_uri.html)

, ! , , !

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

URL /cache/cache/about.html.html Rails, . , ! /cache$1, /cache/cache/about Rails, $1.html /about.html.html Rails, $1 /about, Rails . , . Nginx , Passenger ?

+3
1

: nginx

:

# root
if (-f $document_root/cache/$uri/index.html) {
  rewrite (.*) /cache/$1/index.html break;
}

# pages like /about, cached with .html but accessed without
if (-f $document_root/cache/$uri.html) {
  rewrite (.*) /cache/$1.html break;
}

# pages like /api/v1/something.xml, cached as xml
if (-f $document_root/cache/$uri) {
  rewrite (.*) /cache/$1 break;
}
+4

Source: https://habr.com/ru/post/1729825/


All Articles