在nginx.conf.erb中使用Heroku服务器URL进行负载平衡

我有2个服务器:

  • 服务器1是用于与Nginx的负载平衡 – https://server1.herokuapp.com/
  • 服务器2用于执行RESTful API。 – https://server2.herokuapp.com/

这里我在服务器1上configurationnginx.conf.erb : https : //gist.github.com/ntvinh11586/5b6fde3e804482aa400f3f7faca3d65f

当我尝试调用https://server1.herokuapp.com/而不是从https://server2.herokuapp.com/返回数据时,我达到了400 - Bad request 。 我不知道在我的nginx.conf.erb错误的地方,或者我需要在服务器2中实现nginx。

尝试研究一些资源,但我几乎发现这些教程configuration在本地主机而不是特定的主机,如heroku。

那么我应该怎样做才能成功?

你需要配置你的应用程序如下 –

 #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负载平衡。