U
U
uralmas2018-11-08 17:13:47
Nginx
uralmas, 2018-11-08 17:13:47

How to set a rule for nginx to exclude all requests except for a few allowed paths?

Recently, bots have become more active, knocking on well-known vulnerabilities. I would like to close all requests (which may be misinterpreted by the engine), except for those that start with certain folders. For example, allowed:

  • /news/
  • /forum/
  • /shop/

And all the rest, which do not start with these folders, immediately received 404.
I want to place it after all the main locations, so that it does not interfere with the implementation of the main directions.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Softer, 2018-11-08
@uralmas

You can make 3 locations, and take the root to 404.
You can do 1 location ^/(news|forum|shop), and take the root to 404.
You can make a map with a regular request_uri and take away from the variable to 404.
I like the second option: )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question