FRP配合Nginx实现域名访问Windows远程桌面的配置方案
发表于:2025-06-08 | 分类: frp
字数统计: 829 | 阅读时长: 3分钟 | 阅读量:

根据您提供的frps.toml和frpc.toml配置,我将详细说明如何通过Nginx反向代理,实现使用域名xx.xx访问Windows远程桌面的完整配置流程。

现有FRP配置分析

您提供的FRP配置显示:

  • FRP服务端(frps)运行在公网服务器(x.x.x.x)的7000端口
  • HTTP服务设置在7002端口
  • FRP管理面板在7500端口
  • 远程桌面连接被映射到服务端的7001端口
  • 客户端本地RDP服务在3389端口
  • 已启用数据加密和压缩传输

Nginx配置步骤

1. 在公网服务器上安装Nginx

1
2
3
4
apt update
apt install nginx -y # Debian/Ubuntu系统
# 或
yum install nginx -y # CentOS系统

2. 创建Nginx配置文件

创建文件 /etc/nginx/conf.d/rdp.conf 并添加以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# HTTP重定向到HTTPS配置
server {
listen 80;
server_name xxxx.com www.xxxx.com;

# 将HTTP请求重定向到HTTPS
return 301 https://$host$request_uri;
}

# RDP Guacamole Web访问配置(如果使用)
server {
listen 443 ssl;
server_name xxxx.com www.xxxx.com;

# SSL证书配置
ssl_certificate /etc/nginx/ssl/xxxx.crt;
ssl_certificate_key /etc/nginx/ssl/xxxx.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;

# RDP Web访问(如使用Apache Guacamole等工具)
location /rdp/ {
proxy_pass http://localhost:8080/guacamole/;
proxy_buffering off;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_cookie_path /guacamole/ /rdp/;
access_log off;
}

# FRP管理面板访问
location /frp/ {
proxy_pass http://localhost:7500/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
}
}

3. 配置TCP流量转发

编辑Nginx主配置文件 /etc/nginx/nginx.conf,在http部分外添加stream模块配置:

1
2
3
4
5
6
7
8
9
10
# 在http {...}之外添加
stream {
# RDP流量转发
server {
listen 3389; # 标准RDP端口
proxy_pass 127.0.0.1:7001; # 转发到FRP映射的端口
proxy_connect_timeout 10s;
proxy_timeout 30s; # RDP连接通常需要更长时间
}
}

4. 申请并配置SSL证书

可以使用Let’s Encrypt免费证书:

1
2
apt install certbot python3-certbot-nginx -y
certbot --nginx -d xxxx.xx -d xxxx.xx

5. 配置域名DNS解析

在域名管理面板中,为xxxx.xx和www.xxxx.com添加A记录,指向您的服务器IP(x.x.x.x)。

6. 测试并重启Nginx

1
2
nginx -t  # 检查配置语法
systemctl restart nginx # 重启Nginx服务

7. 防火墙配置

确保服务器防火墙开放必要端口:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# UFW (Ubuntu)
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 3389/tcp
ufw allow 7000/tcp
ufw allow 7001/tcp
ufw allow 7002/tcp

# Firewalld (CentOS)
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --permanent --add-port=3389/tcp
firewall-cmd --permanent --add-port=7000-7002/tcp
firewall-cmd --reload

远程桌面连接方式

方法一:直接使用RDP客户端

在远程桌面客户端中,可以直接使用域名连接:

  • 地址:xxxx.xx
  • 端口:3389(默认,可省略)
  • 用户名、密码:Windows账户凭据

方法二:使用Web接口(如配置了Guacamole)

  1. 访问 https://xxxx.xx/rdp/
  2. 输入Windows的用户名和密码
  3. 通过Web浏览器访问远程桌面

安全建议

  1. 限制远程桌面访问IP:通过Nginx配置添加IP白名单
  2. 启用Windows网络级别身份验证
  3. 定期更新远程桌面服务补丁
  4. 配置失败登录尝试限制
  5. 使用复杂密码
  6. 考虑使用VPN作为额外安全层

这套配置实现了通过加密隧道将Windows远程桌面安全地暴露到互联网,并通过域名xxxx.xx提供访问,同时利用SSL加密保护数据传输安全。

上一篇:
使用Fail2ban保护服务器免受可疑IP攻击
下一篇:
Rethinking U-Net Task-Adaptive Mixture of Skip Connections for Enhanced Medical Image Segmentation