---
title: "ngrok"
weight: 20
description: "内网穿透工具"
date: "2026-03-24T16:29:46+08:00"
lastmod: "2026-03-24T16:29:46+08:00"
---

## ngrok

ngrok 是一款内网穿透工具，可以将本地服务暴露到公网。

## 基础使用

### 启动 HTTP 隧道
```bash
ngrok http 80
```

### 启动 HTTPS 隧道
```bash
ngrok http https://localhost:443
```

### 指定端口
```bash
ngrok tcp 22
```

### 自定义域名
```bash
ngrok http --subdomain=myapp 8080
```

## 常用参数

| 参数 | 描述 |
|------|------|
| http | HTTP 隧道 |
| tcp | TCP 隧道 |
| --subdomain | 自定义子域名 |
| --region | 选择区域 |
| --config | 配置文件 |
| --log | 日志文件 |

## 功能特性

- **快速部署** - 一键启动隧道
- **HTTPS 支持** - 自动 SSL 证书
- **Web 界面** - 请求检查界面
- **API 支持** -  programmable API
- **认证机制** - 访问控制

## 使用示例

```bash
# 本地 Web 服务
ngrok http 3000

# TCP 服务
ngrok tcp 3306

# 指定区域
ngrok http 80 --region=us

# 保存配置
echo "authtoken: YOUR_TOKEN" > ~/.ngrok2/ngrok.yml
```

## 参考资源

- [ngrok 官方文档](https://ngrok.com/docs)
- [ngrok GitHub](https://github.com/inconshreveable/ngrok)