X
X
XenK2016-11-28 20:40:46
Nginx
XenK, 2016-11-28 20:40:46

Close access by IP nginx?

There was a need to make the site inaccessible from an external IP ( http://12.34.56.78).
That is, available only to the domain name.
What is the best way to implement this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dimonchik, 2016-11-28
@XenK

server {
listen 80 default_server;
server_name_;
return 444;
}
instead of 444, you can use some kind of "bandwich limit"
PS options with listing domains (like colleagues in the answers) will backfire when adding subdomains and not only

E
Erelecano Oioraen, 2016-11-28
@Erelecano

if ($host !~* ^(domain.tld|www.domain.tld|abc.domain.tld)$ ) {
                return 444;
        }

In the config for your domain, it will send everyone who came for something other than the names indicated in brackets to the frog grandmother. What is the entry by IP, what is the resolution of your IP officer into something else.
I have such a design provided with a config for each domain. Thus, I cut off all unnecessary calls.

M
mureevms, 2016-11-28
@mureevms

Make a redirect from IP to domain, something like this:

server {
        listen 12.34.56.78:80;
        server_name example.com www.example.com;
location / {
        rewrite ^(.*)$ http://example.com$1 break;
        }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question