欢迎光临散文网 会员登陆 & 注册

云服务器自建frp并实现双向TLS验证

2021-08-29 17:45 作者:欢乐的小汪  | 我要投稿

首页你的得有台带公网ip的云服务器(废话)

以下是实战环境

frps0.37.1 ubuntu 18.04 OpenSSL 1.1.1l 

frpc0.37.1 ubuntu 20.04 OpenSSL 1.1.1f 

安装部署可直接看文档https://gofrp.org/docs/setup/

这里特别提醒下,ubuntu 18.04并不能直接使用压缩包中自带的.service

(被这卡了半小时)

这里贴出我用的.service

[Unit]

Description=Frpusxiaogoudog2233

After=network.target


[Service]

Type=simple

User=root

Restart=on-failure

RestartSec=5s

ExecStart=/root/frp/frpc -c /root/frp/frp.xiaogoumc.xyz.ini

ExecReload=/root/frp/frpc reload -c /root/frp/frp.xiaogoumc.xyz.ini

LimitNOFILE=1048576


[Install]

WantedBy=multi-user.target

ExecStart和ExecReload不要忘了改成自己的路径


然后TLS证书了

可以参照

https://gofrp.org/docs/features/common/network/network-tls/#openssl-%E7%94%9F%E6%88%90%E8%AF%81%E4%B9%A6%E7%A4%BA%E4%BE%8B

建议在frps同目录下生成

特别说明:

生成 frps 证书:


openssl genrsa -out server.key 2048


openssl req -new -sha256 -key server.key \

    -subj "/C=XX/ST=DEFAULT/L=DEFAULT/O=DEFAULT/CN=server.com" \

    -reqexts SAN \

    -config <(cat my-openssl.cnf <(printf "\n[SAN]\nsubjectAltName=DNS:localhost,IP:127.0.0.1,DNS:example.server.com")) \

    -out server.csr


openssl x509 -req -days 365 \

-in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial \

-extfile <(printf "subjectAltName=DNS:localhost,IP:127.0.0.1,DNS:example.server.com") \

-out server.crt

其中这两段要修改

-config <(cat my-openssl.cnf <(printf "\n[SAN]\nsubjectAltName=DNS:localhost,IP:127.0.0.1,DNS:example.server.com")) \

-extfile <(printf "subjectAltName=DNS:localhost,IP:127.0.0.1,DNS:example.server.com") \

IP一定要改成frps的ip,有域名可以把example.server.com改成自己的域名

frps.ini示例

[common]

bind_port = 7000

kcp_bind_port = 7000

vhost_https_port = 443

vhost_http_port = 80

authentication_method = token

token = 密

log_file = /var/log/frps/frps.log

tls_cert_file = /root/frp/server.crt

tls_key_file = /root/frp/server.key

tls_trusted_ca_file = /root/frp/ca.crt

max_pool_count = 10

custom_404_page = /root/frp/404.html

当 tls_trusted_ca_file 内容是有效的话,那么默认就会开启 tls_only = true

frpc使用自签的TLS要注意下

需要将生成的ca.crt放入受信任的根证书颁发机构(windows)

sudo cp ca.crt  /usr/local/share/ca-certificates && sudo update-ca-certificates

(ubuntu/linux)

不然,建立不了连接

如果有frp的配置等问题可以来私聊

云服务器自建frp并实现双向TLS验证的评论 (共 条)

分享到微博请遵守国家法律