0

I have several applications located at:

http://www.foo.com:80
http://www.bar.com:42
http://www.baz.com:1337

that I am attempting to reverse proxy with one nginx machine. the issue I have right now is that these applications are requesting files that are identical in name, but not identical in content:

location /bootstrap.css {
 proxy_pass http://www.foo.com:80/bootstrap.css;
}

location /bootstrap.css {
 proxy_pass http://www.bar.com:42/bootstrap.css;
}

location /baz {
 proxy_pass http://www.baz.com:1337;
}

location /foo {
 proxy_pass http://www.foo.com:80/;
}

is it possible for me to re-write all responses coming from a particular application server to point to it's application subfolder?

ex: redirect

http://www.foo.com:80/* 

to

/foo
Carl Sagan
  • 982
  • 1
  • 13
  • 34

1 Answers1

0

You can setup something like:

location /foo {
    proxy_pass http://www.foo.com:80;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

However, your application foo might need to know about this. See this post for example.

EDIT:

Nginx might be able to do what you want by using sub_filter from ngx_http_sub_module

Try the example in: answer 1 and answer 2

Community
  • 1
  • 1
JrBenito
  • 973
  • 8
  • 30
  • The issue is that the html emitted by www.foo.com has absolute references to say -- /bootstrap.css, rather than /foo/bootstrap.css How do I get the response from www.foo.com to be /foo/bootstrap.css or to get the request for /bootstrap.css to forward to /foo/bootstrap.css – Carl Sagan May 10 '16 at 00:33
  • I don´t know if nginx can do this alone. I believe this is application´s foo responsibility. Look the [post](http://www.htpcguides.com/configure-sickrage-reverse-proxy-nginx/) and see that author´s explicit tells to configure application (Sickrage in this example) to be aware it will be called from inside a directory (/sickrage in the example). Are your application self contained or served by an Apache server or other http server? I don´t know if it is possible to rewrite responses in Apache or any other http server. – JrBenito May 10 '16 at 12:35
  • Actually it is possible as shown in the EDIT section above. I hope it helps you. – JrBenito May 10 '16 at 12:41