A
A
Alexander Kalinin2021-12-16 16:56:28
Nginx
Alexander Kalinin, 2021-12-16 16:56:28

How to deny access to the site if the visitor accesses the machine's direct IP?

how to disable access to the site by direct ip like http://1.1.1.1 in nginx?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2021-12-16
@tchlgru

NGINX will eventually answer yes. You can make a separate config that will catch "all other" ( default_server) requests, incl. by direct IP:

server {
    listen       80  default_server;
    server_name  _;
    return       444;
}
Here _, the underscore is not something magical, just a non-existent domain name.
Read more: nginx.org/en/docs/http/server_names.html#miscellan...

V
Vasily Bannikov, 2021-12-16
@vabka

Like this:

server {
  listen 80;
  server_name example.com;
  ...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question