B
B
Berik Kazhikumarov2019-02-19 14:03:08
Nginx
Berik Kazhikumarov, 2019-02-19 14:03:08

How to whitelist URLs in nginx config?

Hello. the essence of the question is that you need to register a certain check whether there is such a URL and if it is not there, then issue 404.
a piece of the config file is what I tried to do:

server
{
    listen localhost:80;
    server_name example.com;
    charset utf-8;
     location  / {
           root /var/www/html/;
           try_files $uri $uri/ /index.html;   \\редирект всех запросов на index.html
            index index.html;
                 location ~* !^(\/|css|balance|deposit|signup|profilelogin|settings|static|fonts|img|index\.html|favicon\.ico)/
              {
               return 404;
               break;
            }
      }
}

I also tried to do it through if instead of the second location
, the problem is that only one of the conditions is fulfilled. ((if the URL check works, then if the page is refreshed it gives 404. If the try_files rule works, then the URL check does not work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Berik Kazhikumarov, 2019-02-20
@Kazhikumarov

decided like this. suddenly someone will be useful. thanks to the kind person from stackoverflow

location / {
    return 404;
}
location ~ ^/(signup|market|support|profie|login|settings|index\.html|static|fonts|img|$) {
    try_files $uri $uri/ /index.html;
}
location = /{
try_files $uri $uri/ /index.html;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question