How to restrict acces to specific friendly URL by IP in Wordpress site?

Francis Daly francis at daoine.org
Mon May 22 23:09:11 UTC 2017


On Fri, May 19, 2017 at 03:24:43AM -0400, ohmykot wrote:

Hi there,

in nginx, one request is handled in one location, and only the config in
(or inherited into) that location applies.

> On the web-site, I have a wordpress page, i.e. domain.com/secret-page/, that
> I want to restrict access to everybody but 1 specific IP address of my other
> server.

> location ~* ^/secret-page/ { 
> allow 1.1.1.1; 
> deny all; 
> }

If the request is for /secret-page/ and is handled in that location{},
you have no explicit how-to-handle-it configuration, so the default
"serve it from the filesystem" will be used.

Assuming that you want the to be handled just like every other request,
you could add

  try_files $uri $uri/ /index.php?q=$uri&$args;

in the location{}, and it will do what you asked for.

Note: this will restrict a request f or /secret-page/, but not a request
for /index.php?q=/secret-page/

The second one there is possibly functionally equivalent to the first;
if you want to restrict that as well, it would be more work in nginx.


As an aside, it may be clearer to use

  location ^~ /secret-page/

instead of

  location ~* ^/secret-page/

The meanings are not identical, depending on what else is in the config
file and where it is.

http://nginx.org/r/location for the details on what the various squiggles
mean.

Good luck with it,

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list