Admin... by accident!

You may have chosen to be an admin. I didn't!

  • Home
  • FreeBSD
  • GNU/Linux
  • Security
  • Network
  • Virtualization
  • Politics
  • Github
  • Donate
  • Me

How to configure a Virtual Host in Apache

April 26, 2017 by Albert Valbuena

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.

 

Filed Under: How To's, How To's

Recent Posts

  • How to install Redis for WordPress on FreeBSD
  • How to compile cloudflared in FreeBSD 13/14
  • How to configure FreeBSD to use a webcam (version 12 and 13)
  • Symbolic and Hard Links in UNIX and Linux
  • How to import iocage jails to Bastille on FreeBSD 13
  • How to load and unload kernel modules in Linux
  • How to use find in GNU/Linux and FreeBSD
  • How to install Mate on FreeBSD 12/13
  • How to install Nessus 10 on FreeBSD 12
  • How to enable TLS traffic from the origin server on Cloudflare Argo Tunnel
  • How to use Cloudflare’s Argo Tunnel service to publish a website on FreeBSD 12/13
  • How to setup MariaDB master-slave replication on FreeBSD
  • How to upload a FreeBSD custom image on DigitalOcean
  • How to install Drupal 9 on FreeBSD 13.0
  • How to manage site visitors based on IP Geolocation
  • How to enable Geolocation in AWStats on FreeBSD 13.0
  • How to install AWStats on FreeBSD 13.0
  • How to configure Modsecurity 3 for WordPress on FreeBSD
  • How to configure Apache HTTP with a TLS reverse proxy backend on FreeBSD
  • How to detect a WAF – Web Application Firewall

Archives

  • November 2024
  • October 2024
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • January 2023
  • December 2022
  • April 2022
  • March 2022
  • October 2021
  • September 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • September 2018
  • June 2018
  • May 2018
  • April 2018
  • February 2018
  • January 2018
  • November 2017
  • April 2017

RSS Admin… by accident!

  • How to install Redis for WordPress on FreeBSD
  • How to compile cloudflared in FreeBSD 13/14
  • How to configure FreeBSD to use a webcam (version 12 and 13)
  • Symbolic and Hard Links in UNIX and Linux
  • How to import iocage jails to Bastille on FreeBSD 13
  • How to load and unload kernel modules in Linux
  • How to use find in GNU/Linux and FreeBSD
  • How to install Mate on FreeBSD 12/13
  • How to install Nessus 10 on FreeBSD 12
  • How to enable TLS traffic from the origin server on Cloudflare Argo Tunnel

Copyright © 2025 · Magazine Pro Theme on Genesis Framework · WordPress · Log in