You may have just one website and that is ok. If that is your case you can avoid this entire chapter. But some of you may also have several websites. And quite probably you want to use one single public ip to resolve all the domains you have.
The Apache documentation is the main resource to go and find out the solution for your particular problem. In here we will setup two websites both resolving on the same ip. Some of you, the very newbies may be asking yourselves what on Earth means resolving. So get the very basics first and then we move on to the configuration.
We, the humans, understand letters much better than we do numbers. We don’t refer to a spoon to name it by using a chunk of numbers. Instead we use words which are combination of letters.
Computers on the other hand understand numbers. Basically two numbers. One and zero. And they combine them to form complicated structures and sort out “clever things” we ask them.
DNS. This is the acronym for Domain Name Server. These servers do resolve one of the questions we humans ask to computers all the time, specially when surfing the internet. These servers understand us when we type www.google.com and look for the ip address where google is. This is called name resolution.
Now if you have one website anyone looking for myfancysite.com will be directed to the server it is sitting at thanks to the DNS servers. They are spread around the world and for obvious reasons the ISP’s also have their own in order to make the internet fast and provide good levels of service. If you happen two sites the same should happen but remember you may only have one ip addres in your only working server. What can you do to use one single ip and resolve two domain names? Use a “trick” and that “trick” is called virtual hosts.
If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.
Use this link to get $200 credit at DigitalOcean and support Adminbyaccident.com costs.
Get $100 credit for free at Vultr using this link and support Adminbyaccident.com costs.
Mind Vultr supports FreeBSD on their VPS offer.
Let’s say you have two websites. One more relevant than the other. You will place the configuration for that website as all the tutorials on the internet explain. For the second website you will use the virtual hosts configuration. Alternatively you can configure two different virtual hosts, one per site.
First you will have to edit the httpd.conf file in /usr/local/etc/apache24 directory and uncomment the virtual hosts directive:
Now you have enabled that path to work. The path in FreeBSD is /usr/local/etc/apache24/extra/httpd-vhosts.conf. You will see a configuration example in the same directory, so you can always maintain a good reference in there. This is what you will find in the regular file so you can edit it straight away.
So once we have enabled the virtual hosts directive it is time to configure our third or fourth site. Mind one very important thing. www.myfancysite.com has to have its own host. And myfancysite.com also has to have it. And if you enable ssl certificates so you can administer the site using encrypted communication you also have to add the applicable virtual host. You will have to add the following lines to have https enabled.
Mind you haven’t issued or set any SSL/TLS certificate yet. So Apache will complain. So at this moment this https thing is not sufficiently configured. To enable https for your sites you have to edit the httpd.conf file. In FreeBSD this is done by doing the following:
Edit your httpd.conf file.
sudo vi /usr/local/etc/apache24/httpd.conf
Uncomment the following module:
# Load Module ssl_module modules/mod_ssl.so
It should look now as:
Load Module ssl_module modules/mod_ssl.so
Now we have enabled SSL capability to our Apache web server. To test the configuration we have set is right type the following:
sudo apachectl configtest
If any errors it will complain and tell us what’s wrong.
If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.
Use this link to get $200 credit at DigitalOcean and support Adminbyaccident.com costs.
Get $100 credit for free at Vultr using this link and support Adminbyaccident.com costs.
Mind Vultr supports FreeBSD on their VPS offer.