nginx : upstream with multiple server directives?

after so rumbling & testing, I figured a way to make it work and be able to ship one config file per application.

Here it is, dispatched in one common file and a pair of upstream/location files per application:

  • /etc/nginx/conf.d/common-proxies.conf:

    include /upstreams/*.conf;
    
    server {
    include /locations/*.conf
    }
    
  • /etc/nginx/locations/backend1.conf

    location /backend1/ {
      upstream http://backend1;
    }
    
  • /etc/nginx/locations/backend2.conf

    location /backend2/ {
      upstream http://backend2;
    }
    
  • /etc/nginx/upstreams/backend1.conf

    upstream backend1 {
      http://localhost:8989;
    }
    
  • /etc/nginx/upstreams/backend2.conf

    upstream backend2 {
      http://localhost:8990;
    }
    

Tags:

Nginx