---
title: "用 Google Cloud Platform 搭建內網穿透伺服器 ( Frp Server )"
description: "逐步說明如何在 Google Cloud Platform 建立 Ubuntu VM，安裝並設定 FRP Server，實現穩定且低成本的內網穿透服務。"
canonical_url: "https://blog.markkulab.net/post/frps"
author: "Mark Ku"
author_url: "https://blog.markkulab.net/author/mark-ku"
site: "Mark Ku's Blog"
date_published: "2024-10-01 01:01:35 +0800"
category: "Cloud"
tags: ["frp", "frps", "reverse proxy", "gcp", "nat traversal", "self-hosted", "linux", "cloud"]
language: "zh-TW"
license: "CC BY 4.0"
license_url: "https://creativecommons.org/licenses/by/4.0/"
attribution: "轉載或引用請註明作者並附上原文連結"
---

# 用 Google Cloud Platform 搭建內網穿透伺服器 ( Frp Server )

## 解決問題
[先前一篇文章+](https://blog.markkulab.net/2021/05/31/frpc/)介紹過如何透過免費的 Frps 反向代理伺服器，將內網網站經過映射出去，但因為免費的真的太不穩定，BLOG 和 DEMO 網站，常常服務會掛掉，後來經網友推薦，Google 有免費體驗90天，並給予 300 美金的體驗費用，這篇就來介紹用 GCP (Google Cloud) 來自己架內網穿透伺服器 ( FRPS )

## 首先，請申請 GCP 帳號及挷定信用卡

## 登入 GCP 的後台 > 虛擬機器 (VM) 執行個體
![GCP Compute Engine VM執行個體，建立執行個體按鈕](https://blog.markkulab.net/content/markku/posts/frps/images/LNph6ly.webp)

## 選擇地區為台灣，作業系統 Ubuntu ，因為我只要反向代理，不需要複雜的運算，選擇 f1-micro就好，預估費用一個月只要約 15X 元台幣，算是蠻實惠的。  
![GCP建立frp-server虛擬機，f1-micro每月5.60](https://blog.markkulab.net/content/markku/posts/frps/images/qtpWIMy.png)

## 主機建立好時，在菜單選單中找到 VPC 網路，將主機的IP改成靜態，這樣就IP就不會跑掉了。
![GCP VPC網路將frp-server的IP設為靜態](https://blog.markkulab.net/content/markku/posts/frps/images/PukFeHZ.webp)

![保留新的靜態IP位址視窗，名稱frp-server](https://blog.markkulab.net/content/markku/posts/frps/images/TyPfbfU.webp)

## 回到虛擬機器( VM ) 執行個體，對剛建立的主機開啟 SSH
![Google Cloud VM 執行個體 SSH 選單](https://blog.markkulab.net/content/markku/posts/frps/images/AuSmzRf.webp)

## 接著會開啟瀏覽器版 SSH 中，依序輸入下面的 Linux 指令

更新系統

```
sudo apt-get update
sudo apt-get upgrade
```

FRP使用Go語言，大部分Linux主機都有預裝了，但如果你的沒有，可以先執行以下指令

```
sudo apt-get install bison ed gawk gcc libc6-dev make golang-go vim
```

接著你必須到FRP的Github上查看最新frps ，並下載他

```
wget https://github.com/fatedier/frp/releases/download/v0.62.1/frp_0.62.1_linux_amd64.tar.gz
```

解壓縮檔案並重新命名資料夾為 frp

```
tar -zxvf frp_0.62.1_linux_amd64.tar.gz
sudo mkdir /var/frps
sudo mv frp_0.62.1_linux_amd64/* /var/frps/
cd /var/frps
```

編輯 frps 的設定檔 (sudo vim frps.toml)

```
# frps.toml
bindAddr = "0.0.0.0"
bindPort = 7000
vhostHttpPort = 80
vhostHttpsPort = 443
webServer = { port = 7500, user = "admin", password = "your password", addr="0.0.0.0" }
auth.method = "token"
auth.token = "your token"
```

執行
```
sudo ./frps -c ./frps.toml
```

## 在到 DNS 主機中設定域名
![Frp伺服器啟動成功並建立多個代理](https://blog.markkulab.net/content/markku/posts/frps/images/wxhxp8T.webp)

首先將挷定 DNS 將 proxy.markkulab.net 指向 FRPS 主機外部IP
![DNS A 記錄設定介面，主機 proxy 指向 IP 位址](https://blog.markkulab.net/content/markku/posts/frps/images/Br3Kpe1.webp)
接著，挷定 CNAME，這樣訪問者訪問 blog.markkulab.net frps 就會指到指定用戶端映射的網站
![CNAME 記錄設定，主機 blog 指向](https://blog.markkulab.net/content/markku/posts/frps/images/WHDoSYy.webp)

![設定 CNAME 記錄，將 shop 指向](https://blog.markkulab.net/content/markku/posts/frps/images/7iCNmjK.webp)

## frpc.toml 的設定

```
serverAddr = "35.223.172.254"
serverPort = 7000
auth.token = "your token"
transport.poolCount = 10000

[[proxies]]
name = "test-tcp"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 6000

[[proxies]]
name = "ShopCarthttps1"
type = "http"
customDomains = ["www.letgo.com.tw"]
localPort = 8896

[[proxies]]
name = "linebot"
type = "https"
customDomains = ["linebot.letgo.com.tw"]
[proxies.plugin]
type = "https2http"
localAddr = "127.0.0.1:48002"
crtPath = "/Public/!.letgo.com.tw/fullchain.crt"
keyPath = "/Public/!.letgo.com.tw/cert.key"
hostHeaderRewrite = "linebot.letgo.com.tw"
requestHeaders.set.x-from-where = "frp"
```
## 如果你需要重開機自動啟動，則需要額外註冊成服務
### 在 /lib/systemd/system/ 增加設定檔
```
sudo vim /lib/systemd/system/frps.service
```
建立自動啟動設定檔
```
[Unit]
Description=FRP Server
After=network.target
Wants=network.target

[Service]
Restart=on-failure
RestartSec=5
ExecStart=/var/frps/frps -c /var/frps/frps.toml

[Install]
WantedBy=multi-user.target
```
### 啟動服務
```
sudo systemctl daemon-reload  // reload service
sudo systemctl stop frps.service //停止 FRP Server 服務
sudo systemctl start frps.service //啟動 FRP Server 服務
sudo systemctl restart frps.service //重啟 FRP Server 服務
sudo systemctl disable frps.service //開機時不要啟動 FRP Server 服務
sudo systemctl enable frps.service //開機時自動啟動 FRP Server 服務
sudo systemctl status frps.service //查看FRP Server 狀態
```
## 測試防火牆有沒有關
windows 測試防火牆有沒有關
```
telnet 35.223.172.254  7000
```
linux 測試防火牆有沒有開
```
nc -zv 127.0.0.1 7000
```
## 記得 GCP 必須關閉防火牆，否則外網連不到，回到 instance 修改裡面的 Network tags 才會生效。
![Google Cloud防火牆規則frps設定，允許所有來源與埠](https://blog.markkulab.net/content/markku/posts/frps/images/disable-gcp-firewall.png)

## 接著找一台 Ubuntu 主機來，安裝frpc
### 建立資料夾
```
sudo mkdir -p /etc/frp
```
### 下載 FRP 0.62.1 並解壓到 
```
cd /etc/frp
sudo wget https://github.com/fatedier/frp/releases/download/v0.62.1/frp_0.62.1_linux_amd64.tar.gz
sudo tar -zxvf frp_0.62.1_linux_amd64.tar.gz --strip-components=1
```
### 建立frpc.toml設定檔
```
sudo vim /etc/frp/frpc.toml
```
frpc.toml
```
serverAddr = "your server"
serverPort = 7000
auth.token = "your token"
transport.poolCount = 10000

[[proxies]]
name = "jks"
type = "https"
customDomains = ["jks.letgo.com.tw"]
[proxies.plugin]
type = "https2http"
localAddr = "127.0.0.1:8080"
crtPath = "/var/frpc/letgo/fullchain.crt"
keyPath = "/var/frpc/letgo/cert.key"
hostHeaderRewrite = "jks.letgo.com.tw"
requestHeaders.set.x-from-where = "frp"
```
### 測試
```
/etc/frp/frpc -c /etc/frp/frpc.toml
```
### 建立開機後自動啟動
```
sudo vim /lib/systemd/system/frpc.service
```
### 建立自動啟動的設定檔
```
[Unit]
Description=FRP Client
After=network.target
Wants=network.target

[Service]
Restart=on-failure
RestartSec=5
ExecStart=/etc/frp/frpc -c /etc/frp/frpc.toml

[Install]
WantedBy=multi-user.target
```
### 啟動服務 
```
sudo systemctl daemon-reload  // reload service
sudo systemctl stop frpc.service //停止 FRP Server 服務
sudo systemctl start frpc.service //啟動 FRP Server 服務
sudo systemctl restart frpc.service //重啟 FRP Server 服務
sudo systemctl disable frpc.service //開機時不要啟動 FRP Server 服務
sudo systemctl enable frpc.service //開機時自動啟動 FRP Server 服務
sudo systemctl status frpc.service //查看FRP Server 狀態
```
## 最後
最後將VM建在台灣節點，聽說Google的機房在嘉義，網速超級快，也很穩定，一個月差不多150元台幣左右，就能擁有反向代理及一個固定IP，其實蠻滑算的
![瀏覽器顯示販售水果乾的電商網站](https://blog.markkulab.net/content/markku/posts/frps/images/G28BhNe.webp)

## 補充 - GCP 免費計劃
[免費計劃連結](https://cloud.google.com/free/docs/gcp-free-tier/?hl=zh-CN#compute)

在免費試用期結束後，我們還是可以在限制的用量內免費使用特定產品。例如最常見的 Google Compute Engine 就提供了以下免費條件：  

僅限美國地區「us-central1」、「us-east1」和「us-west1」  
* 每月 1 個 f1-micro 執行個體每月 30 GB 硬碟空間
* 每月 1 GB 網路輸出量 (從北美輸出至中國和澳洲以外的所有地區)

f1 的方案 就算放在台灣一個月也只要  5.6 *27.82 (美金匯率) = 約 155 台幣左右
![GCP f1-micro 虛擬機設定與每月預估費用](https://blog.markkulab.net/content/markku/posts/frps/images/nGMDwz8.png)

---

## 關於本文與作者

本文出自 [Mark Ku's Blog](https://blog.markkulab.net/post/frps)

授權條款： [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) — 轉載或引用請註明作者並附上原文連結

### 關於作者

**[Mark Ku](https://blog.markkulab.net/author/mark-ku)** — Software Solution Provider

- 10+ 年資深軟體工程師，現為 AI 應用 Builder
- 專注大型平台架構設計，從北美電商到AI SaaS訂閱收費系統
- 結合 AI Agent 與自動化，打造高效可演進的產品技術基礎

### 作者開發的免費工具

以下工具皆可免費使用：

- [免費 PDF 簽名工具](https://blog.markkulab.net/tools/pdf-sign): 線上 PDF 簽名工具，瀏覽器內完成手繪、打字、上傳簽名，可拖曳放置、縮放、下載。所有處理都在你的裝置完成，檔案不會上傳。
- [VS Code Refactory](https://blog.markkulab.net/tools/refactory): Refactory 是一款 VS Code 重構擴充套件：34 個重構動作、37 條 code smell 檢查、Code Health 儀表板、18 種語言、534 支測試。懂你的專案慣例：介面放哪、DI 註冊寫在哪、'use client' 該不該加；還會用 git 修改頻率 × 複雜度排出「該先修哪個檔案」，並一鍵把壞味道交給你自己電腦上的 Claude Code 修。免費使用，原始碼不離開你的機器。
- [DB-Kit 資料庫管理工具](https://blog.markkulab.net/tools/db-kit): DB-Kit 是一個用 Tauri + Rust + React 打造的輕量跨平台資料庫管理工具，用單一一致的介面同時管理 MySQL、MariaDB、PostgreSQL、SQL Server、Oracle、SQLite、MongoDB、Redis、Kafka、Elasticsearch 與 RabbitMQ 十一種資料來源：連線密碼以 OS keychain 加密、SSH Tunnel、完整 CRUD、視覺化查詢建構器、多結果集同時顯示、跨連線資料傳輸與比對同步、Excel / CSV 匯入匯出、執行計畫視覺化、ER 圖、排程備份、SQL 壓力測試（p50～p99 延遲百分位）、15 條規則的 SQL 審查、Kafka 訊息瀏覽與監控告警；繁中 / 英文雙語介面，內建 AI 助手（自然語言生成 SQL、AI 審查與調校建議）與命令列工具 dbk。免費開源（MIT），提供 Windows / macOS / Linux 安裝檔。
- [VS Code Super Mermaid](https://blog.markkulab.net/tools/super-mermaid): Super Mermaid 是一款 VS Code 擴充套件：開箱即用的漂亮 Mermaid 圖表，自動上色、即時預覽、滑鼠平移縮放、PNG / SVG 高解析匯出，內建 21 種範本與多種主題。免費開源（MIT）。
- [React Super Mermaid](https://blog.markkulab.net/tools/react-super-mermaid): react-super-mermaid 是一個開源 React 元件庫：一行 <MermaidViewer> 即可渲染漂亮的 Mermaid 圖表，內建 colorful / sketch 主題、平移縮放、圖內搜尋、SVG / PNG 高解析匯出。輕量、SSR 安全、完整 TypeScript 型別。免費開源（MIT）。
- [Jira / Confluence Super Mermaid](https://blog.markkulab.net/tools/jira-super-mermaid): Atlassian Forge app：在 Jira issue 與 Confluence 內文直接寫 Mermaid 語法，畫流程圖、時序圖、狀態機與甘特圖。11 種圖表、SVG / PNG 匯出、明暗主題、完整中日韓文字支援。取得 Runs on Atlassian 資格：圖表存在你自己的站台，app 不呼叫任何第三方服務。免費，即將上架 Atlassian Marketplace。
- [Mermaid 線上預覽](https://blog.markkulab.net/tools/mermaid-preview): 在瀏覽器裡寫 Mermaid、即時看圖，整張圖表壓進網址就能分享。免註冊、不上傳伺服器，相容 mermaid.live 的分享連結。
- [React Intl Phone Number](https://blog.markkulab.net/tools/react-intl-phone-number): react-intl-phone-number 是一個開源 React 元件：framework-agnostic、不依賴 antd，提供 E.164 進出、可搜尋國旗 / 國碼下拉、可配置驗證等級（strict / mobile-strict / loose）、可主題化 CSS 與 i18n，電話邏輯由 google-libphonenumber 驅動。輕量、完整 TypeScript 型別。免費開源（MIT）。
- [Uptime Kuma Cluster](https://blog.markkulab.net/tools/uptime-kuma-cluster): 把單機版 Uptime Kuma 改造成高可用叢集：OpenResty + Lua 智慧負載平衡、MariaDB 共享狀態、健康檢查與自動 Failover，附叢集管理 REST API，一行 Docker Compose 啟動。免費開源（MIT）。
- [特教專案](https://blog.markkulab.net/education): 為特殊教育學生製作的學習教材

### 每日 Podcast

- [科技新鮮事](https://blog.markkulab.net/category/tech-news): 每日精選 AI 與科技趨勢，透過語音摘要快速掌握最新技術動態，涵蓋 AI 應用、軟體架構、DevOps 與工程實戰。 — RSS: https://blog.markkulab.net/feed.xml
- [AI股市蝦聊](https://blog.markkulab.net/category/ai-stock-chat): 每個交易日用 AI 分析台股盤勢，以雙人對話聊當天的盤中觀察與隔日預測。 — RSS: https://blog.markkulab.net/ai-stock-chat/feed.xml

### 電子報

[訂閱電子報](https://blog.markkulab.net/subscribe) — 第一時間收到新文章通知，無垃圾信、隨時可取消訂閱。
