Skip to main content

Configuring Apache for self-hosted applications

Configuring Apache for self-hosted applications

 

After installing Apache, there will be a default configuration file located in /etc/apache/enabled-sites/ that contains some VirtualHost configuration settings. It can be modified using Apache modules to allow Apache to serve our application as our root domain.

To do this, we will need to enable one of the following Apache mods using sudo a2enmod <module name>

sudo a2enmod proxy_http
sudo a2enmod mod_proxy

After one of these two modules install, set up your VirtualHost configuration within the /etc/apache/enabled-sites/ directory as follows:

<VirtualHost *:80>
    ServerAdmin me@mydomain.com
    ServerAlias mydomain.com
    ServerName www.mydomain.com
    ProxyPreserveHost On

    # setup the proxy
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>
    ProxyPass / http://www.mydomain.com:8888/
    ProxyPassReverse / http://www.mydomain.com:8888/
</VirtualHost>

To apply these settings, run sudo systemctl restart apache2.service to restart Apache and reload your new configuration. If this command returns an error, look closer at your config settings and be sure you enabled the necessary modules.