Rewriting

Francis Daly francis at daoine.org
Sat May 25 10:07:15 UTC 2013


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 at daoine.org



More information about the nginx mailing list