It is necessary that a domain is available for any non-existent subdomain. I understand that you need to configure the DNS so that it sends all requests to the domain, and in the Apache settings, specify an alias for the type * domain. But I also don’t know how to do it correctly.

Tell me how to implement this.

    1 answer 1

    Your question is too general, therefore it is difficult to give an objective answer. I will indicate the general direction.

    The task is divided into two parts.

    First, you need to make sure that when you access the DNS on any subdomain some IP-address is issued (the default behavior - there is no record in the DNS - the answer will be "not found").

    This part of the question is very extensive ... Firstly, with a high degree of probability you do not keep the zone yourself (two geographically independent class C subnets, your own DNS servers, etc.), but your domain registrar leads. All of them, as a rule, combine several services: where they registered a domain, there is also a panel for adding / editing records to the DNS. And secondly, with a high degree of probability, your provider cannot make it so that a default IP is issued for non-existing records.

    What can be done?

    The first option is to raise the DNS server and configure it as you please. I don’t give details, as this is for you - choose the server type (On Windows or Linux), configure it. There will be specific questions - ask separately.

    The second option is to look for a provider who will provide you with such a service. I can only name a network solution among such providers. I do not know how relevant the example will be in a year / two / three - so this is also for you to look for yourself.

    The second part of the question relates to the configuration of the web server and is independent of the DNS configuration. Why independent? Because you can always enter a couple of non-existent subdomains in the hosts file and emulate a configured bind or whatever you will have as a DNS.

    So this is how it is solved if you have an apache-based server: when virtual hosts are configured, one of them will be the default host, and all traffic from unrecognized requests will go to it.

    Plus, you can explicitly prescribe, as in this question on en so .

    And for the server based on Nginx everything is done via * in servername:

    server_name mydomain.tld *.mydomain.tld; 

    Or through the default virtual host:

     listen 80 default_server; 

    (To process https you need to have a wildcard certificate, its price is usually an order of magnitude higher than the usual certificate - and letsencrypt still seems to not issue free wildcards)

    Something like that in general terms.

    Update. Addition to the answer to the clarifying question.

    I want my site to be available on all sub-domains of the 3rd level and the name of the sub-domain of the 3rd level went into the server variable, for example, the whole thing is started on the virtual Bitrix virtual machine so it’s not a problem to set everything up. I would like to know whether it is possible to implement it at all?

    Of course it is. In PHP, there is a global variable $ _SERVER and you can always find out the host name in the data set. It is transmitted by the web server, you can take HTTP_HOST and parse it, highlighting the name of the subdomain, if you need it.

    • "with a high degree of probability, your provider cannot make it so that a default IP is issued for non-existing records." - and can be an example of this? I worked with domains at three different registrars - everyone could - andreymal
    • Also, Let's Encrypt wildcard will be soon - andreymal
    • @andreymal On nic.ru turn on the DNS master and try to do it. On the masterhost try to do. This offhand. And I have been waiting for certificates from le for a long time. - AK ♦
    • Thanks for your reply. I want my site to be available on all sub-domains of the 3rd level and the name of the sub-domain of the 3rd level went into the server variable, for example, the whole thing is started on the virtual Bitrix virtual machine so it’s not a problem to set everything up. I would like to know whether it is possible to implement it at all? - Igor Branitsky
    • @ IgorBranitsky You know, I wonder why you didn’t write this clarification right away in your question, but already when you were given a general answer and now you need to actually ask a new question. You do not see how many questions per day are closed and minus for bad wording, for too general vague questions and how many people leave the site in negative to never return? - AK ♦