简体   繁体   中英

Deploy two different apps on different ports

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 admin@example.com
    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>

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM