title: path based routing as a reverse proxy
body: <p>We were looking to use the AWS application load balancer (ALB) to direct incoming requests to specific servers where a &quot;tenant&quot; may reside. For example - customerA signs up to our free trial and we provision them a new instance of our application on webserver1 and we send them a link to their app, eg. <a href="https://trial.our.app/customerA" rel="nofollow noreferrer">https://trial.our.app/customerA</a></p>
  <p>What we need is for our automated deployment that we will design and develop to ensure that when that person hits the load balancer it directs them to the appropriate server. However, from what we understand the AWS ALB has a rule limit of 100 rules therefore if we hit 100 free trials we would have run out of rules :</p>
  <pre><code>if path is '/customerA/*' then forward to webserver1
  if path is '/customerB/*' then forward to webserver1 
  ...
  if path is '/customerX/*' then forward to webserver2 
  if path is '/customerY/*' then forward to webserver3 
  etc. 
  </code></pre>
  <p>Also, if the customer browses to the &quot;root&quot; <a href="https://trial.our.app" rel="nofollow noreferrer">https://trial.our.app</a> it redirects them to our website free trial page (different URL, eg. <a href="https://ourwebsite.io/freetrial" rel="nofollow noreferrer">https://ourwebsite.io/freetrial</a>)</p>
  <p>We're not looking to load balance, it will simply be a case of redirecting the customer to their appropriate webserver where they have been provisioned.</p>
  <p>We're considering NGINX (and are new to it!) and have spun it up to test this out and it mostly works, however we are unsure of a few things:</p>
  <ul>
  <li>what would a basic/sample configuration of this look like?  what he have so far on our test is as follows:</li>
  </ul>
  <pre><code>    server {
          listen       80;
          listen       [::]:80;
          server_name  _;
          root         /usr/share/nginx/html;
  
          # Load configuration files for the default server block.
          include /etc/nginx/default.d/*.conf;
  
          error_page 404 /404.html;
          location = /404.html {
          }
  
          error_page 500 502 503 504 /50x.html;
          location = /50x.html {
          }
  
      location = / {
            return 301 https://ourwebsite.io/freetrial;
          }
  
          location /customerA {
            proxy_pass http://10.101.1.149/;
          }
          location /customerB {
            proxy_pass http://10.101.2.34/;
          }
      }
  </code></pre>
  <ul>
  <li>how do we ensure the location path is case insensitive, processes and includes everything after the path , eg. <a href="https://trial.our.app/customerA/#/app" rel="nofollow noreferrer">https://trial.our.app/customerA/#/app</a></li>
  <li>how would you go about automating this so that the nginx config is updated when a new customer signs up and is added to the list of &quot;locations&quot; in the nginx.conf file?</li>
  <li>any other suggestions of how best to approach this? are we using the right approach?</li>
  </ul>