nginx - 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>
解决方案
经过一些互联网阅读后,我能够使 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)。我不是系统管理员,因此我不知道这些配置。
推荐阅读
- python - 如何从 python 脚本在 azure devops 管道中生成合理的错误消息
- javascript - 如何在点击 Javascript 时在 index.html 中加载另一个 html
- swift - 使用 MKLocalSearch/MapKit 查找附近的餐馆?
- node.js - 在从 typescript 编译的代码中导入 PrismaClient 时出错 [SyntaxError: Named export 'PrismaClient' not found]
- python - cv2 python 颜色无法正常工作(绘图)
- firebase - 如何访问firestore文档中的集合并将其作为列表分配给模型中的飞镖列表?
- python - 使用 Psycopg2 从 PostgreSQL 数据库获取行的正确方法是什么?
- java - 从内部联接插入信息
- typescript - 将类型转换为类型元组的实用程序类型
- itext - itext7:定位签名的矩形