首页 > 解决方案 > 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 是这个项目的必需品。

标签: node.jswindowsnginxload-balancing

解决方案


所以,我conf/nginx.conf用上面显示的内容重写了 的内容。首先,我得到了一个错误"map" directive is not allowed here。然后,在删除此指令后,我收到另一个错误,即"upstream" directive is not allowed here". 我认为,我使用的二进制文件不支持负载平衡。


推荐阅读