使用nginx.conf.erb上的Heroku服务器URL进行负载平衡 [英] Use Heroku server url at nginx.conf.erb for load balancing

查看:127
本文介绍了使用nginx.conf.erb上的Heroku服务器URL进行负载平衡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个服务器:

  • Server 1 is for loading balance with Nginx - https://server1.herokuapp.com/
  • Server 2 is for acting RESTful APIs. - https://server2.herokuapp.com/

这是我在服务器1上配置的nginx.conf.erb: https://gist.github.com/ntvinh11586/5b6fde3e804482aa400f3f7faca3d65f

Here my configuration of nginx.conf.erb at Server 1: https://gist.github.com/ntvinh11586/5b6fde3e804482aa400f3f7faca3d65f

当我尝试致电https://server1.herokuapp.com/时,而不是从 https://server2.herokuapp.com/<返回数据/a>,我到达400 - Bad request.我不知道我的nginx.conf.erb某处有问题,还是我需要在服务器2中实现nginx.

When I try call https://server1.herokuapp.com/, instead of return data from https://server2.herokuapp.com/, I reach a 400 - Bad request. I don't know somewhere in my nginx.conf.erb wrong or I need implement nginx in server 2.

尝试研究一些资源,但我发现这些教程几乎都是在localhost中配置的,而不是像heroku这样的特定主机配置的.

Try to research some resources but I found almost these tutorials configuring in localhost instead of specific hosts like heroku.

那我该怎么做才能使我的工作成功?

So what should I do to make my work successfully?

推荐答案

您需要按以下步骤配置您的应用-

You need to configure your app as follows -

#upstream nodebeats {
#       server server2.herokuapp.com;
#   }

 server {
    listen       <%= ENV['PORT'] %>;
    server_name  herokuapp.com;
    root    "/app/";
    large_client_header_buffers 4 32k;

    location / {
        proxy_redirect off;
        proxy_set_header   X-Real-IP            $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Host                   $http_host;
        proxy_set_header   X-NginX-Proxy    true;
        proxy_set_header   Connection "";
        proxy_http_version 1.1;
         proxy_pass http://localhost:<node-app-port>;
    }

我的两分钱.

注释掉上游.使用单个服务器server1.herokuapp.com,使其与上述实现一起使用,然后可以添加server2.hreokuapp.com来实现负载平衡.

Comment out the upstream. Work with a single server server1.herokuapp.com, get it working with the above implementation, and then you can accomplish on adding the server2.hreokuapp.com to load balance.

这篇关于使用nginx.conf.erb上的Heroku服务器URL进行负载平衡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆