What should my Nginx rewrite rules be for Rails with Passenger for page caching in a subdirectory? -
I am using Nginx 0.7.64, passenger 2.2.9, Rail 2.3.5. My page is set to the caching directory / public / cache, and I want to be able to serve pages cached on the HTTP request, but always press the rails app while requesting on HTTPS.
The bulk of my config looks like this:
server {80; Server_name website.com www.website.com; Proxy_set_header X-Forwarded-Proto http; Root / home / posted / website / current / public; Active on passenger; If (-f $ document_root / cache / $ request_filename.html) {re-type (. *) $ Document_root / cache / $ 1.html break; }} Listen to server {443; Server_name website.com www.website.com; Root / home / posted / website / current / public; Active on passenger; Proxy_set_header X-Forwarded-Proto https; Ssl on; ISBN: Ssl_certificate_key /home/deploy/website/shared/ssl/www.website.com.key; }
I hope that when I request website.com/about, I should be served at /public/cache/about.html, but instead I used Rail Server ( Shows the log shows it).
Was thinking that I could have an inappropriate slash (and in most instances, seeing $ document_root
is not seeing), I have also tried all of the following changes, of which Nobody does the work:
if (-f cache $ request_filename.html) {rewrite (. *) Cache $ 1.html breaks; } If (-f /cache$request_filename.html) {re-type (. *) /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 have also removed the root
, passenger_enabled
, and a separate location /
block, But it also does not work. I have also reviewed the statements so that passenger_disabled
will come in the end I have also tried to use the $ uri
clearly I have some misunderstandings I am!
This is a bit simpler, because I have an XML API that has been cached in locations (possibly rewrite rule except for .html
parts), as well as me < Service of code> public / cache / index.html will be required when the root of website.com
will be requested. I just want to work on one piece.
Any help is appreciated!
Update
conditionally
if (-f $ document_root / cache $ request_uri.html)
seems to work! However, I would think that rewriting will not work! Trying
if (-f $ document_root / cache $ request_uri.html) {re-type (. *) /cache$1.html break; break; }
writes the URL in the form of /cache/cache/about.html.html
and sends it to the rail, which is fast enough to double it Yes, yes! But if I just rewrite / cache $ 1
then it sends / cache / cache / about
to the rail, and $ 1.html < / Code> sends
/ about.html.html
to the rail, and simply sends $ 1
about /
which goes to the rail It does not kill the cash and it is obviously not the right behavior. NGNA has to write it again and then the traveler is writing it again?
The answer was found here:
Confirm ends:
# root if (-f $ document_root / cache / $ uri / index.html) {re-type (. *) /cache/$1/index.html break; } # Of pages like /, cached from .html but without (-f $ document_root / cache / $ uri.html) {re-type (. *) /cache/$1.html break; } # Pages like /api/v1/something.xml, XML as cache if (-f $ document_root / cache / $ uri) {re-type (. *) / Cache / $ 1 break; }
Comments
Post a Comment