簡體   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