skip to Main Content

The question is quite simple. How two deploy two different Nodejs apps on ubuntu 20 remote server. App1 should accessed throw http://ip-address:8080 and Second App should be deployed on http://ip-address:8081. This two app always are accessible from localhost. My web server is apache and this two port are disabled in firewall.

So ufw status return below result

Status: active

To                         Action      From
--                         ------      ----
8080                       ALLOW       Anywhere
8081                       ALLOW       Anywhere
80                         ALLOW       Anywhere
8080 (v6)                  ALLOW       Anywhere (v6)
8081 (v6)                  ALLOW       Anywhere (v6)
80 (v6)                    ALLOW       Anywhere (v6)

and my apache2 configured to reverse proxy like below:

<VirtualHost *:80>

    ProxyPreserveHost On

    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/

    ProxyPass / http://127.0.0.1:8081/
    ProxyPassReverse / http://127.0.0.1:8081/

    ServerAdmin [email protected]
    DocumentRoot /var/www/html
    <Directory /var/www/html>
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

2

Answers


  1. You are confusing Apache by giving the direct path for both the cases. how will apache know which request should be redirected to which port ?

    Answer:

    ProxyPass /app1 http://127.0.0.1:8080/
    ProxyPassReverse /app1 http://127.0.0.1:8080/
    
    ProxyPass /app2 http://127.0.0.1:8081/
    ProxyPassReverse /app2 http://127.0.0.1:8081/
    

    I hopefully believe this should resolve your issue if other configurations are in place. any further errors should be investigated accordingly

    Login or Signup to reply.
  2. You can use:

    ProxyPass /app1 http://localhost:8080/app1
    ProxyPassReverse /app1 http://localhost:8080/app1

    ProxyPass /app2 http://localhost:8081/app2
    ProxyPassReverse /app2 http://localhost:8081/app2

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search