项目地址: [https://github.com/fatedier/frp](https://github.com/fatedier/frp) ### 服务端和客户端配置 > 服务端(server) frps.ini 文件内容: ```ini [common] bind_port = 7000 vhost_http_port = 8007 # 仪表盘配置 dashboard_addr = 0.0.0.0 dashboard_port = 8008 dashboard_user = admin dashboard_pwd = admin # trace, debug, info, warn, error log_file = /home/www/bin/frp/frps.log log_level = info log_max_days = 3 # auth token token = WktjD1QB9SnH8mv81xzLNU283ern8YiFtY= # when subdomain is test, the host used by routing is test.frps.com subdomain_host = frp.tinywan.top # if tcp stream multiplexing is used, default is true tcp_mux = true ``` 开启服务 ``` nohup ./frps -c frps.ini & ``` > 客户端(Client)配置 frpc.ini 配置文件 ``` [common] server_addr = frp.tinywan.top server_port = 7000 token = WktjD1QBSnH8mv81xzLNU283ern8YiFtY= [newtrain] type = http local_ip = 127.0.0.1 local_port = 80 subdomain = newtrain ``` window 客户端使用git bash 启动客户端程序 ```bash Tinywan@DESKTOP-TEDEO2S MINGW64 ~/Desktop/frp_0.20.0_windows_amd64 $ ./frpc.exe -c frpc.ini 2020/02/04 17:30:46 [I] [proxy_manager.go:300] proxy removed: [] 2020/02/04 17:30:46 [I] [proxy_manager.go:310] proxy added: [newtrain] 2020/02/04 17:30:46 [I] [proxy_manager.go:333] visitor removed: [] 2020/02/04 17:30:46 [I] [proxy_manager.go:342] visitor added: [] 2020/02/04 17:30:47 [I] [control.go:246] [bee78005cfa109d5] login to server success, get run id [bee78005cfa109d5], server udp port [0] 2020/02/04 17:30:47 [I] [control.go:169] [bee78005cfa109d5] [newtrain] start proxy success ``` >[danger] 如果提示错误信息:`login to server failed: EOF`。这种情况是客户端版本和服务器版本的版本号不一致 #### Web 服务配置 这里按照PHPStudy 集成环境为案例Apache >[success] Nginx 虚拟主机配置 ``` server { listen 80; server_name newtrain.frp.tinywan.top; root "D:/phpstudy_pro/WWW/WC3.0/public"; location / { index index.php index.html; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } } location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } } ``` 重启Nginx服务 > Apache 虚拟主机配置 配置vhost ```bash <VirtualHost *:80> DocumentRoot "D:\phpStudy\PHPTutorial\WWW\pay_project_dev\public" ServerName pay.env ServerAlias newtrain.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> ``` 重启Apache服务 > 代理预览 访问公网地址:`http://newtrain.frp.tinywan.top:8007/?aa=bb`。 ### 其他附件 ##### 配置一个域名 > 服务端配置 ``` [common] bind_port = 7000 vhost_http_port = 8080 ``` 1、服务端IP地址:`139.224.239.21` 2、服务商域名解析: `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> ``` >[success] 浏览器地址栏:`http://frp.tinywan.top:8080/index/index/last_insert_id` 将会通过外网访问本地Web项目了 >[success]### 自定义二级域名 #### 服务端配置 ``` [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` >[success]### 自定义三级域名 > 【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.conf`:`ServerAlias 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` 即可访问 >[success]### 配置多个客户端 这里配置多个客户端,只要开启本地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 ```