[英]Use Heroku server url at nginx.conf.erb for load balancing
I have 2 server: 我有2个服务器:
Here my configuration of nginx.conf.erb
at Server 1: https://gist.github.com/ntvinh11586/5b6fde3e804482aa400f3f7faca3d65f 这是我在服务器1上对
nginx.conf.erb
配置: https : //gist.github.com/ntvinh11586/5b6fde3e804482aa400f3f7faca3d65f
When I try call https://server1.herokuapp.com/
, instead of return data from https://server2.herokuapp.com/ , I reach a 400 - Bad request
. 当我尝试致电
https://server1.herokuapp.com/
,而不是从https://server2.herokuapp.com/返回数据,我遇到了400 - Bad request
。 I don't know somewhere in my nginx.conf.erb
wrong or I need implement nginx in server 2. 我不知道我的
nginx.conf.erb
某个地方有错误,或者我需要在服务器2中实现nginx。
Try to research some resources but I found almost these tutorials configuring in localhost instead of specific hosts like heroku. 尝试研究一些资源,但是我发现几乎这些教程都是在localhost中配置的,而不是像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>;
}
My two cents. 我的两分钱。
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.
使用单个服务器server1.herokuapp.com,使其与上述实现一起使用,然后可以添加server2.hreokuapp.com以实现负载平衡。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.