Set up Apache¶
1. Install Apache + mod_wsgi¶
Command:
sudo apt-get update sudo apt install apache2 libapache2-mod-wsgi-py3
2. Install SSL Certificates¶
Obtain SSL certificates to enable HTTPS from a Certificate Authority(CA) like Let’s Encrypt. See SSL Certificates of how to get SSL certificates from Let’s Encrypt.
See NO-IP Client of how to setup of a Linux dynamic update client to automatically updates the hostname to the correct IP address for the SSL certificates.
3. Enable SSL and WSGI¶
Apache needs the SSL and WSGI module enabled:
sudo a2enmod ssl sudo a2enmod wsgi
4. Enable proxy modules¶
Enable necessary Apache proxy modules:
sudo a2enmod proxy proxy_http
5. Service for Apache Server¶
The service
apache2for the Apache Server has been automatically created in the directory/lib/systemd/system.
6. Configure Apache¶
Main configuration in
/etc/apache2/apache2.conf:sudo nano /etc/apache2/apache2.conf
7. Configure Apache Ports¶
Main configuration in
/etc/apache2/apache2.conf:sudo nano /etc/apache2/apache2.conf
8. Configure Virtual Hosts¶
Create separate configuration files for each virtual host in the directory
/etc/apache2/sites-available/.For example for
dingx.gotdns.ch:sudo nano /etc/apache2/sites-available/dingx.gotdns.ch.confContent:
<VirtualHost *:443> ServerName dingx.gotdns.ch ServerAlias dingx.gotdns.ch DocumentRoot /var/www/html SSLEngine on SSLCertificateFile /etc/letsencrypt/live/dingx.gotdns.ch/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/dingx.gotdns.ch/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/dingx.gotdns.ch/chain.pem <Directory /var/www/html> Options FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
9. Enable virtual host¶
Enable the virtual host using the
a2ensitecommand:sudo a2ensite dingx.gotdns.ch.confA symbolic link will be created in
/etc/apache2/sites-enabledto enable the virtual host.
10. Disable virtual host¶
Disable the virtual host configuration file using the a2dissite command:
sudo a2dissite dingx.gotdns.chThe symbolic link in
/etc/apache2/sites-enabledwill be deleted.
11. Test the Apache configuration¶
sudo apache2ctl -t
12. Restart Apache¶
Restart Apache after making any changes to Apache’s configuration for the changes to take effect:
sudo systemctl daemon-reload sudo systemctl restart apache2