Frp之后的群晖获取真实来访ip

群晖环境

  • 机型 DS3617xs
  • 版本 6.1.7
  • 开启 docker (镜像:nginx, stilleshan/frpc)
  • 开启 ssh

1. 修改群晖 nginx 配置

备份 DSM.mustache

1
cp /usr/syno/share/nginx/DSM.mustache{,.bak}

在第一个 server 块加入以下代码

1
2
set_real_ip_from 172.17.0.0/16;
real_ip_header X-Real-IP;

重启 nginx

1
nginx -s stop

2. 搭建 nginx 反代群晖

2.1 在 File Stationdocker 目录下新建 nginx 文件夹, 然后创建 default.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
server {
listen 443 ssl proxy_protocol;

real_ip_header proxy_protocol;
real_ip_recursive on;
set_real_ip_from 172.17.0.0/16;

ssl_certificate /etc/nginx/conf.d/cert;
ssl_certificate_key /etc/nginx/conf.d/key;

location / {
proxy_set_header X-Real-IP $proxy_protocol_addr;
proxy_set_header X-Forwarded-For $proxy_protocol_addr;
proxy_pass http://172.17.0.1:5000;
}
}

然后将 ssl 证书也导入 nginx 文件夹,并改名为 certkey

2.2 创建 nginx 容器

创建时选择 高级设置 > 存储空间 > 添加文件夹 ,选择 docker/nginx 文件夹,装载路径 设置为 /etc/nginx/conf.d ,然后 端口设置本地端口 设置为 50443容器端口 设置为 443类型 设置为 TCP ,然后正常创建即可

3. 创建 frpc 客户端

3.1 在 File Station 中 docker 目录下新建 frpc 文件夹, 然后创建 frpc.ini

1
2
3
4
5
6
7
8
9
[common]
// 你的 frp 服务器配置

[dsm]
type = tcp
local_port = 50443 // 上面创建的 nginx 的映射的本地端口
local_ip = 172.17.0.1
remote_port = 33333 // 看自己喜好选择端口即可
proxy_protocol_version = v2

3.2 创建 frpc 容器

创建时选择 高级设置 > 存储空间 > 添加文件,选择 docker/frpc/frpc.ini 文件,装载路径设置为 /frp/frpc.ini ,然后正常创建即可

4. 访问 https://你的frp服务器地址:33333 如能正常访问,应该就说明配置好了