nginxdynamic-ip

nginx configuration domain and ip


I'm have a problem with nginx: I want to create one server to ip address (its dynamic) and another to domain (I'm using Dynamic DNS).

How can I specify listen blocks, when ip is dynamic?

P.S. My config for domain name should stay as now:

server_name ~^(?P<sub>.+)\.top\.tld$ ~^(?P<sub>.+)\.top2\.tld$ top.tld top2.tld;

Solution

  • Found solution with default_server:

    server {
        listen      80 default_server;
        listen      [::]:80 default_server;
        listen      443 ssl http2 default_server;
        listen      [::]:443 ssl http2 default_server;
        ...
    }
    server {
        listen      80;
        listen      [::]:80;
        server_name ~^(?P<sub>.+)\.top\.tld$ ~^(?P<sub>.+)\.top2\.tld$ top.tld top2.tld;
        rewrite     ^ https://$host$request_uri? permanent;
    }
    server {
        listen      443 ssl http2;
        listen      [::]:443 ssl http2;
        server_name ~^(?P<sub>.+)\.top\.tld$ ~^(?P<sub>.+)\.top2\.tld$ top.tld top2.tld;
        ...
    }