Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

What the quickest and cleanest solution if you want to proxy URL request to two different backends via proxypass based on location.

 location /app1/ {
         alias /var/www/ruby/public;
         proxy_set_header  X-Real-IP  $remote_addr;
         proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header  Host $http_host;
         proxy_redirect    off;
         try_files $uri $uri/ @ruby;
       }

      location @ruby {
         proxy_pass http://127.0.0.1:3000;
      }

 location /app2/ {
         proxy_set_header  X-Real-IP  $remote_addr;
         proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header  Host $http_host;
         proxy_redirect    off;
         try_files $uri $uri/ @other;
       }

      location @other {
         proxy_pass http://127.0.0.1:8080;
      }

With this config nginx pass "/app1" or "/app2" to proxy and backend doesn't recognize the url/command ..

as for instance would like to pass to http://127.0.0.1:3000 only /messages when accessing http://<nginx>/app1/messages - but in configuration above also pass /app1/ as http://127.0.0.1:3000/app1/messages. Same goes for /app2

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.