Reverse Proxy serve different folder NGINX

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

I want to expose those APIs just like they are serving from a single source. nginx config file /etc/nginx/site-available

server {
 
    listen              443 ssl;
    server_name         app.yourapp.com;
    ssl_certificate     /etc/nginx/ssl/app.yourapp.com.crt;
    ssl_certificate_key /etc/nginx/ssl/app.yourapp.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:8090;
            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: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;
 }
}

If you add multiple application at same host. we have configured NGINX reverse Proxy for two apps using location block, v1 is listening at 8090 and / is listening at 8080.

You can access the app : https:://app. yourapp.com and https:://app.yourapp.com/v1

If you are new to nginx server so you can check this link to use nginx.

No comments:

Post a Comment

Download the eBook of react js for beginners

ReactJS basically is an open-source JavaScript library which is used for building user interfaces specifically for single page applications...

Popular