Skip to main content

How to Create a Simple Website With node.js and host it with Apache

In the last two sections, we have learnt how to set up some bare bones websites using node.js and/or flask, and run the sites locally. In this section, we will look at how we can use Apache to set up a reverse proxy, so that whenever an outside connection is sent to the IP address of the VM, it redirects to the content of what is being served on the local port.

First, we have to enable a proxy connection on our VM. Run

sudo a2enmod proxy proxy_http

Then,

sudo systemctl restart apache2

Now, we should have everything set up to enable our proxy connection. We will continue to navigate to this folder:

cd /etc/apache2/sites-available

Then, we will edit the 000-default.conf file so that all traffic which comes in from port 80 is redirected to whatever is happening on port 3000. Run

sudo nano 000-default.conf

Add this line to the bottom of the file:

ProxyPass / http://localhost:3000/

Close and save the document.

If you now run

curl localhost:80

You will now see the same output as earlier. More importantly, if you now enter the IP-address for the VM in a browser on any PC with an internet connection, you should now see:

alt text

What we essentially have done here is the following: we have set up docusaurus on our VM to output a site at port 3000. All incoming traffic coming in via the port 80 to the VM is now redirected to what is happening on port 3000 on the VM (ie. port 80 is acting as a proxy for port 3000)