Multiple nginx applications

I am trying to route traffic between multiple upstream servers on nginx as follows:

upstream app_a { server unix:/tmp/app_a.sock fail_timeout=10; # For a TCP configuration: # server localhost:8000 fail_timeout=0; } server { #listen 80; ## listen for ipv4; this line is default and implied #listen [::]:80 default ipv6only=on; ## listen for ipv6 index index.html index.htm; server_name localhost; root /home/ubuntu/app_a/www/staging/static; location ~ ^/app_a/(.*)$ { try_files $1 @proxy_to_app_a; } location @proxy_to_app_a { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://app_a; } 

Unfortunately, applications do not know the full uri and expect to sit at the root, which means that I need to rewrite uri when passing to the application, so I thought this might work:

  location ~ ^/app_a/(.*)$ { try_files $1 @proxy_to_app_a; } 

the application works fine if the location is just / (due to the aforementioned root problem), but this regex-based solution doesn't work. What do I need to do so that the application receives / instead of app_a in the URL?

thanks

+4
source share
1 answer
 location /app_a/ { rewrite /app_a/(.*) /$1 break; proxy_set_header Host $http_host; proxy_pass http://app_a; } 
+4
source

All Articles