代理故障排除

了解如何使用一组推荐的工具对代理进行故障排除。


macOS 代理配置 (Sierra)

🌐 macOS proxy configuration (Sierra)

如果出现任何问题,你可以在系统网络偏好设置中使用自动代理配置 your-corporate-proxy-uri:port-number/proxy.pac 恢复到“自动代理设置”。

概述

🌐 Overview

要在使用公司 Wi-Fi 网络时在本地 iOS 模拟器中运行此操作,需要一个本地代理管理器。你可以使用本地代理应用,例如 Charles

🌐 To run this in the local iOS Simulator while on your corporate Wi-Fi network, a local proxy manager is required. You can use a local proxy application such as Charles.

打开 macOS 网络偏好设置

🌐 Open macOS network preferences

  1. 在你的 Mac 上打开 System Preferences(苹果菜单 > 系统偏好设置)。
  2. 转到网络。
  3. 确保你的 Location 设置为你的代理网络,而不是“自动”。
  4. 在左侧选择 Wi-Fi 和/或以太网连接后,点击窗口右下角的 Advanced...

配置代理地址

🌐 Configure proxy address

  1. 如果已启用,请禁用/取消勾选“自动代理配置”。
  2. 勾选“Web 代理(HTTP)”,并将“Web 代理服务器”设置为 127.0.0.1:8888
  3. 勾选“安全网页代理(HTTPS)”,并将“安全网页代理服务器”设置为 127.0.0.1 : 8888

配置 Charles

🌐 Configure Charles

  1. 打开查尔斯

  2. 如果它提示,不要允许它管理你的 macOS 网络配置,之前的步骤已经完成了这一操作。(如果你更改了 Charles 的端口,请在前面的步骤中更新为正确的端口,而不是默认的 8888)

  3. 在 Charles 的菜单中,进入 Proxy > External Proxy Settings,勾选 Use external proxy servers

  4. 检查 Web Proxy (HTTP),然后输入 your-corporate-proxy-uri:port-number

  5. 检查 Proxy server requires a password

  6. 域:你的域名,用户名:你的用户名,密码:你的密码

  7. 安全网页代理(HTTPS)也一样。_请务必填写相同的代理、用户名和密码地址_字段。

  8. Bypass external proxies for the following hosts: 的文本区域输入:

    localhost *.local

    你可能需要包含你的邮件服务器或其他公司网络地址。

  9. 勾选“总是绕过本地主机的外部代理”

iOS 模拟器配置

🌐 iOS Simulator configuration

如果你已有一个正在运行的 iOS 模拟器自定义设置但无法正常工作,请在菜单中选择“模拟器 > 重置内容和设置”。

🌐 If you have an existing iOS Simulator custom setup going that is not working, "Simulator > Reset Content and Settings" from the menu.

如果模拟器仍处于打开状态,请退出它。

🌐 If you have the Simulator open still, quit it.

现在,在 Charles 中,点击“帮助”菜单 > 安装 Charles 根证书,然后再次在 iOS 模拟器中安装 Charles 根证书

🌐 Now, in Charles under the "Help" menu > Install Charles Root Certificate, and then again for Install Charles Root Certificate in iOS Simulators

技术说明: 这个整个过程是必要的,因为 iOS 模拟器收到的是一个无效的代理证书,而不是实际证书,并且不允许使用它,针对 https://exp.host/,而这个网址是运行 Expo 所必需的。
另请注意: 配置需要互联网访问的应用,比如 Spotify,使用 http://localhost:8888 作为你的代理。一些应用,比如 Chrome 和 Firefox,你可以在设置中配置使用“系统网络偏好设置”,它将使用 Charles: 8888,或者不使用代理,这取决于你在 Apple 菜单/网络偏好设置中如何设置“位置”。如果设置为“自动”,则不使用代理;如果设置为“你的代理网络”,则会使用代理,并且需要保持 Charles 运行。

命令行应用代理配置

🌐 Command line application proxy configuration

npm、git、Brew、Curl 和任何其他命令行应用也需要代理访问。

🌐 npm, git, Brew, Curl, and any other command line applications need proxy access too.

对于 npm

🌐 For npm

打开 ~/.npmrc 并设置:

🌐 Open ~/.npmrc and set:

.npmrc
http_proxy=http://localhost:8888 https_proxy=http://localhost:8888

对于 git

🌐 For git

打开 ~/.gitconfig 并设置

🌐 Open ~/.gitconfig and set

.gitconfig
[http] proxy = http://localhost:8888 [https] proxy = http://localhost:8888

对于命令行应用

🌐 For command line applications

根据你的 shell 和配置,打开 ~/.bashrc~/.bash_profile~/.zshrc,或者你设置 shell 变量的地方,并设置:

🌐 Depending on your shell, and config, Open ~/.bashrc, ~/.bash_profile, or ~/.zshrc or wherever you set your shell variables and set:

export HTTP_PROXY="http://localhost:8888" export http_proxy="http://localhost:8888" export ALL_PROXY="http://localhost:8888" export all_proxy="http://localhost:8888" export HTTPS_PROXY="http://localhost:8888" export https_proxy="http://localhost:8888"

如果你将网络位置切换回“自动”以使用 npm 或 git,你需要在希望禁用的行前使用 # 将这些行注释掉。你也可以选择使用命令行代理管理工具。