2

I would like to use Nginx upstreams to balance two instances of an application, one of them is on an EC2 server and the other on Heroku.

The problem is, when I put the app.herokuapp.com in the upstream directive, it resolves to the ip address, and the requests are sent to the ip address, but heroku uses the host to identify the application, so it doesn't work.

I'm stuck on this, what could I do?


Update: My app uses host too, so I think I am stuck on this. As I can't change Heroku, I guess I will have to add a header with the original request Host to be used by my application and keep the Host as default, so Heroku will find my application

bwagner
  • 1,029
  • 1
  • 11
  • 13

1 Answers1

3

Add Host header to proxy.

proxy_pass http://upstream;
proxy_set_header Host $host;
....
Alexey Ten
  • 13,794
  • 6
  • 44
  • 54
  • 1
    My application uses the host to identify the shop and heroku uses the host to identify the app, It didn't work for me, because if I set the Host to the original request host, heroku won't find my app. – bwagner Apr 17 '14 at 14:14
  • @bwgpro, put anything you want instead of `$host`. – Alexey Ten Apr 17 '14 at 14:18
  • If I change the proxy Host, heroku won't find my app, as it expects the host to be app.herokuapp.com – bwagner Apr 17 '14 at 14:19
  • In this case you have to modify one of upstreams to match the other. – Alexey Ten Apr 17 '14 at 14:41