Welcome! Log In Create A New Profile

Advanced

Re: Rewriting

Francis Daly
May 25, 2013 06:08AM
On Fri, May 24, 2013 at 09:01:58AM +0300, wishmaster wrote:

Hi there,

You've got a few different things happening here, and I suspect that the
combination leads to you not getting the results you want.

> if ($remote_addr !~ '190\.212\.201\.[0-9]{0,3}') {
> rewrite ^/(.*)$ /unav/$1 break;
> }

So if I request "/file.php", this will rewrite to "/unav/file.php",
which probably doesn't exist, so I'm going to get a 404 unless you handle
it carefully.

> 2013/05/24 08:49:45 [error] 76017#0: *1910 open() "/usr/local/www/akbmaster/unav/unav/index.html" failed (2: No such file or directory), client: 190.212.201.198, server: akbmaster.server.com, request: "GET / HTTP/1.1", host: "akbmaster.server.com"
>
> I see twice rewriting.

The initial request was for "/". The explicit rewrite will make
that be "/unav/" (presuming that the rewrite applies here). In the
matching location{}, "/unav/" corresponds to a directory, not a file,
so there is an implicit rewrite to "/unav/index.html". This then
goes through the config again, and the explicit rewrite makes that
"/unav/unav/index.html". In the matching location{}, that does not
correspond to anything on the filesystem, hence 404.

> I have rewritten rule like this and this solved twice rewriting problem.
> rewrite ^/([^/]*)$ /unav/$1 break;

What happens with that if my initial request is for "/dir/file.php"?



Back you your original issue:

> > > I use opencart with nginx+php-fpm. Sometimes it is necessary to redirect all clients, except admin (190.212.201.0/24), to "Service unavailable" page which is simple index.html file with logo, background image and some text, located in /unav directory.

So if I ask for "/dir/file.php" during this time, what response do you want
me to get?

The contents of one file? A redirection to a separate url? Something else?

When you can answer that question, you'll have a better idea of the
configuration you need.


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

and that that can be done with "if" and "rewrite", possibly helped by
"map"; but the details depend on what exactly you want.

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: 138
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