首页 > 解决方案 > Nginx 负载均衡器配置

问题描述

我的要求是负载平衡在两个单独的节点中运行的两个 ESB Web 服务,(10.110.6.29, 10.110.6.45)我使用的是 nginx 并安装在 10.110.6.45 中。基本上,当我向它发送请求时10.110.6.45 (port 80),应该对两个节点进行同样的负载平衡。

下面是/etc/nginx/nginx.conf。

user  www;
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;    

    sendfile        on;

    keepalive_timeout  65;

    upstream esbhnbwso2.hnb.lk{
    server 10.110.6.45:8280;
    server 10.110.6.29:8280;
    }

    server {
        listen       80;
        server_name  localhost;


        location / {
            proxy_pass http://esbhnbwso2.hnb.lk;
            proxy_http_version 1.1;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

}

当我尝试调用该服务时http://10.110.6.45/hnbceftapi,我得到了下面的 nginx 页面。我究竟做错了什么?任何帮助将不胜感激。

<html>
   <head>
      <meta content="HTML Tidy for Java (vers. 27 Sep 2004), see www.w3.org" name="generator"/>
      <title>404 Not Found</title>
   </head>
   <body bgcolor="white">
      <center>
         <h1>404 Not Found</h1>
      </center>
      <hr/>
      <center>nginx/1.14.2</center>
   </body>
</html>

标签: nginxload-balancing

解决方案


经过一些互联网阅读后,我能够使 nginx 工作。这些是我的发现,想分享这些。

我必须使用以下命令启用 linux 内部防火墙。

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent  --zone=public --add-service=https

这些命令基本上会创建一个公共区域并允许 http(80)、https(443) 流量。

可以通过运行以下命令来验证允许的端口。

firewall-cmd --list-ports

必须运行以下命令以允许 httpd - http 守护进程(nginx 运行的 Apache Web 服务器)进行 http 通信。

setsebool -P httpd_can_network_connect 1

这些配置是必需的,因为我正在处理的发行版是安全增强型 Linux (SELinux)。我不是系统管理员,因此我不知道这些配置。


推荐阅读