Skip to content

NGINX reverse Proxy – Serve from different folder

Last updated on June 4, 2022

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

0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments