Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

NGINX reverse Proxy – Serve from different folder

In this post, I will show you how we can configure NGINX to serve applications form the different directories. I have two node application both are running at different ports, 8000 and 8080.
I want to expose those APIs just like they are serving from a single source.

Here is my NGINX config file content, generally it will be available at /etc/nginx/site-available.

server {

    listen              443 ssl;
    server_name         app.arjun.com;
    ssl_certificate     /etc/nginx/ssl/app.arjun.com.crt;
    ssl_certificate_key /etc/nginx/ssl/app.arjun.com.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

    location /v1/ {
            proxy_pass http://localhost:8080;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    }

    location / {
        proxy_pass http://localhost:8008;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
	}
}

If you want to add another application at same host just create a new block. here we have configured NGINX reverse Proxy for two apps using location block, v1 is listening at 8080 and / is listening at 8000.

Now you can access applications at https:://app.arjunphp.com and http://app.arjunphp/v1

Leave a Reply