frp 供内网穿透服务的工具

项目地址: https://github.com/fatedier/frp

修改配置文件:

[common]
server_addr = frp.yo1c.cc
server_port = 7000
#log_file = ./frpc.log
log_level = info
log_max_days = 3
privilege_token = 30064E394C1C63766DA345EEFDA490EF

[pay]
type = http
local_ip = 127.0.0.1
local_port = 80
subdomain = tinywan 
#custom_domains = www.yourdomain.com
pool_count = 10

使用git shell 启动服务

// 进入到当前frp文件目录
$ ./frpc.exe -c ./frpc.ini
2018/07/09 18:05:44 [I] [control.go:276] [61198354d3f13b48] login to server success, get run id [61198354d3f13b48]
2018/07/09 18:05:45 [I] [control.go:411] [61198354d3f13b48] [pay] start proxy success

phpstudy 配置vhost

<VirtualHost *:80>
    DocumentRoot "D:\phpStudy\PHPTutorial\WWW\pay_project_dev\public"
    ServerName pay.env
    ServerAlias frp.tinywan.top
  <Directory "D:\phpStudy\PHPTutorial\WWW\pay_project_dev\public">
      Options FollowSymLinks ExecCGI
      AllowOverride All
      Order allow,deny
      Allow from all
     Require all granted
  </Directory>
</VirtualHost>

重启phpstudy服务

访问公网地址:http://frp.tinywan.top/?aa=bb,可以方便调试异步回调

提示错误信息

frp安装的时候,提示:login to server failed: EOF

$ ./frpc.exe -c frpc.ini
2018/07/20 09:28:22 [W] [control.go:121] login to server failed: broken pipe
broken pipe

这种情况是客户端版本和服务器版本的版本号不一致


配置一个域名

服务端配置

[common]
bind_port = 7000
vhost_http_port = 8080

IP:139.224.239.21
域名 frp.tinywan.top 已经被A记录到139.224.239.21

客户端配置

[common]
server_addr = 139.224.239.21 # 可以直接换成 www.tinywan.com
server_port = 7000

[web]
type = http
local_port = 80
custom_domains = frp.tinywan.top

phpStudy配置 vhosts.conf

<VirtualHost *:80>
    DocumentRoot "D:\phpStudy\PHPTutorial\WWW\notes\public"
    ServerName notes.env   // 本地访问域名
    ServerAlias frp.tinywan.top // 外网访问域名
  <Directory "D:\phpStudy\PHPTutorial\WWW\notes\public">
      Options FollowSymLinks ExecCGI
      AllowOverride All
      Order allow,deny
      Allow from all
     Require all granted
  </Directory>
</VirtualHost>

浏览器地址栏:http://frp.tinywan.top:8080/index/index/last_insert_id

将会通过外网访问本地Web项目了

自定义二级域名

服务端配置
[common]
bind_port = 7000
vhost_http_port = 8007
subdomain_host = tinywan.top
token = 2W/WktjD1QB9xX/oDZSnH8mv81xzLNU283ern8YiFtY=

服务端IP:139.224.239.21
阿里云域名解析: *.tinywan.top A记录到139.224.239.21

客户端配置
  • 配置一(我的PC配置)

    [notes]
    type = http
    local_ip = 127.0.0.1
    local_port = 80
    use_encryption = false
    use_compression = false
    subdomain = notes
  • 配置二(我的笔记本配置)

    [pay]
    type = http
    local_ip = 127.0.0.1
    local_port = 80
    use_encryption = false
    use_compression = false
    subdomain = pay
phpStudy配置 vhosts.conf

PC配置

<VirtualHost *:80>
    DocumentRoot "D:\phpStudy\PHPTutorial\WWW\notes\public"
    ServerName notes.env
    ServerAlias notes.tinywan.top
  <Directory "D:\phpStudy\PHPTutorial\WWW\notes\public">
      Options FollowSymLinks ExecCGI
      AllowOverride All
      Order allow,deny
      Allow from all
     Require all granted
  </Directory>
</VirtualHost>

笔记本配置

<VirtualHost *:80>
    DocumentRoot "D:\phpStudy\PHPTutorial\WWW\pay_project_dev\public"
    ServerName pay.env
    ServerAlias pay.tinywan.top
  <Directory "D:\phpStudy\PHPTutorial\WWW\pay_project_dev\public">
      Options FollowSymLinks ExecCGI
      AllowOverride All
      Order allow,deny
      Allow from all
     Require all granted
  </Directory>
</VirtualHost>
访问浏览器
  • 地址一:http://notes.tinywan.top:8007/index/index/last_insert_id
  • 地址二:http://pay.tinywan.top:8007/index/index/last_insert_id

自定义三级域名

【1】二级域名:*.frp.tinywan.top 域名解析A记录到:139.224.239.21

【2】服务端配置:subdomain_host = frp.tinywan.top

【3】客户端配置:

[notes]
type = http
local_ip = 127.0.0.1
local_port = 80
use_encryption = false
use_compression = false
subdomain = notes

【4】phpStudy配置 vhosts.confServerAlias notes.frp.tinywan.top

【5】浏览器访问:http://notes.frp.tinywan.top:8007 即可访问

【6】Nginx做一个反向代理

server {
    server_name  notes.frp.tinywan.top;

    location / {
        proxy_pass http://0.0.0.0:8007;

        #Proxy Settings
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}

通过:http://notes.frp.tinywan.top 即可访问

配置多个客户端

这里配置多个客户端,只要开启本地WEB服务就可以直接访问了

多客户端配置

[notes]
type = http
local_ip = 127.0.0.1
local_port = 80
use_encryption = false
use_compression = false
subdomain = notes

[pay]
type = http
local_ip = 127.0.0.1
local_port = 80
use_encryption = false
use_compression = false
subdomain = pay

vhost.conf配置

<VirtualHost *:80>
    DocumentRoot "D:\phpStudy\PHPTutorial\WWW\notes\public"
    ServerName notes.env
    ServerAlias notes.frp.tinywan.top
    ...
</VirtualHost>


<VirtualHost *:80>
    DocumentRoot "D:\phpStudy\PHPTutorial\WWW\pay_project_dev\public"
    ServerName pay.env
    ServerAlias pay.frp.tinywan.top
    ...
</VirtualHost>

Nginx 配置

直接做两个代理皆可以

配置一:proxy_local:8007-notes.frp.tinywan.top.conf

server {
    server_name  notes.frp.tinywan.top;

    location / {
        proxy_pass http://0.0.0.0:8007;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}

配置二:proxy_local:8007-pay.frp.tinywan.top.conf

server {
    server_name  pay.frp.tinywan.top;

    location / {
        proxy_pass http://0.0.0.0:8007;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}

Windows 批处理文件 start_service.bat

frpc.exe -c frpc.ini
pause