首页指南参考教程

代理故障排除

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


macOS 代理配置 (Sierra)

¥macOS proxy configuration (Sierra)

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

¥If anything goes wrong, you can revert to the "Automatic Proxy settings" in System Network Preferences using Automatic Proxy Configuration 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(Apple 菜单 > 系统偏好设置)。

    ¥Open System Preferences for your Mac (Apple Menu > System Preferences).

  2. 转到网络。

    ¥Go to Network.

  3. 确保你的 Location 设置为你的代理网络,而不是 "自动的"。

    ¥Be sure your Location is set to your proxy network, and not "Automatic".

  4. 在左侧选择 Wi-Fi 和/或以太网连接后,单击窗口右下角的 Advanced...

    ¥With Wi-Fi selected on the left and/or ethernet connection, click Advanced... on the bottom right side of the window.

配置代理地址

¥Configure proxy address

  1. 如果已设置,则禁用/取消选中 "自动代理配置"。

    ¥Disable/uncheck "Automatic Proxy Configuration" if it is set.

  2. 检查 "网络代理 (HTTP)" 并将 "网络代理服务器" 设置为 127.0.0.1 : 8888

    ¥Check "Web Proxy (HTTP)" and set "Web Proxy Server" to 127.0.0.1 : 8888

  3. 检查 "安全网络代理 (HTTPS)" 并将 "安全网络代理服务器" 设置为 127.0.0.1 : 8888

    ¥Check "Secure Web Proxy (HTTPS)" and set "Secure Web Proxy Server" to 127.0.0.1 : 8888

配置 Charles

¥Configure Charles

  1. 打开查尔斯

    ¥Open Charles

  2. 如果它询问,请不要允许它管理你的 macOS 网络配置,前面的步骤就是这样做的。(如果更改 Charles 端口,请将上一步更新为正确的端口,而不是默认的 8888)

    ¥If it asks, don't allow it to manage your macOS Network Configuration, the previous steps do that. (If you change Charles port, update the previous step to the correct port instead of default 8888)

  3. 在 Charles 的菜单中转到 Proxy > External Proxy Settings,选中 Use external proxy servers

    ¥In the menu of Charles go to Proxy > External Proxy Settings, check Use external proxy servers

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

    ¥Check Web Proxy (HTTP), and enter your-corporate-proxy-uri:port-number

  5. 检查 Proxy server requires a password

    ¥Check Proxy server requires a password

  6. 字段:你的域名、用户名:你的用户名密码:你的密码

    ¥Domain: YOUR DOMAIN, Username: YOUR USERNAME Password: YOUR PASSWORD

  7. 安全 Web 代理 (HTTPS) 也是如此。请务必填写相同的代理、用户名和密码地址字段。

    ¥Same for Secure Web Proxy (HTTPS). Be sure to fill in the same proxy, username, and password address fields.

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

    ¥In the text area for Bypass external proxies for the following hosts: enter:

    localhost
    *.local
    

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

    ¥You may need to include your mail server or other corporate network addresses.

  9. 检查 "始终绕过本地主机的外部代理"

    ¥Check "Always bypass external proxies for localhost"

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 模拟器提供的是一个临时代理证书而不是实际证书,并且不允许它,对于运行 Expo 所需的 https://exp.host/
另请注意:配置需要互联网访问的应用(例如 Spotify)以使用 http://localhost:8888 作为代理。某些应用(例如 Chrome 和 Firefox),你可以在设置中配置为使用 "系统网络偏好设置",该 "系统网络偏好设置" 将使用 Charles : 8888,或不使用代理,具体取决于你在 Apple 菜单/网络首选项中设置 "定位" 的方式。如果设置为 "自动的",则不使用代理;如果设置为 "你的代理网络",则使用代理,并且需要运行 Charles。

¥Technical note: This whole process is required because the iOS Simulator is served a bum proxy certificate instead of the actual certificate, and doesn't allow it, for https://exp.host/ which is required to run Expo.
Also note: Configure applications that need internet access, such as Spotify, to use http://localhost:8888 as your proxy. Some apps, such as Chrome and Firefox, you can configure in the settings to use your "System Network Preferences" which will use Charles : 8888, or no proxy, depending on how you have your "Location" set in the Apple menu/network preferences. If you are set to "Automatic" no proxy is used, if it is set to "your proxy network" the proxy is used and Charles will need to be running.

命令行应用代理配置

¥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,则需要在要禁用的行之前使用 # 注释掉这些行。如果你愿意,也可以使用命令行代理管理器。

¥If you switch your network location back to "Automatic" to use npm or git, you will need to comment these lines out using a # before the line you wish to disable. You could alternatively use a command-line proxy manager if you prefer.

Expo 中文网 - 粤ICP备13048890号