Welcome! Log In Create A New Profile

Advanced

Re: Rewriting

Francis Daly
May 26, 2013 05:24AM
On Sat, May 25, 2013 at 02:40:37PM +0300, wishmaster wrote:

[Back to the list]

Hi there,

> > I suspect that the final logic will be something like:
> >
> > if this is not an admin address
> > if the request is for /unav/something, then serve the file
> > else return http 503 with the content corresponding to /unav/index.html
> > else
> > give full normal access to the site
>
> My logic is: for all requests (from not an admin) like http://example.org/ use rewriting and show for clients simple temp html page.

I think that that statement is not specific enough for what you actually
want.

Because your html page "/unav/index.html" will include an image
"/unav/img.png", and you want that not to count as "all requests".

> But I think, I have solved it :)

If this does what you want it to, that's good.

When I tested, I saw some problems.

> if ($remote_addr ~ '_admin_IP_') {
> rewrite ^/(.*)$ /unav/$1 last;
> }
>
> location ^~ /unav/ {
> try_files $uri $uri/ /index.html;
> }

That will serve the content of /unav/index.html for all requests (unless
you have an /unav/unav/img.png, for example), but it goes through lots
of rewrites to get there.

> location / {
>
> try_files $uri $uri/ @opencart;
> }
>
> location @opencart {
> rewrite ^/(.+)$ /index.php?_route_=$1 last;
> }
>
> ... and so on .....

My suggestion:

use "geo" or "map" or even "if" to set a variable $site_looks_down,
which is "1" for users and "0" for admins.

if that variable is true, do nothing special for /unav/* urls, and return
503 for the rest.

have the 503 error return the content of /unav/index.html

have /unav/index.html include links like /unav/img.png


Overall, this is something like:

http {
geo $site_looks_down {
default 1;
127.0.0.3 0;
}
server {
if ($site_looks_down) {
rewrite ^/unav/ $uri last;
return 503;
}
error_page 503 /unav/index.html;
location ^~ /unav/ {
}
# extra location{}s and server-level config here
}
}


Now you can do things like

curl -i http://127.0.0.1/unav/img.png
curl -i http://127.0.0.3/unav/img.png

and you should see the same image response, while things like

curl -i http://127.0.0.1/sample/
curl -i http://127.0.0.3/sample/

should give you different responses -- one "503 unavailable", and one
correct (maybe 404, maybe useful content).


Change the "default" value to 0, or (better) just remove the if() block,
to make the site available to all again.

See documentation at things like http://nginx.org/r/geo for the syntax.

f
--
Francis Daly francis@daoine.org

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

Rewriting

artem May 23, 2013 04:14PM

Re: Rewriting

Bozhidara Marinchovska May 23, 2013 05:48PM

Re: Re[2]: Rewriting

B.R. May 24, 2013 01:00PM

Re: Rewriting

Francis Daly May 25, 2013 06:08AM

Re: Rewriting

Francis Daly May 26, 2013 05:24AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 105
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