This might be a very simple question but I don't know what to search to solve my problem. Please feel free to direct me to the right resource, that would also be very helpful.

This is my first time trying to deploy an app from Node.js to an actual server (I've only ever tested locally).

My app is built with NextJS. I've successfully built it on my server and then ran:

npm run start

The app seems to be running perfectly, however it's currently running on my domain on port :8080, which means that I can only access it from my domain like this example.com:8080.

I've tried forcing it to run on port 80 but that port is already in use.

I've tried making Apache listen to port 8080 following this guide, but then my app refuses to start because the port is also already in use.

How do I make my app appear on example.com? Is it something I have to do from my domain DNS settings?

Is it possible to also still run Apache on a different port?

1 Answer 1


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

       ProxyRequests Off
        ProxyPreserveHost On
        ProxyVia Full
        <Proxy *>
        Require all granted

       <Location />
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined


The important part here is this:

       <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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.