# 无法看到 localhost 服务器的任何请求

> localhost:3000 的请求没有显示在 Proxyman 中？可借助 Automatic Setup 从 Google Chrome 抓取 localhost 流量，或使用 /etc/hosts 或 localhost.proxyman.io。

## 1. 问题 {#1-problem}

我在 **http://localhost:3000** 上开发了一个本地 NodeJS、Ruby 或 Python 后端，但在 Google Chrome 或 Safari 中访问 **http://localhost:3000** 时，Proxyman 应用中没有任何流量。

**为什么会这样？** 在 macOS 上，默认情况下 localhost 请求不会经过系统 HTTP 代理，因此 Proxyman 不会记录任何流量。

![Google Chrome 打开 localhost:4000 时，Proxyman 请求列表保持为空](https://proxyman.com/docs/assets/capture_http_localhost_chrome_2.jpeg)

_默认情况下，localhost 流量不会显示在 Proxyman 中_

## 2. 解决方法 {#2-solution}

### 2.1 ✅ v6.3.0 版本的新方法 {#21--new-solution-for-v630}

从 Proxyman macOS v6.3.0 开始，Proxyman 可以：

* 在 Google Chrome / Firefox 中抓取 `http://localhost:3000` 或任何 localhost 流量，无需修改 /etc/hosts 文件
* 只需点击一下即可完成
* 教程：[如何从 Google Chrome 抓取 HTTP localhost 流量](https://proxyman.com/posts/how-to-capture-http-localhost-traffic-from-google-chrome)

#### 操作方法 {#how-to-do-it}

1. 在 Proxyman 中打开 **Setup** 菜单 → **Automatic Setup…**，然后在 Web Browsers 部分点击 **Google Chrome…**
2. 会出现一个新的 Google Chrome 窗口。
3. 完成。访问 http://localhost:3000，Proxyman 即可抓取该请求。

![Proxyman 从 Google Chrome 中抓取 localhost:3000 和 localhost:4000 的请求](https://proxyman.com/docs/assets/capture_http_localhost_chrome_1.jpeg)

_从 Google Chrome 抓取 localhost 流量_

### 2.2 旧方法 {#22-old-solution}

以下提供两种方法，任选其一即可。

#### 方法一：在 `/etc/hosts` 中将 **localhost** 映射到域名  {#solution-1-map-localhost-to-a-domain-name-in-etchosts-}

1. 使用 Vim 或 VS Code 打开 `/etc/hosts` 文件。

```
$ sudo vim /etc/hosts
```

2\. 为 **IPv4** 和 **IPv6** 添加域名（可以将 `proxyman.debug` 替换为任意名称）

```
127.0.0.1 proxyman.debug
::1 proxyman.debug
```

![VS Code 中的 /etc/hosts 文件，proxyman.debug 映射到 127.0.0.1 和 ::1](https://proxyman.com/docs/assets/Screenshot%202023-09-01%20at%2022.11.30.png)

_在 /etc/hosts 中添加 proxyman.debug_

3\. 使用 `sudo` 权限保存文件。

4\. 访问 **http://proxyman.debug:3000** 上的本地服务器（将 3000 替换为你的 localhost 端口）。 

5\. 尽情调试吧！

> **备注:** 如果你使用 `local` 作为后缀，例如 proxyman.local，请确保从绕过代理列表中移除 `*.local`（[操作方法](https://proxyman.com/docs/zh-cn/troubleshooting/.local-doesnt-appear-in-proxyman#2-solution)）。

#### 方法二：使用 **localhost.proxyman.io** 代替 **localhost** {#solution-2-use-localhostproxymanio-instead-of-localhost}

Proxyman 使用 Cloudflare，并将 **localhost.proxyman.io** 的 DNS 解析为 127.0.0.1（localhost）。因此，Proxyman 可以像平常一样抓取本地流量 ✅ 

例如：

<table data-header-hidden><thead><tr><th width="374">旧 URL</th><th>新 URL</th></tr></thead><tbody><tr><td>旧 URL</td><td>新 URL</td></tr><tr><td>localhost:3000</td><td>localhost.proxyman.io:3000</td></tr><tr><td>localhost:8080</td><td>localhost.proxyman.io:8080</td></tr><tr><td>...</td><td>...</td></tr></tbody></table>
