53

I have a server at mysite.no-ip.org. Everything is working fine and I have a blog and owncloud that I access writing mysite.no-ip.org/blog and mysite.no-ip.org/owncloud. Now, I want to create subdomains so that I can write blog.mysite.no-ip.org and owncloud.mysite.no-ip.org.

I have looked a lot into it and the simplest tutorial was this one which I followed. http://www.bcat.eu/blog/local-subdomains-under-ubuntu-linux-and-apache-2-4-tutorial/ Except that I am not on my server but ssh into it remotely so if I use localhost I cannot see if this works I believe. This is my first obstacle, can I follow this tutorial without being present next to the server?

I also just discovered CNAME records which (I am not completely sure) seem necessary to what I want to do. I use no-ip.org and I have tried to follow something like this but this is not really clear either https://support.uberflip.com/entries/235780-4-4-5-how-to-setup-a-cname-redirect#noip

Does anyone have any pointers? This is quite shady to me and I have no idea if I am far from the solution or really close (at least if I could try localhost that would be a first step in order to check my Apache conf but I can't even do it since I ssh).

Anyways, thanks for your help in advance. Any help, link is welcomed.

Eric Leschinski
  • 2,221
  • 1
  • 20
  • 24
user1983400
  • 633
  • 1
  • 6
  • 4
  • You can find the solution at https://stackoverflow.com/questions/43470374/set-ssl-for-my-virtual-host/77502430#77502430 – Jaime Montoya Nov 17 '23 at 17:37

3 Answers3

74

This is actually really easy.

First make sure your DNS is working. You can use a A, AAAA or CNAME record as long as it points to your IP address.

Please check if it's working before you continue! This will save you much trouble. You can check using ping subdomain.mydomain.com or nslookup subdomain.mydomain.com. If it's pointing to your IP address you're good.

Note that DNS changes may take up to 24 hours. If you want to continue now, you can edit your hosts file to manually add the sub domain. Note that this will only work for your current PC so you should check your DNS again 24 hours later to make sure it's working elsewhere as well (don't forget to revert your changes to your hosts file before you check).

To do this:

sudo nano /etc/hosts

add line like (replacing the IP and hostname of course):

34.54.235.64 subdomain.mydomain.com

and save the file.

Now update your Apache2 configuration.

Just adding this VirtualHost will do:

<VirtualHost *:80>
    ServerName subdomain.mydomain.com
    DocumentRoot /var/www/subdomain.mydomain.com
</VirtualHost>

Now create /var/www/subdomain.mydomain.com and restart Apache2:

mkdir -p /var/www/subdomain.mydomain.com
sudo service apache2 restart

enable the site:

sudo a2ensite subdomain.mydomain.com

Repeat this for every sub domain you want to add.

Louis Matthijssen
  • 11,885
  • 6
  • 44
  • 50
  • 2
    Great this works! Thank you very much. Last point, but it might be because of no-ip, I managed to make it work but using the address blog-mysite.no-ip.org when I registered the subdomain. I couldnt write blog.mysite.no-ip.org (message:invalid hostname)...now, is this because no-ip wants me to pay or did I do something wrong? – user1983400 May 09 '14 at 22:28
  • I don't know if no-ip allows you to create sub domains. If they do, it may take 24 hours before it's working as I said in my answer. Try to reach it again tomorrow. Also, I see you're using blog-mysite first and then blog.mysite. This is not the same, so if you chose the first you'll have to use that one. Don't forget to update your Apache2 config in that case. – Louis Matthijssen May 09 '14 at 22:34
  • Hey, yes sorry that is what I meant. No-ip would only let me create a subdomain with a dash and not a period. Is this no-ip restricting my free account with them? There shouldnt be reason you couldnt otherwise, should it? – user1983400 May 09 '14 at 22:41
  • I think so. I don't use no-ip. If you really want to know you should contact their support. You could also buy your own domain (like mydomain.com). This way you'll have full control of your DNS and you can add as many subdomains you want. It's not so expensive, just make sure you don't order hosting with it (this makes it expensive). Prices are usually per year and I think you can get a domain for around 10$/year. – Louis Matthijssen May 09 '14 at 22:46
  • I rolled back the last edit, as changing ownership to the apache user on the document root directory is not needed, and can even be a security risk. It is enough to give read access to the directory. – Dan Mar 01 '17 at 13:29
  • @user1983400 consider service slike heroku or appengine as an alternative to no-ip – Felipe Valdes Oct 17 '19 at 13:15
  • Thank you for the ping tip, that made it clear that the sub1.mysite.com was not even resolved to my server's IP – medmek Apr 04 '21 at 16:06
0

In my case, all I was missing was to add A record in my Godaddy domain DNS settings.

Remember I had to also add the VirtualHost and a2ensite as well.


cp /etc/apache2/site-available/000-default.conf /etc/apache2/site-avaiable/subdomain.mydomain.com

<VirtualHost *:80> ServerName subdomain.mydomain.com DocumentRoot /var/www/subdomain.mydomain.com </VirtualHost>

a2ensite

sudo a2ensite subdomain.mydomain.com

restart apache sudo systremctl reload apache2

0

In my case, all I was missing was to add A record in my Godaddy domain DNS settings.

insert A record for subdomain

Remember I had to also add the VirtualHost and a2ensite as well.


   /etc/apache2/sites-available
cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/subdomain.mydomain.com

<VirtualHost *:80> ServerName subdomain.mydomain.com DocumentRoot /var/www/subdomain.mydomain.com </VirtualHost>

a2ensite

sudo a2ensite subdomain.mydomain.com

restart apache sudo systremctl reload apache2