Grenny Bown
Grenny Bown

Reputation: 121

Setup reversed proxy on heroku to heroku app

I have a backend server running nodejs on heroku for example app1.herokuapp.com I have a balancer server running nginx on heroku for example balancer.herokuapp.com with such nginx config

upstream heroku {
    server app1.herokuapp.com;
    # server app2.herokuapp.com;
    # etc..
}

server {
    listen <%= ENV['PORT']%>;
    server_name _;
    keepalive_timeout 5;

    location / {
        proxy_pass http://heroku;
        proxy_set_header Host $host;
        proxy_redirect off;
    }
}

the problem is, when after deploying balancer app i'm trying to access my backed through proxy i'm getting such error from heroku

No such app (There's nothing here, yet.)

When i'm running backend server and balancer on localhost everything seems fine

Upvotes: 3

Views: 1337

Answers (2)

John Doe
John Doe

Reputation: 36

Heroku Round-Robin Load Balancing

server {
    listen 80 default_server;
    server_name _;
    location / {
        set_formatted_local_time $upstream "%S";
        if ($upstream ~ 00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15) {
            set $backend_url http://phpmyadmin-heroku.herokuapp.com;
            set $backend_host phpmyadmin-heroku.herokuapp.com;
        }
        if ($upstream ~ 16|17|18|19|20|21|22|23|24|25|26|27|28|29|30) {
            set $backend_url https://helloenvoy.herokuapp.com;
            set $backend_host helloenvoy.herokuapp.com;
        }
        if ($upstream ~ 31|32|33|34|35|36|37|38|39|40|41|42|43|44|45) {
            set $backend_url http://powr.herokuapp.com;
            set $backend_host powr.herokuapp.com;
        }
        if ($upstream ~ 46|47|48|49|50|51|52|53|54|55|56|57|58|59) {
            set $backend_url https://blog.heroku.com;
            set $backend_host blog.heroku.com;
        }
        proxy_pass $backend_url;
        proxy_set_header Host $backend_host;
    }
    location /this_is_ip_resolver_just_ignore_it_1 {
        proxy_pass http://phpmyadmin-heroku.herokuapp.com;
    }
    location /this_is_ip_resolver_just_ignore_it_2 {
        proxy_pass https://helloenvoy.herokuapp.com;
    }
    location /this_is_ip_resolver_just_ignore_it_3 {
        proxy_pass http://powr.herokuapp.com;
    }
    location /this_is_ip_resolver_just_ignore_it_4 {
        proxy_pass https://blog.heroku.com;
    }
}

Upvotes: 0

korefn
korefn

Reputation: 955

Essentially you k=just have to add the section below explicitly specifying the application domain

proxy_set_header Host my-other-app.herokuapp.com

Kindly follow the details here

Upvotes: 1

Related Questions