If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

Ubuntu subdomains

Started by rickde, Feb 04, 2023, 03:42 AM

Previous topic - Next topic

rickdeTopic starter

There is a server with ubuntu 14.04 VPS. It has everything it needs, including apache2, php7, etc. Additionally, there is also a domain attached to it. The website runs smoothly, and it processes html and php files flawlessly. Even the subfolders are working without any issues. The domain is registered in the virtual hosts /etc/apache/sites-enabled/mydomain.net (also available in sites-available). All the files are present in the folder /var/www/sites/mydomain.net/httpd.

However, when attempting to create a subdomain by adding lines like /etc/apache/sites-enabled/mydomain.net (or httpd.conf) to the file, it overloads Apache and generates an error message: "NameVirtualHost *:80 has no VirtualHosts." Subsequently, nothing works, and even commenting out the above mentioned line in ports.conf does not resolve the issue.

Copying the file /etc/apache/sites-available/mydomain.net and renaming it as sub.mydomain.net results in the creation of three default files in sites-available: mydomain.net, sub.mydomain.net. Changing all the paths to the folder sub.mydomain.net/httpd, activating the site with the a2ensite command, and restarting Apache doesn't cause any warnings. However, it still doesn't create a subdomain.

What should be done in this case? While searching through forums and topics, they sometimes mention issues related to the DNS servers, claiming that there might be no records. I'm not sure how to verify whether there are any records or not as I don't have the DNS server installed on my server. Could these glitches be due to that?
  •  


Kickera

To resolve the issue, one suggestion is to comment out the line "NameVirtualHost *:80" not in ports.conf, but in /etc/apache/sites-enabled/mydomain.net.
  •  

messnct

Another suggestion is to ensure that subdomains are registered in /etc/hosts. This step should not be overlooked.
  •  

Pyrotech

Since your main domain is working perfectly, it's clear that Apache is configured correctly for that. However, let's focus on the steps you need to take to set up that subdomain properly.

First, let's ensure that the DNS records for your subdomain are set properly. To check if the DNS records are present, you can use a tool like `dig` or `nslookup`. This can be done from your terminal or any online DNS checker. You want to look for an A record that points `sub.mydomain.net` to the IP address of your VPS.

For example, you can run the following command in a terminal:

dig sub.mydomain.net

If you see something like "no answer" or it does not return the correct IP address, you will need to log into the control panel where your domain is registered and add an A record for `sub.mydomain.net`. It should point to the same IP as your main domain.

Now, assuming that the DNS is set up correctly, let's go back to Apache. Ensure that your virtual host configuration for the subdomain in `/etc/apache/sites-available/sub.mydomain.net` looks something like this:

<VirtualHost *:80>
    ServerName sub.mydomain.net
    DocumentRoot /var/www/sites/sub.mydomain.net/httpd

    <Directory /var/www/sites/sub.mydomain.net/httpd>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/sub.mydomain.net-error.log
    CustomLog ${APACHE_LOG_DIR}/sub.mydomain.net-access.log combined
</VirtualHost>


After you've configured this, you need to enable the subdomain with:

sudo a2ensite sub.mydomain.net

And then restart Apache:

sudo systemctl restart apache2

If everything is configured correctly but the subdomain still isn't resolveing, you might need to check the Apache error logs found in `/var/log/apache2/error.log` to see if there are any specific issues reported there.

Sometimes, issues also comes from conflicting configurations in `/etc/apache/ports.conf`. If you have explicitly defined `NameVirtualHost *:80`, verify that it's necessary. In newer versions of Apache, this directive is not needed, and having it without the corresponding virtual host can lead to confusion.

Lastly, if you are still running into problems, double check if there's a misconfiguration in your DNS or Apache settings. It sometimes takes time for DNS changes to propagate too, so have some patience if you've just made changes.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...