Correct place to include ProxyPass and ProxyPassReverse (Bitnami Node.js server on AWS Lightsail)

I've set up a Bitnami Node.js server on AWS Lightsail. I then ran the Bitnami HTTPS Configuration Tool:

sudo /opt/bitnami/bncert-tool

This created several Apache config files, and I'm trying to figure out how and where to set up the proxy to my app running on port 3000. I've identified five different files where I could potentially include the proxies:

/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf 
/opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf
/opt/bitnami/apache2/conf/bitnami/bitnami.conf  
/opt/bitnami/apps/letsencrypt/conf/httpd-app.conf
/opt/bitnami/apps/letsencrypt/conf/httpd-prefix.conf

For the time being, I've included my proxy lines in the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf file. The entire contents of the file look like this:

# Bitnami applications installed in a prefix URL
Include "/opt/bitnami/apps/letsencrypt/conf/httpd-prefix.conf"
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/

That seems to work, but tbh, I have no idea what I'm doing. Is that configuration correct? Any suggestions / guidance would be much appreciated.

Answers 1

  • Bitnami Engineer here. To create a custom Node.js application from scratch, follow the steps below. These steps assume that your application will live in the /opt/bitnami/apps/myapp/* directory:

    • Run the following commands to create the directories:

        $ sudo mkdir -p /opt/bitnami/apps/myapp
        $ sudo mkdir /opt/bitnami/apps/myapp/conf
        $ sudo mkdir /opt/bitnami/apps/myapp/htdocs
      
    • Create a new Node.js project with Express:

        $ cd /opt/bitnami/apps/myapp/htdocs
        $ sudo express --view pug
        $ sudo npm install
      
    • Start the Express server:

        $ cd /opt/bitnami/apps/myapp/htdocs
        $ DEBUG=sample:* ./bin/www
      

      Alternatively, use the following command to start the server and keep it running even after your server session ends. Replace FILE with the correct filename for your application.

        $ forever start FILE.js
      

      NOTE: Although your application is now available, you may not be able to access it immediately. This is because the Express server runs on port 3000 by default, and Bitnami stacks on some platforms have this port closed for security reasons. To access the application, you will need to create an SSH tunnel to the port.

    • Create and edit the /opt/bitnami/apps/myapp/conf/httpd-prefix.conf file and add the line below to it:

        Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
      
    • Create and edit the /opt/bitnami/apps/myapp/conf/httpd-app.conf file and add the content below to it. This is the main configuration file for your application, so modify it further depending on your application's requirements.

        ProxyPass / http://127.0.0.1:3000/
        ProxyPassReverse / http://127.0.0.1:3000/
      

      NOTE: 3000 is the default port for the Express server. If you have customized your application to use a different port, change it here as well.

    • Once you have created the files and directories above, add the following line to the end of the main Apache configuration file at /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf, as shown below:

        Include "/opt/bitnami/apps/myapp/conf/httpd-prefix.conf"
      
    • Restart the Apache server:

        $ sudo /opt/bitnami/ctlscript.sh restart apache
      

    You can find more information here: https://docs.bitnami.com/installer/infrastructure/nodejs/administration/create-custom-application-nodejs/


Related Articles