Host multiple frontend React/Angular app on one NGINX server – Nicolas BAPTISTA

Host multiple frontend React/Angular app on one NGINX server

Is it possible that you have multiple web applications React.JS or Angular and you want it to be on one unique machine

You will have to check your NGINX configuration file /etc/nginx/nginx.conf or /etc/nginx/conf.d/ssl.conf – on CentOS/Fedora/RedHat.

ON THE SAME DOMAIN

One app will run on domain.com and the other app will run on domain.com/app2 :

server {
    listen 443 http2 ssl;
    listen [::]:443 http2 ssl;

    server_name DOMAIN.COM;
    #ssl_certificate /etc/letsencrypt/live/DOMAIN.COM/fullchain.pem; # managed by Certbot
    #ssl_certificate_key /etc/letsencrypt/live/DOMAIN.COM/privkey.pem; # managed by Certbot
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    
    # FIRST WEB APP - runs on https://DOMAIN.COM
    root /usr/share/nginx/firstapp/build;
    index index.html index.htm;
    try_files $uri $uri/ /index.html;

    # SECOND WEB APP - runs on https://DOMAIN.COM/app2
    location /app2 {
      autoindex on;
      index index.html;

      alias /usr/share/nginx/app2/build/;

      try_files $uri $uri/ /index.html;
    }
}

ON DIFFENTS DOMAINS

One app will run on app1.domain.com and the other app will run on app2.domain.com :

server {
    listen 443 http2 ssl;
    listen [::]:443 http2 ssl;

    server_name app1.domain.com;
    #ssl_certificate /etc/letsencrypt/live/app1.domain.com/fullchain.pem; # managed by Certbot
    #ssl_certificate_key /etc/letsencrypt/live/app1.domain.com/privkey.pem; # managed by Certbot
    ssl_dhparam /etc/ssl/certs/dhparam.pem;

    root /usr/share/nginx/app1/build;
    index index.html index.htm;
    try_files $uri $uri/ /index.html;
}
server {
    listen 443 http2 ssl;
    listen [::]:443 http2 ssl;

    server_name app2.domain.com;
    ssl_certificate /etc/letsencrypt/live/app2.domain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/app2.domain.com/privkey.pem; # managed by Certbot
    ssl_dhparam /etc/ssl/certs/dhparam.pem;

    root /usr/share/nginx/app2/build;
    index index.html index.htm;
    try_files $uri $uri/ /index.html;
}

403 Forbidden / 404 Not authorized

In case of error, you will have to check your logs:

sudo tail -n 20 /var/log/nginx/error.log