Search code examples
nginxservernginx-locationnginx-reverse-proxywinginx

NGINX resolving a non configured domain, why?


I have one server running on: http://localhost:8080

I'm configuring a sample NGINX server.

I copied from internet the following configuration:

# user  nobody;
worker_processes  1;

error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile            on;
    keepalive_timeout   65;
    # gzip              on;

    server
    {
        listen 80;
        server_name mydomain01.com www.mydomain01.com;

        location /
        {
            proxy_pass http://localhost:8080;
            include "../proxy_params.conf";
        }
    }

}

On the hosts file I have just the following entries:

127.0.0.1 mydomain01.com
127.0.0.1 www.mydomain01.com;
127.0.0.1 mydomain02.com
127.0.0.1 www.mydomain02.com;

When I go to: http://mydomain01.com I get the same content as on: http://localhost:8080

My question is:

Why when I go to: http://mydomain02.com I also get the same content as on: http://localhost:8080?

I think I should not get that content because this last domain is not on the NGINX configuration.

Do I have an error on the configuration above?

Thanks!


Solution

  • nginx always contains a default server which will handle requests for server names that do not match a server_name directive. If you do not define a default_server, nginx will use the first server block with a matching location. See this document for details.