Nginx负载均衡器配置

时间:2019-04-26 05:53:23

标签: nginx selinux

我的要求是对两个单独的节点(10.110.6.29, 10.110.6.45)中运行的两个ESB Web服务进行负载平衡,我正在使用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>

1 个答案:

答案 0 :(得分:0)

经过一番互联网阅读,我能够使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)。我不是系统管理员,因此我不知道这些配置。