I understand there's a name resolution. For instance, I have a DNS A record I think and it redirects everything that goes to bi.example.com to www.example.com, which is the hostname of the server.

But then I have a nginx config like this:

server {
  listen ;

  server_name bi.example.com;

  client_max_body_size 64M;

      location / {
        proxy_pass http://externalservice.com;
        proxy_set_header Host externalservice.com;
        proxy_set_header Referer https://www.externalservice.com;

        proxy_set_header User-Agent $http_user_agent;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Accept-Encoding "";
        proxy_set_header Accept-Language $http_accept_language;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        sub_filter externalservice.com bi.example.com;
        sub_filter_once off;

Why does the server name has to be bi.example.com? The DNS redirects to www.example.com, which is the real hostname of the server, but then I need to write a virtual server_name bi.example.com in this case, in order for the redirection to externalservice to work. Is there a second Domain Name Resolution inside the server itself and how does that work exactly? Because it's kinda confusing. The IP is fake btw as well as the urls.

1 Answer 1


Webservers use name base multiplexing. On any given single IP address they allow to host multiple websites. The server is listening (at the TCP/IP level) on one IP address, and then receives an HTTP frame. This frame contains an HTTP header called host that the client uses to signal which website it wants to visit (on that specific IP address that was found earlier by the client when doing a name resolution).

The configuration allows to apply different settings per websites, and hence you can have different blocks with different hostnames.

  • Thanks, so it's not a second DNS, but just some redirection? Also, host contains the hostname, correct? Does the http frame contain an IP address, because I see some VirtualHost settings inside my Apache configs and it seems I have multiple internal IPs that are being serviced inside my server, how does that work?
    – Sayaman
    Dec 30, 2021 at 1:40
  • No redirection. The HTTP message contains an host header giving the hostname. There are no IP addresses therE (except if the URL was using an IP address itself instead of an hostname) Dec 30, 2021 at 3:36
  • Thanks. Hmm, but then what are the IPs in the VirtualHost inside the Apache configs for? httpd.apache.org/docs/2.4/vhosts/ip-based.html
    – Sayaman
    Dec 30, 2021 at 3:57
  • HTTP is based off TCP/IP. A webserver needs to know on which IP addresses it should listen, as a given host can have multiple ones. The link you gave, as written in its address ,is about IP based virtualhosting. The point explained above is about name based virtualhosting where multiple website (so different names) all use the same IP address (a given one, or some small number, far lower than the number of distinct hostnames). Dec 30, 2021 at 5:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.