E
E
Egor Peregudov2014-05-06 18:38:52
Nginx
Egor Peregudov, 2014-05-06 18:38:52

How to give a 404 error at a specific URL in nginx

The problem is the following, there is a URL (the address of a specific page of the site), when accessing which you need to give a 404 error, you need to do this at the nginx level.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vlad Zhivotnev, 2014-05-06
@Stalk-p

location =/someuri { 
return 404;
}

Everything after? - this is $args, you can't work with them through location, only through if.
That is, if you need to restrict access to the /someuri?page=1 page, you will have to do this:
location =/someuri { 
if ($arg_page = 1) { return 404; }
# или (если вообще искать цифру 1 во всей части ссылки после ? 
if ($arg ~* 1) {return 404; }
<здесь вставляем конфигурацию для обработки запроса к /someuri без page=1 или с другими аргументами, например строки про proxy_pass - скорее всего нужно скопировать из location />
}

If "block any requests with ?page=1" would do, then if ($arg_page = 1) { return 404; } can be inserted directly into location / { } (before the rest of the config).
location =/blah, respectively, must be set in order to match the condition to the exact uri, and not to /blahhereanytext

A
Andrey Burov, 2014-05-06
@BuriK666

location /404forever {
return 404;
}

E
Egor Peregudov, 2014-05-06
@Stalk-p

What if there are question marks in the URL? Tell me what to do. In his absence, everything works, with him - no.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question