Welcome! Log In Create A New Profile

Advanced

Re: try_files ignored in combination with error_page and named locations

Džen
April 04, 2012 01:28PM
On 04/04/2012 11:03, Edho Arief wrote:
[...]
> location /maintenance-static/ {
>
> }
>
> location / {
> try_files /$hostid-maintenance/ @backend;
> }

Right, this would work just fine. However, requests to /maintenance-static/
would still be possible even if /$hostid-maintenance/ doesn't exist (minor
problem, but maybe the backend uses /maintenance-static/ for some reason).

Unfortunately, I still haven't found a solution which pleases me. Just to
clarify, this is how I want the request to be processed (el-cheapo pseudo
code):

if the directory /maintenance/ exists, then
set root to /maintenance/
if the file $uri exists, then
serve $uri with errcode 503
otherwise
serve index.html with errcode 503
otherwise
proxy_pass http://backend

My new attempt:

recursive_error_pages on;
error_page 599 @maintenance;

if ( -d $document_root/$hostid-maintenance ) {
return 599;
}

location @maintenance {
root /var/nginx/$hostid-maintenance;
index index.html;
try_files $uri $uri/ /index.html /;
}

I used error code 599 because I noticed that for some reason the backend
might
raise an 503 error although $document_root/$hostid-maintenance doesn't
exist.
The result in such a situation would be unexpected (an infinite redirect
loop?).
By using an unused error code like 599, nginx's default 503 error page
will be
displayed instead, if the backend raises 503.

This configuration seems to work, but the 599 error code in the HTTP header
isn't that nice. Unfortunately, something like

error_page 599 =503 @maintenance;

doesn't result in what I expected (it will again just return nginx's default
503 error page, although error 503 is correctly set in the HTTP header).

I still think that I misunderstood something, am I right?

Kind regards

--
Džen

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

try_files ignored in combination with error_page and named locations

Džen April 03, 2012 04:32PM

Re: try_files ignored in combination with error_page and named locations

Ruslan Ermilov April 04, 2012 04:18AM

Re: try_files ignored in combination with error_page and named locations

Džen April 04, 2012 04:50AM

Re: try_files ignored in combination with error_page and named locations

Edho Arief April 04, 2012 05:06AM

Re: try_files ignored in combination with error_page and named locations

Džen April 04, 2012 01:28PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 110
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready