

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# CodeBuild 在透明代理服务器中运行
<a name="run-codebuild-in-transparent-proxy-server"></a>

 要 AWS CodeBuild 在透明代理服务器上运行，必须将代理服务器配置为可以访问与之交互的网站和域。

**Topics**
+ [将 Squid 配置为透明代理服务器](#use-proxy-server-transparent-squid-configure)
+ [创建 CodeBuild 项目](#use-proxy-server-transparent-create-acb-project)

## 将 Squid 配置为透明代理服务器
<a name="use-proxy-server-transparent-squid-configure"></a>

 要将代理服务器配置为透明，您必须授予其访问您希望其访问的域和网站的权限。要 AWS CodeBuild 使用透明代理服务器运行，必须授予其访问权限`amazonaws.com`。您还必须授予其他网站的访问 CodeBuild 权限。它们会有所不同，具体取决于您创建 CodeBuild 项目的方式。示例网站是 Bitbucket GitHub、Yum 和 Maven 等存储库的网站。要授予 Squid 访问特定域和网站的权限，请使用类似于以下内容的命令来更新 `squid.conf` 文件。此示例命令授予对 `amazonaws.com`、`github.com` 和 `bitbucket.com` 的访问权限。您可以编辑此示例以授予对其他网站的访问权限。

```
cat | sudo tee /etc/squid/squid.conf ≪EOF
visible_hostname squid
#Handling HTTP requests
http_port 3129 intercept
acl allowed_http_sites dstdomain .amazonaws.com
#acl allowed_http_sites dstdomain domain_name [uncomment this line to add another domain]
http_access allow allowed_http_sites
#Handling HTTPS requests
https_port 3130 cert=/etc/squid/ssl/squid.pem ssl-bump intercept
acl SSL_port port 443
http_access allow SSL_port
acl allowed_https_sites ssl::server_name .amazonaws.com
acl allowed_https_sites ssl::server_name .github.com
acl allowed_https_sites ssl::server_name .bitbucket.com
#acl allowed_https_sites ssl::server_name [uncomment this line to add another website]
acl step1 at_step SslBump1
acl step2 at_step SslBump2
acl step3 at_step SslBump3
ssl_bump peek step1 all
ssl_bump peek step2 allowed_https_sites
ssl_bump splice step3 allowed_https_sites
ssl_bump terminate step2 all
http_access deny all
EOF
```

 来自私有子网中的实例的传入请求必须重定向到 Squid 端口。Squid 在端口 3129 上侦听 HTTP 流量（而不是 80），并在端口 3130 上侦听 HTTPS 流量（而不是 443）。使用 **iptables** 命令可路由流量：

```
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3129
sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 3130
sudo service iptables save
sudo service squid start
```

## 创建 CodeBuild 项目
<a name="use-proxy-server-transparent-create-acb-project"></a>

 配置代理服务器后，无需进行更多配置，即可 AWS CodeBuild 在私有子网中使用它。每个 HTTP 和 HTTPS 请求都经过公共代理服务器。使用以下命令查看 Squid 代理服务器访问日志：

```
sudo tail -f /var/log/squid/access.log
```