云服務(wù)器自建frp并實(shí)現(xiàn)雙向TLS驗(yàn)證
首頁你的得有臺(tái)帶公網(wǎng)ip的云服務(wù)器(廢話)
以下是實(shí)戰(zhàn)環(huán)境
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
(被這卡了半小時(shí))
這里貼出我用的.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
當(dāng) tls_trusted_ca_file 內(nèi)容是有效的話,那么默認(rèn)就會(huì)開啟 tls_only = true
frpc使用自簽的TLS要注意下
需要將生成的ca.crt放入受信任的根證書頒發(fā)機(jī)構(gòu)(windows)
sudo cp ca.crt??/usr/local/share/ca-certificates &&?sudo update-ca-certificates
(ubuntu/linux)
不然,建立不了連接
如果有frp的配置等問題可以來私聊