A
A
Alexey Kot2017-05-12 18:04:22
Nginx
Alexey Kot, 2017-05-12 18:04:22

How to block access to url in nginx?

Hey!
There is a server on nginx and a site on Wordpress.
There was a task - to give access to a certain URL (not a directory, but to a certain page) only from a certain IP, and to prohibit the rest.
Tried such constructions in the config file

if ($request_uri ~ ^/specific-page) {
allow 1.1.1.1;
deny all;
}

But such a block does not work, since the deny, allow methods are prohibited in them. It didn’t work through location either, since I don’t have a directory, but just a URL.
What is the best way to do it in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
egor_nullptr, 2017-05-12
@egor_nullptr

location = /path/to/page.html {
    allow 1.1.1.1;
    deny all;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question