.. apache: Set up Apache ============= 1. Install Apache + mod_wsgi ---------------------------- Command: .. code:: 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 :ref:`chapter_ssl_certificates` of how to get SSL certificates from Let's Encrypt. See :ref:`chapter_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: .. code:: sudo a2enmod ssl sudo a2enmod wsgi | 4. Enable proxy modules ----------------------- Enable necessary Apache proxy modules: .. code:: sudo a2enmod proxy proxy_http | 5. Service for Apache Server ---------------------------- The service ``apache2`` for the Apache Server has been automatically created in the directory ``/lib/systemd/system``. | 6. Configure Apache ------------------- Main configuration in ``/etc/apache2/apache2.conf``: .. code:: sudo nano /etc/apache2/apache2.conf | 7. Configure Apache Ports ------------------------- Main configuration in ``/etc/apache2/apache2.conf``: .. code:: 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``: .. code:: sudo nano /etc/apache2/sites-available/dingx.gotdns.ch.conf Content: .. code:: 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 Options FollowSymLinks AllowOverride All Require all granted | 9. Enable virtual host ---------------------- Enable the virtual host using the ``a2ensite`` command: .. code:: sudo a2ensite dingx.gotdns.ch.conf A symbolic link will be created in ``/etc/apache2/sites-enabled`` to enable the virtual host. | 10. Disable virtual host ------------------------ Disable the virtual host configuration file using the a2dissite command: .. code:: sudo a2dissite dingx.gotdns.ch The symbolic link in ``/etc/apache2/sites-enabled`` will be deleted. | 11. Test the Apache configuration --------------------------------- .. code:: sudo apache2ctl -t | 12. Restart Apache ------------------ Restart Apache after making any changes to Apache's configuration for the changes to take effect: .. code:: sudo systemctl daemon-reload sudo systemctl restart apache2