繁体   English   中英

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

[英]Use Heroku server url at nginx.conf.erb for load balancing

我有2个服务器:

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

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

尝试研究一些资源,但是我发现几乎这些教程都是在localhost中配置的,而不是像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以实现负载平衡。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM