【问题标题】:Setup reversed proxy on heroku to heroku app在heroku到heroku应用程序上设置反向代理
【发布时间】:2018-12-28 03:51:17
【问题描述】:

我有一个在 heroku 上运行 nodejs 的后端服务器,例如 app1.herokuapp.com 我有一个在 heroku 上运行 nginx 的平衡器服务器,例如 balancer.herokuapp.com 具有这样的 nginx 配置

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;
    }
}

问题是,在部署平衡器应用程序后,我试图通过代理访问我的支持,我从 heroku 收到这样的错误

没有这样的应用程序(这里什么都没有。)

当我在本地主机上运行后端服务器和平衡器时,一切似乎都很好

【问题讨论】:

  • 有什么解决办法吗?

标签: nginx heroku proxy load-balancing reverse-proxy


【解决方案1】:

Heroku 循环负载平衡

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;
    }
}

【讨论】:

    【解决方案2】:

    基本上你 k=只需要添加下面明确指定应用程序域的部分

    proxy_set_header Host my-other-app.herokuapp.com
    

    请关注详情here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-06
      • 1970-01-01
      • 2021-07-24
      • 1970-01-01
      • 1970-01-01
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多