0

I am trying to understand how to resolve DNS for websites names to named IP addresses. The websites are registered with reg123 but the sites are hosted on another server. Where do input these details on Nginx? Where in my Nginx config files do I imput the correct DNS that will link the website to the correct IP address ? I followed this turorital and it seems to indicate that your server is set up like this:

server {
        listen 80;
        listen [::]:80;

        root /var/www/example.com/html;
        index index.html index.htm index.nginx-debian.html;

        server_name example.com www.example.com;

        location / {
                try_files $uri $uri/ =404;
        }
}

However the IP address for my website is something like: 192.889.167.423

Dave M
  • 4,514
  • 22
  • 31
  • 30
theSeeker
  • 101
  • 1
  • You do not. The mapping from your domain name to an IP address is accomplished with a DNS server, which is often provided by the registrar that your domain is registered with. – Richard Smith Apr 26 '20 at 10:10
  • @RichardSmith. thanks for reply. I understand that part about the registrar linking the dormain to the IP adresses. but i am referring to my server. on my server i have several IP addresses each linked to a diffrent dormain name. where do i go to allow the server to know for example to listen on IP 192. 889.167.423 for example.com . and then listen on 192. 889.167.666 for exampleTwo.com – theSeeker Apr 26 '20 at 10:24
  • Nginx can filter connections by IP address using the `listen` directive. For example: `listen 192.168.0.1:80;` See [this document](http://nginx.org/en/docs/http/request_processing.html#mixed_name_ip_based_servers). – Richard Smith Apr 26 '20 at 10:34

1 Answers1

0

Simply answering to the HTTP requests, Nginx doesn't need to be aware of the DNS at all:

  1. The directive listen address[:port] binds the server{} to the given IP address and port. (While an address may also be a hostname, it's resolved to an IP address, because the hostname doesn't really exists on transport nor network layer.)
  2. The server_name, settings names of a virtual server, is used to pick the correct server{} among all the server{} blocks with a matching listen. It uses the HTTP Host header i.e. the browser delivers that information (regardless of the DNS).

With the HTTP Host (RFC 7230, 5.4) feature don't need to have separate IP addresses for all your domains, and the server name indication (SNI, RFC 6066, 3) enables the same for HTTPS.

With a listen *:80; server_name example.com; your Nginx will answer to requests for example.com on every IP address it has, but that won't really a) happen as the DNS is pointing to another IP address nor b) matter, as it doesn't make your server vulnerable to anything.

Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129