770 字
4 分钟
FRP配合Nginx实现域名访问Windows远程桌面的配置方案
根据您提供的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
apt updateapt install nginx -y # Debian/Ubuntu系统# 或yum install nginx -y # CentOS系统2. 创建Nginx配置文件
创建文件 /etc/nginx/conf.d/rdp.conf 并添加以下内容:
# 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模块配置:
# 在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免费证书:
apt install certbot python3-certbot-nginx -ycertbot --nginx -d xxxx.xx -d xxxx.xx5. 配置域名DNS解析
在域名管理面板中,为xxxx.xx和www.xxxx.com添加A记录,指向您的服务器IP(x.x.x.x)。
6. 测试并重启Nginx
nginx -t # 检查配置语法systemctl restart nginx # 重启Nginx服务7. 防火墙配置
确保服务器防火墙开放必要端口:
# UFW (Ubuntu)ufw allow 80/tcpufw allow 443/tcpufw allow 3389/tcpufw allow 7000/tcpufw allow 7001/tcpufw allow 7002/tcp
# Firewalld (CentOS)firewall-cmd --permanent --add-port=80/tcpfirewall-cmd --permanent --add-port=443/tcpfirewall-cmd --permanent --add-port=3389/tcpfirewall-cmd --permanent --add-port=7000-7002/tcpfirewall-cmd --reload远程桌面连接方式
方法一:直接使用RDP客户端
在远程桌面客户端中,可以直接使用域名连接:
- 地址:xxxx.xx
- 端口:3389(默认,可省略)
- 用户名、密码:Windows账户凭据
方法二:使用Web接口(如配置了Guacamole)
- 访问 https://xxxx.xx/rdp/
- 输入Windows的用户名和密码
- 通过Web浏览器访问远程桌面
安全建议
- 限制远程桌面访问IP:通过Nginx配置添加IP白名单
- 启用Windows网络级别身份验证
- 定期更新远程桌面服务补丁
- 配置失败登录尝试限制
- 使用复杂密码
- 考虑使用VPN作为额外安全层
这套配置实现了通过加密隧道将Windows远程桌面安全地暴露到互联网,并通过域名xxxx.xx提供访问,同时利用SSL加密保护数据传输安全。
FRP配合Nginx实现域名访问Windows远程桌面的配置方案
https://louaq.github.io/posts/frp/frp配合nginx实现域名访问windows远程桌面/ 最后更新于 2025-06-08,距今已过 189 天
部分内容可能已过时