背景:把内网研发机器(没有公网)暴露在公网上提供服务:真实提供服务,小程序、公众号码测试

环境: linux, 阿里云机器(A), 本地内网机器(B)

1. 下载 frp

wget https://github.com/fatedier/frp/releases/download/v0.21.0/frp_0.21.0_linux_386.tar.gz

解压

2. 编辑服务器(A)配置:frps.ini

# frps.ini
[common]
bind_port = 9001
vhost_http_port = 9002

bind_port 负责有B 通信, vhost_http_port 数据监听地址

3. 编辑服务器(A)配置(nginx):

server {
    listen       80;
    server_name  neice.xxxx.vip;
    access_log /opt/xxxx/access.log;
    error_log /opt/xxxx/error.log;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:9002;
    }
}

4. 编辑客户端(B) 配置: frpc.ini

[common]
server_addr = 阿里云机器B的公网地址
server_port = 9001

[web]
type = http
local_port = 8081
custom_domains = 127.0.0.1

5. 启动服务:

nginx

./frps -c ./frps.ini

./frpc -c ./frpc.ini

6. 修改DNS 指向

neice.xxxx.vip 指向阿里云机器A 的公网地址

 

7. 整个数据流程

nei.xxxx.vip -----> 阿里云A的80端口, nginx处理-------> 转发到阿里云的9002 端口---------> 阿里云A通过9001与B机器通信 ------> B 机器通过本地8081 对外服务

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐