个人技术分享

在 Nginx 中,stream 上下文必须在 http 上下文之外,并且只能位于顶级配置文件中或包含在主配置文件中的单独文件中。

Nginx 的配置文件通常包含一个 http 块,用于处理 HTTP 和 HTTPS 请求,但是 stream 块是独立的,并且不能嵌套在 http 块中。

要解决这个问题,你可以采取以下步骤:

1.确保你的 stream 块配置在一个单独的文件中,例如 /etc/nginx/rdp-stream.conf。

2.确保 rdp-stream.conf 文件中的 stream 块是文件的唯一内容,或者它是文件中的第一个上下文(在 http 上下文之前)。

3.在 /etc/nginx/nginx.conf 文件中,不要包含 rdp-stream.conf 文件在 http 块内,而是直接在 http 块之外包含它。这通常通过 include 指令在 events 块之后和 http 块之前完成。

示例 nginx.conf 文件:

user  nginx;  
worker_processes  auto;  
  
error_log  /var/log/nginx/error.log notice;  
pid        /var/run/nginx.pid;  
  
events {  
    worker_connections  1024;  
}  
  
include /etc/nginx/rdp-stream.conf;  # 包含 stream 配置  
  
http {  
    # ... HTTP 配置 ...  
}

示例 rdp-stream.conf 文件:

stream {  
    upstream backend {  
        server 192.168.1.100:3389;  
    }  
  
    server {  
        listen 12345;  
        proxy_pass backend;  
    }  
}

确保你已经将 rdp-stream.conf 文件放在 /etc/nginx/ 目录下,并且已经按照上述方式在 nginx.conf 中包含了它。

之后,重新测试配置并重启 Nginx 服务:

sudo nginx -t  
sudo systemctl reload nginx

如果一切正常,你应该能够使用配置的端口 12345 连接到你的 RDP 代理了。
在这里插入图片描述