0

I have the next setup:

Main server main.com and additional standalone server (additional.com), which should be served via proxy from the subpage url keeping relative paths, etc. main.com/additional

However, trying to setup proxy_pass with location block I can't achieve relative pathes and also static content does not load.

Here is some code:

server {
  listen       80;
  server_name  main.com;

  resolver %RESOLVERS%;
  set $url "main.com$request_uri";
  set $url_additional "https://additional.com";

  if ($http_x_forwarded_proto = 'http') {
    return 301 https://main.com$request_uri;
  }

   location /additional {

         proxy_pass $url_additional;
     }

  location / {
     rewrite ^/$ /$lang;
     proxy_pass $url;
    }
  }

It tries to load static and index from additional.com/additional, and not additional.com

I have tried with root and alias and some other parameters, but nothing helps :(

What am I missing?

Dima Arbuzin
  • 3
  • 1
  • 4
  • The first `proxy_pass` statement contains no scheme (is it supposed to be `$url_additional`? The second `proxy_pass` contains a variable set at the top of the file, so the `rewrite` will have no effect that I can see. The use of `set` is dubious at best and serves to make your configuration look very strange and unpredictable. – Richard Smith May 22 '17 at 12:10
  • @RichardSmith yep, you are right: the first one is `$url_additional`. The use of set is because the website is hosted on AWS and this is done in case amazon will change IP addresses. – Dima Arbuzin May 22 '17 at 14:21

1 Answers1

0

I've got it working in this way:

location ~* ^/additional/(.*)$ {
    proxy_pass http://additional.com/$1$is_args$args;
}
  • 1
    Worked perfectly! Could you pls elaborate on your answer. I guess params did the trick. Also how I can make it work with **main.com/additional**. now it works only with **main.com/additional/** – Dima Arbuzin May 22 '17 at 13:09
  • also I changed **additional.com$request_uri** to just **additional.com** in order to make it work. – Dima Arbuzin May 22 '17 at 13:22
  • **$1** - will match string in (.*) from location tag. Then **$is_args** checks if arguments are passed in url, and if they are then adds **?** character. Also if arguments exists they will be placed in uri by **$args**. – Andrey Prokhorov May 22 '17 at 14:28
  • As for the ending bracket - I have it working with or without it. – Andrey Prokhorov May 22 '17 at 14:29
  • Fixed it using ` location /additional {return 302 /additional/ }` before another location. – Dima Arbuzin May 22 '17 at 15:03