frp內網穿透服務器搭建及免費frp服務器提供

通過自定義域名訪問部署于內網的 web 服務【frp內網穿透服務器搭建及免費frp服務器提供】有時想要讓其他人通過域名訪問或者測試我們在本地搭建的 web 服務,但是由于本地機器沒有公網 IP,無法將域名解析到本地的機器,通過 frp 就可以實現這一功能,以下示例為 http 服務,https 服務配置方法相同,vhost_http_port 替換為 vhost_https_port,type 設置為 https 即可 。

  1. 修改 frps.ini 文件,設置 http 訪問端口為 8080:
# frps.ini[common]bind_port = 7000vhost_http_port = 8080
  1. 啟動 frps:
./frps -c ./frps.ini
  1. 修改 frpc.ini 文件,假設 frps 所在的服務器的 IP 為 x.x.x.x,local_port 為本地機器上 web 服務對應的端口, 綁定自定義域名 www.yourdomain.com:
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[web]type = httplocal_port = 80custom_domains = www.yourdomain.com
  1. 啟動 frpc:
./frpc -c ./frpc.ini
  1. 將 www.yourdomain.com 的域名 A 記錄解析到 IP x.x.x.x,如果服務器已經有對應的域名,也可以將 CNAME 記錄解析到服務器原先的域名 。
  2. 通過瀏覽器訪問 http://www.yourdomain.com:8080 即可訪問到處于內網機器上的 web 服務 。
https://github.com/fatedier/frp/blob/master/README_zh.md
1使用nohup來啟動這是frps的后臺啟動(路徑寫你服務器上的絕對路徑),如果要查看日志的話,就直接使用cat nohup.out,就可以查看了 。
nohup /path/to/your/fprs -c-c /path/to/your/frps.ini
這是frpc的后臺啟動
nohup /path/to/your/fprc -c-c /path/to/your/frpc.ini
2使用systemctl來控制啟動這個方法比較好用,很方便
sudo vim /lib/systemd/system/frps.service
在frps.service里寫入以下內容
[Unit]Description=fraps serviceAfter=network.target syslog.targetWants=network.target[Service]Type=simple#啟動服務的命令(此處寫你的frps的實際安裝目錄)ExecStart=/your/path/frps -c /your/path/frps.ini[Install]WantedBy=multi-user.target
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
然后就啟動frps
sudo systemctl start frps
再打開自啟動
sudo systemctl enable frps
  • 如果要重啟應用,可以這樣,sudo systemctl restart frps
  • 如果要停止應用,可以輸入,sudo systemctl stop frps
  • 如果要查看應用的日志,可以輸入,sudo systemctl status frps
3使用supervisor來控制首先先安裝supervisor,我用的ubuntu
sudo apt install supervisor
創建 supervisor frps 配置文件,在 /etc/supervisor/conf.d 創建 frp.conf
[program:frp]command = /your/path/frps -c /your/path/frps.iniautostart = true
  • 1
  • 2
  • 3
同樣是你的絕對路徑 。
寫完以后,要重新加載一下supervisor
# 重啟supervisorsudo systemctl restart supervisor# 查看supervisor運行狀態sudo supervisorctl status
  • 1
  • 2
  • 3
  • 4

    相關經驗推薦