I ended up messing around a lot with this and have a solution. I am unsure if it's a good solution, but it's a solution nonetheless.
The problem
The biggest problem here is that I need to run both a NodeJS app AND Wordpress at the same time. Wordpress needs to be accessible on a public address so that my app can access it.
As of yet I have not found a way to run Wordpress on a different port. I do not know if it is possible. Apache can be run on different ports, but that seems to be a global setting that would affect all sites running on the server.
My solution
My solution is pretty simple. I created yet another Apache virtual host situated in a subdomain api.example.com
and moved my Wordpress installation to it.
This way I don't have to worry about my app displaying on port :80
over my Wordpress installation.
I then ran my app on my base domain example.com
on port :8080
and modified my Apache Virtual Host by editing etc/apache2/sites-available/example.com.conf
with this code:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
DocumentRoot /var/www/example.com/public_html
<Directory />
Options -Indexes +FollowSymlinks
AllowOverride None
Require all granted
</Directory>
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
<Location />
ProxyPass http://127.0.0.1:8080/
ProxyPassReverse http://127.0.0.1:8080/
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The important part here is this:
<Location / >
ProxyPass http://127.0.0.1:8080/
ProxyPassReverse http://127.0.0.1:8080/
</Location>
What it does is take whatever is on port :8080
and instead display it on port :80
which we set at the start <VirtualHost *:80>
and at the root of the domain <Location / >
.
This could be written as <Location /app >
if you wanted to display your app at example.com/app
.
Bear in mind I am not an expert with Apache and I just put this answer together from about 10 or so sites that contained only part of what I needed. The explanation of how this works could be wrong, this is just my understanding of it. Feel free to correct me if it is wrong.