node.js - Nginx - 负载平衡在 Windows 上返回 404
问题描述
我已经从这里安装了 Nginx for Windows(64 位),因为官方二进制文件是 32 位的。目的是使用 Nginx 对 NodeJS 应用程序进行负载平衡。我按照此处的说明进行操作,其中还存在指向示例基本配置文件的链接。
以下配置文件在nginx
通过 Ubuntu PPA 安装的 Linux 上成功运行。服务器本身是通过pm2
.
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream top_servers {
# Use IP Hash for session persistence
ip_hash;
# Least connected algorithm
least_conn;
# List of Node.JS Application Servers
server 127.0.0.1:3001;
server 127.0.0.1:3002;
server 127.0.0.1:3003;
server 127.0.0.1:3004;
}
server {
listen 80;
server_name ip.address;
location /topserver/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://top_servers;
proxy_set_header X-Request-Id $request_id;
}
}
但是,此文件不适用于 Windows。我html
在 Windows 上安装 Nginx 的文件夹下收到“没有这样的文件或目录”的错误。我还没有为 Linux 做过任何这样的设置。
你能帮我把上面的配置文件转换成Windows吗?
注意我别无选择 - Windows 是这个项目的必需品。
解决方案
所以,我conf/nginx.conf
用上面显示的内容重写了 的内容。首先,我得到了一个错误"map" directive is not allowed here
。然后,在删除此指令后,我收到另一个错误,即"upstream" directive is not allowed here"
. 我认为,我使用的二进制文件不支持负载平衡。
推荐阅读
- html - 汉堡菜单导航(小问题)
- terraform - 通过 Terraform 运行“aws stepfunctions update-state-machine”时出现 Json 解析错误
- flutter - Flutter / FireStore : 获取刚刚在 Collection 中创建的文档的 ID
- python - 用字典替换熊猫数据框中的值
- android - Android 10 中的 Android 文件复制问题
- sql - 如何将小于、大于、等于 <、>、= 转换为 SQL Server
- docker - 基于另一个服务启动一个docker服务
- node.js - 快递:request.body 未定义
- javascript - “validation.ts:145 Uncaught Error”有什么解决办法吗?
- laravel - 如何创建 SELECT * FROM `TABLE` WHERE user_id = id; 在 Laravel 8