Home > Linux Knowledge > How to setup a new site in Apache (Ubuntu)
published 2021-01-18, updated 2024-01-05
Here are the basic steps to create a new virtual host in Apache on Ubuntu Server. This includes HTTPS setup with LetsEncrypt certbot. apache2 and certbot (and dependencies) need to be installed first.
- create sitename.tld.conf in /etc/apache2/sites-available
- e.g. touch /etc/apache2/sites-available/bragger.xyz.conf
- basic config for sitename.tld.conf:
<VirtualHost *:80>
ServerAdmin webmaster@sitename.tld
ServerName sitename.tld
ServerAlias www.sitename.tld
DocumentRoot /var/www/sitename.tld
ErrorLog ${APACHE_LOG_DIR}/sitename.tld-error.log
CustomLog ${APACHE_LOG_DIR}/sitename.tld-access.log combined
</VirtualHost>
- Now put some static HTML content in DocumentRoot directory
- sudo a2enmod headers
- sudo a2ensite sitename.conf
- sudo systemctl reload apache2
- certbot --apache -d sitename www.sitename
- when certbot asks please enable rewrite from http 80 to https 443
- modify /etc/letsencrypt/options-ssl-apache.conf
- SSLProtocol -all +TLSv1.2
- test your ssl config via SSLLabs
- systemctl reload apache2
- TODO: Enable gzip compression
- TODO: harden Apache with mod_security
- TODO: https://ssl-config.mozilla.org/
It is possible to add multiple sites to the same Apache server in the same manner. Just point your DNS A-Records to the correct server ip adress and Apache will do the rest.