微信支付需要提供回调接口,要求是公网的,https的,通常可使用 ngrok 解决,但此文讲述如何使用frp 搭建https的内网穿透。
方法是 使用frp搭建服务端与客户端的http连接,然后使用nginx配置域名的https,然后转发到frp的http上。
frp配置
服务端
[common]
# 服务器端监听客户端连接请求的端口
bind_port = 7100
# http端口
vhost_http_port = 7200
# 身份验证
token = akjdlakjdkasd
客户端
[common]
# 你的服务器ip
server_addr = 121.141.139.147
# 跟frps的配置端口一致
server_port = 7100
#同服务端的配置token一致,用于验证
token = hahahaha
[my_http]
type = http
local_ip = 127.0.0.1
# 本地起的服务端口
local_port = 7200
custom_domains = hahaha.qq.tech
remote_port = 7200
Nginx配置
# frp 内网穿透
server {
listen 443 ssl http2;
#你的域名
server_name hahaha.qq.tech;
ssl on;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers PROFILE=SYSTEM;
ssl_prefer_server_ciphers on;
#ssl证书的pem文件路径
ssl_certificate /home/cert/hahaha.qq.tech.pem;
#ssl证书的key文件路径
ssl_certificate_key /home/cert/hahaha.qq.tech.key;
location / {
# 转发到服务端的frp 监听的http端口
proxy_pass http://127.0.0.1:7200;
# 必须要header,不然frp可能识别不了
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
访问: https://hahah.qq.tech/api/xxxx 时,就会转发到本地内网机器的server服务上