

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在代理伺服器中執行套用管理員和其他工具
<a name="use-proxy-server-tools"></a>

使用下列程序在代理伺服器中執行套件管理員和其他工具。

**在代理伺服器中執行工具，例如套件管理員**

1.  在 `squid.conf` 檔案中新增陳述式，以將工具新增至代理伺服器的允許清單。

1.  在 buildspec 檔案中新增一行，指向您代理伺服器的私有端點。

 下列範例示範如何對 `apt-get`、`curl` 和 `maven` 這樣做。如果您使用不同的工具，也適用同樣的原則。將其新增至 `squid.conf` 檔案中的允許清單，並將命令新增至您的 buildspec 檔案，讓 CodeBuild 了解代理伺服器的端點。

**如何在代理伺服器中執行 `apt-get`**

1. 在 `squid.conf` 檔案中新增以下陳述式，將 `apt-get` 新增至代理伺服器的允許清單。前三行允許 在建置環境中`apt-get`執行 。

   ```
   acl allowed_sites dstdomain ppa.launchpad.net # Required for apt-get to run in the build environment
   acl apt_get dstdom_regex .*\.launchpad.net # Required for CodeBuild to run apt-get in the build environment
   acl apt_get dstdom_regex .*\.ubuntu.com    # Required for CodeBuild to run apt-get in the build environment
   http_access allow localnet allowed_sites
   http_access allow localnet apt_get
   ```

1. 在 buildspec 檔案中新增以下陳述式，讓 `apt-get` 命令在 `/etc/apt/apt.conf.d/00proxy` 中尋找代理組態。

   ```
   echo 'Acquire::http::Proxy "http://<private-ip-of-proxy-server>:3128"; Acquire::https::Proxy "http://<private-ip-of-proxy-server>:3128"; Acquire::ftp::Proxy "http://<private-ip-of-proxy-server>:3128";' > /etc/apt/apt.conf.d/00proxy
   ```

**如何在代理伺服器中執行 `curl`**

1.  在 `squid.conf` 檔案中新增以下陳述式，將 `curl` 新增至建置環境中的允許清單。

   ```
   acl allowed_sites dstdomain ppa.launchpad.net # Required to run apt-get in the build environment
   acl allowed_sites dstdomain google.com # Required for access to a webiste. This example uses www.google.com.
   http_access allow localnet allowed_sites
   http_access allow localnet apt_get
   ```

1.  在 buildspec 檔案中新增以下陳述式，讓 `curl` 使用私有代理伺服器來存取您新增到 `squid.conf` 的網站。在此範例中，網站為 `google.com`。

   ```
   curl -x <private-ip-of-proxy-server>:3128 https://www.google.com
   ```

**如何在代理伺服器中執行 `maven`**

1.  在 `squid.conf` 檔案中新增以下陳述式，將 `maven` 新增至建置環境中的允許清單。

   ```
   acl allowed_sites dstdomain ppa.launchpad.net # Required to run apt-get in the build environment
   acl maven dstdom_regex .*\.maven.org # Allows access to the maven repository in the build environment
   http_access allow localnet allowed_sites
   http_access allow localnet maven
   ```

1. 在您的 buildspec 檔案中新增以下陳述式。

   ```
   maven clean install -DproxySet=true -DproxyHost=<private-ip-of-proxy-server> -DproxyPort=3128
   ```