---
schema_version: "1"
id: cec71821503b109d81615bfa82774e3b13cb7b19b5655da3b0b627d265208fd1
title: 为 Tableau Server 配置代理和负载平衡器
collection: tableau
version: next
locale: zh-cn
portal_url: https://docs.salesforce.com/tableau/next/zh-cn/server-linux/proxy.md
canonical_url: https://help.tableau.com/v0.0/server-linux/zh-cn/proxy.htm
source_site: help.tableau.com
content_type: documentation
content_hash: 66e9020d5571f13eafbad5e05d53dfe9e506141292b11a517fc22fece9ede7a6
description: Configure forward proxies, reverse proxies, and load balancers for Tableau Server.
---
[跳转到主要内容](#main-content)

# 为 Tableau Server 配置代理和负载平衡器

在大多数企业中，Tableau Server 需要与 Internet 通信。Tableau Server 旨在受保护的内部网络内部运行。不要直接在 Internet 或 DMZ 中设置 Tableau Server。相反，您的网络和 Internet 之间的通信应使用代理服务器传递。反向代理服务器将流量从网络内部传递到 Internet 上的目标。反向代理服务器和负载平衡器将流量从 Internet 传递到网络内部的目标。

## 谁应阅读本文？

本文面向拥有常规联网、负载平衡和网关代理解决方案经验的 IT 专业人员。本文描述 Tableau 为何以及在何时需要 Internet 访问权限，并描述如何配置网络和 Tableau 以使用代理服务器和负载平衡器来访问 Internet 以及通过 Internet 进行访问。有许多第三方解决方案，因此本文的某些内容一定是通用的。

在配置代理服务器之前，请参见[与 Internet 通信](https://help.tableau.com/v0.0/server-linux/zh-cn/plan_network.htm)。

## 配置转发代理服务器

若要实现从 Tableau Server 到 Internet 的通信，请将 Tableau Server 部署在转发代理服务器后面。当 Tableau Server 需要访问 Internet 时，它不会将请求直接发送到 Internet，而是会将请求发送到转发代理，后者将会转发请求。转发代理可以帮助管理员针对负载平衡、阻止访问站点等任务管理外流到 Internet 的流量。

如果使用转发代理，您必须将网络内部运行 Tableau Server 的计算机配置为将流量发送到转发代理。Tableau Server 不支持直通式或手动代理身份验证。

如果您使用转发代理解决方案运行 OpenID 身份验证，则需要额外的配置。请参见[针对 OpenID Connect 配置 Tableau Server](https://help.tableau.com/v0.0/server-linux/zh-cn/openid_auth_server_config.htm#Configur)。

### 配置 Linux 版 Tableau Server 以使用转发代理

我们建议在安装过程中将 Tableau Server 配置为使用转发代理解决方案。具体而言，请在运行 `./initialize-tsm` 时配置 Tableau Server，如[安装和初始化 TSM](https://help.tableau.com/v0.0/server-linux/zh-cn/setup.htm)中所述。

以下过程介绍如何为 Linux 版 Tableau Server 创建转发代理配置文件。

该配置文件存储在以下目录中：

`~<unprivileged_user>/.config/systemd/tableau_server.conf.d`

默认情况下， Tableau Server 将创建非特权用户 `tableau`。因此，配置目录的默认路径为：

`~tableau/.config/systemd/tableau_server.conf.d`

本主题和下面的配置文件中的代理配置文件名称为 `20-proxy.conf`。您可以根据自己的约定命名此文件，但必须使用 .conf 扩展名。systemd 将依据文件名按词典顺序处理 `tableau_server.conf.d` 目录中存储的文件。

1. 运行 `tsm stop` 命令。
2. 以非特权用户身份启动会话。默认情况下，`tableau` 是 Tableau Server 在安装过程中创建的非特权用户。运行以下命令：
    
    `sudo su -l tableau`
3. 在 `tableau_server.conf.d` 目录中创建或打开 `20-proxy.conf` 文件。如果在安装过程中配置了转发代理， 则已创建 `20-proxy.conf` 文件。
    
    - 创建文件。运行以下命令：
        
        `touch ~tableau/.config/systemd/tableau_server.conf.d/20-proxy.conf`
    - 在文本编辑器中打开 `20-proxy.conf` 文件。
4. 将_代理配置文件内容_复制到文件中。如果要编辑现有文件，请注意不删除配置。_代理配置文件内容_包括有关如何设置转发代理配置的说明。编辑并保存文件后，转到步骤 5。

代理配置文件内容

```

# Always edit this file on Tableau Server as the unprivileged user. By default, tableau, is the unprivileged user created by Tableau Server during installation.
# Set environment variables http_proxy and https_proxy to point to your proxy host.
# For example, to set the proxy to example-host for ports 80 and 443, run the following commands:
#
http_proxy=http://example-host:80/
https_proxy=http://example-host:443/
#
# Take care to use 'http' when you specify the URL for the https_proxy environmental variable.  
# Do not specify the 'https' protocol for the value of  the https_proxy environmental variable.
#                   
# To bypass the proxy server, specify exceptions in the no_proxy variable. Use this variable if your proxy server does not route internal addresses. 
# You must also add exceptions to this proxy configuration to guarantee that all communications within a local Tableau Server cluster (if you have one now or will have one later) do not route to the proxy server. 
# Enter both the host name and the IP address for each computer. Additionally, include the cannonical host name (localhost) and IP address (127.0.0.1) for the local computer.
# For example, to specify exceptions for a three-node cluster:
#
no_proxy="localhost,127.0.0.1,hostname1,hostname2,hostname3,IP1,IP2,IP3"
#									
# Where "hostname1" is the actual hostname of node 1, and "IP1" is the actual IP address of node 1, etc.
```

6. 退出 Tableau shell。运行以下命令：
    
    `exit`
7. 重新启动 TSM 业务服务。运行以下脚本命令：
    
    `sudo /opt/tableau/tableau_server/packages/scripts.<version>/stop-administrative-services`
    
    `sudo /opt/tableau/tableau_server/packages/scripts.<version>/start-administrative-services`
8. 重新启动 TSM。
    
    `tsm restart`

## 服务器崩溃报告程序

如果您的组织使用代理服务器连接到 Internet，则必须配置 Tableau Server 的崩溃报告程序才能使用代理。即使您已将 Tableau Server 配置为使用代理，也必须单独配置服务器崩溃报告程序。若要为服务器崩溃报告程序配置代理，请参见[配置服务器崩溃报告程序](https://help.tableau.com/v0.0/server-linux/zh-cn/crashdata_server_config_keys.htm)。

## 反向代理和负载平衡器如何与 Tableau Server 配合工作

反向代理和负载平衡器是指从外部 (Internet) 客户端接收请求并将请求转发到 Tableau Server 的服务器。通过这些解决方案，将可通过 Internet 访问 Tableau Server，而不必向 Internet 暴露该特定 Tableau Server 的单独 IP 地址。它们还充当身份验证和直通设备，因此在公司外部人员可以访问的位置不会存储数据。这一要求对于需要遵循诸如 PCI、HIPAA 或 SOX 之类的各种隐私法规的组织可能很重要。

下图说明了当客户端向配置为使用反向代理和/或负载平衡器 (LB) 的 Tableau Server 发出请求时的通信路径。

![计算机、云和服务器之间的数据流图。](/tableau/next/zh-cn/server-linux/zh-cn/Img/everybody_client_access_reverse_proxy.PNG)

1. 外部客户端发起 Tableau Server 连接。此客户端使用为反向代理服务器/LB 配置的公共 URL，例如 `https://tableau.example.com`。（客户端不知道它在访问反向代理/LB。）
2. 反向代理反过来会将该请求映射至 Tableau Server 请求。在某些情况下，可以将反向代理配置为（使用 SSL/TLS）对客户端进行身份验证，以作为将请求传递给 Tableau Server 的前提条件。
3. Tableau Server 获取请求并将其响应发送到反向代理/LB。
4. 反向代理/LB 将内容发回给客户端。就客户端而言，它刚与 Tableau Server 进行了交互，并且无法得知通信是通过中间服务器进行的。

## TLS/SSL

根据您的网关方案，您应该考虑将反向代理和负载平衡服务器配置为对网络外部的任何流量使用 TLS/SSL。这有助于保护隐私、内容完整性和身份验证。除非您已经采取了其他安全措施来保护您的 Internet 网关与 Tableau Server 之间的流量，否则，也建议配置网关代理与 Tableau Server 之间的 SSL。您可以使用内部证书或自签名证书来对 Tableau 服务器和其他内部计算机之间的流量进行加密。

## 移动访问

Tableau Server 会向 Tableau Mobile 会话的所有 HTTP 响应中添加 X 标头。默认情况下，大多数代理解决方案将保留 X 标头。如果您的网关解决方案未保留 X 标头，则您需要配置代理服务器和负载平衡器以便为移动客户端会话的所有 HTTP 响应保留以下标头：`X-Tableau: Tableau Server`。

如果在网关处配置了身份验证，则代理服务器/LB 必须使用 HTTP 302 响应来响应 Tableau Mobile HTTP 请求。302 必须重定向到身份提供程序登录页面。要查看一个描述 302 身份验证序列的图表，请参见 Tableau 社区中的 [Tableau Mobile 身份验证序列](https://community.tableau.com/s/question/0D54T00000G54tDSAR/tableau-mobile-reverse-proxy-authentication-sequence)。

## 反向代理、负载平衡器和用户身份验证

Tableau Server 会始终验证用户的身份。这意味着，即使您在组织网关处对入站连接进行身份验证，Tableau Server 仍将验证用户的身份。

但是，并非所有客户端都支持使用网关解决方案进行用户身份验证：

- 对于支持的 Web 浏览器，您可以将 SAML、OpenID Connect、 Kerberos、Trusted Tickets 或手动身份验证与反向代理/LB 一起使用。
- Tableau Mobile 支持将 SAML 或手动身份验证与反向代理/LB 一起使用。iOS 版本的 Tableau Mobile 还支持将 Kerberos 与反向代理/LB 一起使用。上面的推荐方法同样适用。
- Tableau Prep 不支持使用反向代理或负载平衡器的身份验证。对于远程访问，请使用 VPN 解决方案，或将网关服务配置为将来自 Tableau Prep 的流量直接路由到 Tableau Server 进行身份验证。
- Tableau Desktop 支持使用反向代理进行身份验证，前提是身份验证模块在将流量路由到 Tableau Server 进行最终身份验证之前对反向代理执行预身份验证。有关详细信息，请参见 _Tableau Server 企业部署指南_的[第 5 部分 - 配置 Web 层](https://help.tableau.com/current/guides/enterprise-deployment/zh-cn/edg_part5.htm)和[配置具有独立网关的身份验证模块](https://help.tableau.com/v0.0/server-linux/zh-cn/server_tsig_configure_auth_mod.htm)。

如果您的组织使用 Active Directory 进行身份验证：

- 在将 Tableau Server 配置为使用 Kerberos 之前，必须针对反向代理配置 Tableau Server。有关详细信息，请参见[配置 Kerberos](https://help.tableau.com/v0.0/server-linux/zh-cn/config_kerberos.htm)。

## 将 Tableau Server 配置为使用反向代理服务器和/或负载平衡器

在配置 Tableau Server 之前，您需要收集有关代理服务器配置的以下信息。若要配置 Tableau Server，请使用 `tsm configuration set` 命令。您需要收集的信息与运行 `tsm` 时所需的选项对应。

大多数以下 tsm 选项也用于配置在负载平衡器后面运行的 Tableau Server 部署。有关详细信息，请参见[添加负载平衡器](https://help.tableau.com/v0.0/server-linux/zh-cn/distrib_lb.htm)。

<table class="simple-table"><colgroup><col style="width: 25%;"><col style="width: 50%;"><col style="width: 25%;"></colgroup><thead><tr><th>项</th><th>描述</th><th>对应的 <code>tsm configuration set</code> 选项</th></tr></thead><tbody><tr><td style="font-weight: normal;"><span style="font-weight: normal;">IP 地址</span> 或 <code>CNAME</code></td><td><p>对于此选项，您可以输入 IP 地址或 CNAME。</p><p>代理和负载平衡器服务器的一个或多个公共 IP 地址。IP 地址必须采用 IPv4 格式（例如 <code>203.0.113.0</code>），并且必须是静态 IP。</p><p>如果无法提供静态 IP 地址，或者如果您正在使用云代理或外部负载平衡器，则您可以指定客户端连接到 Tableau Server 时将使用的 CNAME（规范名称）DNS 值。必须在反向代理解决方案中配置此 CNAME 值以与 Tableau Server 通信。</p></td><td><code>gateway.trusted</code></td></tr><tr><td>FQDN</td><td>人员访问 Tableau Server 所使用的完全限定的域名，如 <code>tableau.example.com</code>。Tableau Server 不支持为此选项使用上下文开关。例如，不支持以下 URL：<code>example.com/tableau</code>.</td><td><code>gateway.public.host</code></td></tr><tr><td>非 FQDN</td><td>代理或 LB 服务器的任何子域名。在 <code>tableau.example.com</code> 这个示例中，子域名为 <code>tableau</code>。</td><td><code>gateway.trusted_hosts</code></td></tr><tr><td>别名</td><td>代理或 LB 服务器的任何公共备用名称。大多数情况下，会使用 CNAME 值指定别名。例如，代理服务器 <code>bigbox.example.com</code> 以及 CNAME 条目 <code>ftp.example.com</code> 和 <code>www.example.com</code>。</td><td><code>gateway.trusted_hosts</code></td></tr><tr><td>端口</td><td>从客户端到反向代理服务器的流量的端口号。</td><td><p><code>gateway.public.port</code></p></td></tr></tbody></table>

如果使用 Tableau Server 的分布式安装，则在群集中的初始节点上运行以下 `tsm` 命令。

1. 输入以下命令以设置客户端通过代理和/或 LB 服务器访问 Tableau Server 时将使用的 FQDN，其中 `name` 是 FQDN：
    
    `tsm configuration set -k gateway.public.host -v '_name'_`
    
    举例来说，如果通过在浏览器中输入 `https://tableau.example.com` 来访问 Tableau Server，请输入此命令：
    
    `tsm configuration set -k gateway.public.host -v 'tableau.example.com'`
2. 输入以下命令以设置代理和/或 LB 服务器的地址或 CNAME，其中 `server_address` 为 IPv4 地址或 CNAME 值：
    
    `tsm configuration set -k gateway.trusted -v '_server_ip_address'_`
    
    如果组织使用多个代理服务器和/或 LB 服务器，请输入多个 IPv4 地址，用逗号分隔这些地址。不支持 IP 范围。为了改善 Tableau Server 的启动和初始化，请最大程度地减少 `gateway.trusted` 的条目数。
3. 输入以下命令以为代理/LB 服务器指定备用名称，例如它的完全限定域名、任何非完全限定域名和任何别名。如果有多个名称，请用逗号将名称隔开。
    
    `tsm configuration set -k gateway.trusted_hosts -v '_name1_, _name2_, _name3'_`
    
    例如：
    
    `tsm configuration set -k gateway.trusted_hosts -v 'proxy1.example.com, proxy1, ftp.example.com, www.example.com'`
4. 如果代理服务器使用 SSL 与 Internet 通信，请运行以下命令，告知 Tableau 反向代理服务器正在使用端口 443，而不是端口 80：
    
    `tsm configuration set -k gateway.public.port -v 443`
    
    **注意**：如果代理服务器使用 SSL 与 Tableau Server 进行通信，则必须在 Tableau Server 上配置和启用 SSL。
5. 输入以下命令以提交配置更改：
    
    `tsm pending-changes apply`
    
    如果待定更改需要重新启动服务器，`pending-changes apply` 命令将显示一个提示，告知您将进行重新启动。即使服务器已停止，此提示也会显示，但在这种情况下不会重新启动。您可以使用 `--ignore-prompt` 选项隐藏提示，但这样做不会改变重新启动行为。如果更改不需要重新启动，则会在不提示的情况下应用更改。有关详细信息，请参见[tsm pending-changes apply](https://help.tableau.com/v0.0/server-linux/zh-cn/cli_pending-changes.htm#pending-changes-apply)。

## 将反向代理或负载平衡服务器配置为使用 Tableau Server

当客户端通过反向代理或负载平衡器访问 Tableau Server 时，必须要保留（或添加）特定消息标头。具体而言，必须在 `gateway.trusted` 和 `gateway.trusted_hosts` 设置中表示消息链中的所有服务器。

下图显示了一个单跳消息链的示例标头，在该消息链中，代理服务器直接与 Tableau Server 通信：

![该图表说明了数据从客户端通过代理流向 Tableau。](/tableau/next/zh-cn/server-linux/zh-cn/Img/everybody_client_access_config.png)

下图显示了一个多跳消息链的示例标头，在该消息链中，消息在连接到 Tableau Server 之前将穿过两个代理服务器：

![从客户端通过两个代理传递到服务器的标头图表。](/tableau/next/zh-cn/server-linux/zh-cn/Img/proxy_reverse_headers.png)

下表介绍了这些标头，以及这些标头如何与 Tableau Server 上的配置设置相关：

<table style="width: 100%;" class="simple-table"><colgroup><col style="width: 25%;"><col style="width: 50%;"><col style="width: 25%;"></colgroup><tbody><tr><td style="font-weight: bold;">标题</td><td><b>描述</b></td><td><b>相关的 Tableau Server 设置</b></td></tr><tr><td><code>REMOTE_ADDR</code> 和 <code>X-FORWARDED-FOR</code> (<code>XFF</code>)</td><td>Tableau Server 需要这些标头来确定请求来源的 IP 地址。<code>X-FORWARDED-FOR</code> 标头必须按连接进行的顺序将 IP 地址链提供给 Tableau Server。</td><td>您在 <code>gateway.trusted</code> 中设置的 IP 地址必须与 <code>REMOTE_ADDR</code> 中呈现的 IP 地址匹配。如果在 <code>gateway.trusted</code> 中发送了多个地址，则其中一个地址必须与 <code>REMOTE_ADDR</code> 中呈现的 IP 地址匹配。</td></tr><tr><td><code>HOST</code> 和 <code>X-FORWARDED&nbsp;HOST</code> (<code>XFH</code>)</td><td>这些标头用于在 Tableau Server 回复客户端时生成指向 Tableau Server 的绝对链接。<code>X-FORWARDED-HOST</code> 标头必须按连接进行的顺序将主机名提供给 Tableau Server。</td><td><code>X-FORWARDED-HOST</code> 标头中呈现的主机名必须包括在 <code>gateway.trusted_hosts</code> 中指定的主机名中。</td></tr><tr><td><code>X-FORWARDED-PROTO</code> (<code>XFP</code>)</td><td>如果为从客户端到代理的流量启用了 SSL，但没有为从代理到 Tableau Server 的流量启用，则必须提供标题。 <p>对于未沿着消息路由的每个跃点来维护 HTTP 或 HTTPS 的情况，<code> X-FORWARDED-PROTO</code> 标头很重要。例如，如果反向代理需要使用 SSL 来处理外部请求，但是未将反向代理与 Tableau Server 之间的通信配置为使用 SSL，则需要提供 <code>X-FORWARDED-PROTO</code> 标头。有些代理解决方案会自动添加 <code>X-FORWARDED-PROTO</code> 标头，而有些则不会。最后，根据您的代理解决方案，您可能必须配置端口转发以将请求从端口 443 转到端口 80。</p><p>相关知识库文章：<a href="https://kb.tableau.com/articles/issue/unable-to-sign-in-and-invalid-username-or-password-error-with-saml-after-upgrading?lang=zh-cn" target="_blank">升级后 SAML 出现“无法登录”以及“用户名或密码无效”错误</a>。</p></td><td><p>必须在相应的参数中指定反向代理上的端口配置（来自客户端的入站连接以及到 Tableau Server 的出站连接）：<code>gateway.public.port</code>，这是用于连接到代理的端口客户端。</p><p>如果代理服务器使用 SSL 与 Tableau Server 进行通信，则必须在 Tableau Server 上配置和启用 SSL。</p></td></tr></tbody></table>

## 验证反向代理和负载均衡器配置

若要验证网关到Tableau Server的配置，请使用 Tableau Server Web 制作或 Tableau Desktop 发布工作簿和数据源。如果使用 Web 浏览器通过 Internet 连接到 Tableau Server，请验证您是否在使用[推荐的浏览器](https://www.tableau.com/zh-cn/products/techspecs#server)。发布和查看使用现有数据源的工作簿以及已发布的数据源。使用下面的链接来熟悉以最终用户身份连接 Tableau Server 的操作。

<table style="width: 100%;" class="simple-table"><colgroup><col style="width: 65%;"><col style="width: 35%;"></colgroup><tbody><tr><th>任务</th><th>文档</th></tr><tr><td>Web 制作概述。</td><td><a href="https://help.tableau.com/current/pro/desktop/zh-cn/web_author_home.htm" target="_blank">在 Web 上使用 Tableau</a></td></tr><tr><td>从 <span class="mc-variable Variables.TabsProductDesktop variable">Tableau Desktop</span> 或 Web 浏览器登录到 Tableau Server。</td><td><a href="https://help.tableau.com/current/pro/online/windows/zh-cn/sign_in_server.htm" target="_blank">登录 Tableau Server 或 Tableau Online</a></td></tr><tr><td>将工作簿发布到 Tableau Server。</td><td><a href="https://help.tableau.com/current/pro/desktop/zh-cn/publish_workbooks_howto.htm" target="_blank">发布工作簿</a></td></tr><tr><td>发布数据源。</td><td><a href="https://help.tableau.com/current/pro/desktop/zh-cn/publish_datasources.htm" target="_blank">发布数据源</a></td></tr><tr><td>从 Tableau Server 中打开工作簿。</td><td><a href="https://help.tableau.com/current/pro/desktop/zh-cn/environ_workbooksandsheets_workbooks.htm#open-from-server" target="_blank">从服务器打开工作簿</a></td></tr><tr><td>注销 Server（使用 Desktop）。</td><td><a href="https://help.tableau.com/current/pro/online/windows/zh-cn/sign_in_server.htm" target="_blank">登录 Tableau Server 或 Tableau Online</a></td></tr><tr><td>通过 Web 浏览器下载工作簿。</td><td><a href="https://help.tableau.com/current/pro/desktop/zh-cn/export.htm" target="_blank">下载工作簿</a></td></tr><tr><td>检查以确保 tabcmd（从非服务器客户端中）正常工作。</td><td><a href="https://help.tableau.com/current/server/zh-cn/tabcmd.htm">tabcmd</a></td></tr></tbody></table>

## 相关主题

- [Tableau Desktop Internet 访问要求](https://help.tableau.com/current/desktopdeploy/zh-cn/desktop_deploy_proxy.htm)
- [添加负载平衡器](https://help.tableau.com/v0.0/server-linux/zh-cn/distrib_lb.htm)