Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

中文标题【使用 Apache 和 mod_proxy】

Atlassian 应用允许用户使用反向代理,但是 Atlassian 并不会为这个功能的配置提供支持。因此,Atlassian 也不能保证能够为这些配置提供任何支持

如果你在配置上有任何需求,请参考 Atlassian Answers 中的内容来获取帮助。

这个页面描述了一个使用 Apache HTTP Server 2.4 来方向代理标准的 Tomcat 容器的方法。你也可以在 NGINX 中找到类似的配置方法。

你可能在下面的情况中需要使用这个配置:

  • 你已经有一个存在的 Apache 网站,同时还希望添加 Confluence 到你已经存在的网站中(例如,http://www.example.com/confluence)。
  • 你已经有多个 Java 的应用了,每一个应用都运行在自己的服务器上,并且使用不同的端口在运行,例如,http://example:8090/confluence 和 http://example:8080/jira 同时你希望你的这个 2 个应用都能运行在常用的 HTTP  (80)端口(例如,http://www.example.com/confluence 和 http://www.example.com/jira)。每一个应用都能够被独立的启动,管理和编辑。

备注: 这个页面的文档是有关 Apache 的配置而不是 Confluence 的配置。Atlassian 将会为你在 Confluence 中的配置提供支持,但是我们不能保证能够帮你解决所有有关 Apache 配置的时候遇到的问题。请意识到,这个页面中的内容只是为配置向你提供相关的的信息,如果参考这个页面配置产生的任何问题,后果自负。

本页中的内容:

基本配置

在这些示例中,我们使用下面的信息:

http://www.example.com/confluence - 你计划使用的 URL

http://example:8090/ - Confluence 当前安装的主机名和端口

http://example:8091/ - Synchrony 当前安装的主机名和端口,这个服务被用来提供默认的协同编辑服务

/confluence - 这个是有关你 Confluence 计划使用的上下文(在主机名和端口的后面)

/synchrony - Synchrony 使用的上下文路径,这个提供了协同编辑服务

你需要将上面的 URL 替换成你自己的 URL。

1 设置上下文路径

(warning) 如果你不需要使用上下文来访问 Confluence,例如你希望使用 www.example.com  来访问这个,你可以跳过这部分的内容。

设置你 Tomcat 中 Confluence 上下文的路径(在主机名和端口的后面)。在这个示例中,上下文路径被配置为 /confluence。

编辑 <installation-directory>conf/server.xml,找到"Context" 的定义:

<Context path="" docBase="../confluence" debug="0" reloadable="true">

然后修改为:

<Context path="/confluence" docBase="../confluence" debug="0" reloadable="true">

在这个示例中,我们已经使用了 /confluence 为上下文的路径。请注意,你不能使用 /resources 为你的上下文路径,这是因为这个上下文的路径在 Confluence 中被用来定义资源,如果你使用这个配置的话,将会在 Confluence 中导致问题。

重启 Confluence,然后你可以尝试使用 http://example:8090/confluence 进行访问,并确保你能正确访问。

2 设置 URL 重定向

下一步,设置 URL 重定向。在 <installation-directory>conf/server.xml 文件中,使用示例的连接器为你的起始点。

注释掉默认的连接器(针对不使用代理的访问)。

 Show me how to do this...

In XML a comment starts with  <!-- and ends with -->, and is used to make sure only the relevant portions of the file are read by the application.

Add <!-- and --> around the default connector. It should now look like this.

<!--
========================================================
DEFAULT - Direct connector with no proxy, for unproxied HTTP access to Confluence.
========================================================
-->
<!--
<Connector port="8090" connectionTimeout="20000" redirectPort="8443"
   maxThreads="48" minSpareThreads="10"
   enableLookups="false" acceptCount="10" debug="0" URIEncoding="UTF-8"
   protocol="org.apache.coyote.http11.Http11NioProtocol"/>
-->

Uncomment the connector listed under the HTTP - Proxying Confluence via Apache or Nginx over HTTP heading.   

 Show me how to do this...

To uncomment a section, remove the <!-- and --> surrounding the connector.

Here's an example showing the default connector commented out, and the HTTP connector uncommented. The headings remain commented out.

<!--
========================================================
DEFAULT - Direct connector with no proxy, for unproxied HTTP access to Confluence.
========================================================
-->
<!--
<Connector port="8090" connectionTimeout="20000" redirectPort="8443"
   maxThreads="48" minSpareThreads="10"
   enableLookups="false" acceptCount="10" debug="0" URIEncoding="UTF-8"
   protocol="org.apache.coyote.http11.Http11NioProtocol"/>
-->
<!--
========================================================
HTTP - Proxying Confluence via Apache or Nginx over HTTP
========================================================
-->
<Connector port="8090" connectionTimeout="20000" redirectPort="8443"
   maxThreads="48" minSpareThreads="10"
   enableLookups="false" acceptCount="10" debug="0"URIEncoding="UTF-8"
   protocol="org.apache.coyote.http11.Http11NioProtocol"
   scheme="http" proxyName="<subdomain>.<domain>.com" proxyPort="80"/>

Insert your proxyName and proxyPort as shown in the last line below:

<Connector port="8090" connectionTimeout="20000" redirectPort="8443"
   maxThreads="48" minSpareThreads="10"
   enableLookups="false" acceptCount="10" debug="0" URIEncoding="UTF-8"
   protocol="org.apache.coyote.http11.Http11NioProtocol"
   scheme="http" proxyName="www.example.com" proxyPort="80"/>

If you plan to enable HTTPS, use the connector under HTTPS - Proxying Confluence via Apache or Nginx over HTTPS


3 配置 mod_proxy

Use one of the examples below to edit your Apache http.conf file to proxy requests to the application server.

(warning) You will need to enable the following required Apache modules if they are not already enabled:

  • mod_proxy
  • mod_proxy_http
  • proxy_wstunnel 
  • mod_rewrite

(proxy_wstunnel and mod_rewrite are new requirements in Confluence 6.0)

The format of the http.conf file, and location of the modules may differ on your operating system. We recommend Windows users specify the absolute path to the module files.

Example 1: Configuration with context path

Use this example if you set a context path in step 1, and will access Confluence with a context path like this http://www.example.com/confluence.  

In this example, users will connect to Synchrony, which is required for collaborative editing, directly via WebSockets. 

(warning) The order of directives in the config is important. 

Apache HTTP server 2.4
# Put this after the other LoadModule directives
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule proxy_wstunnel_module /usr/lib/apache2/modules/mod_proxy_wstunnel.so
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

# Put this in the main section of your configuration (or virtual host, if using Apache virtual hosts)
ProxyRequests Off
ProxyPreserveHost On

<Proxy *>
    Require all granted
</Proxy>

ProxyPass /synchrony http://<domain>:8091/synchrony
<Location /synchrony>
    Require all granted
    RewriteEngine on
    RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
    RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
    RewriteRule .* ws://<domain>:8091%{REQUEST_URI} [P]
</Location>
 
ProxyPass /confluence http://<domain>:8090/confluence
ProxyPassReverse /confluence http://<domain>:8090/confluence

<Location /confluence>
    Require all granted
</Location>

Note: It's not possible to use Apache HTTP Server 2.2 with Confluence 6.0 or later. If you plan to use SSL, you will need version 2.4.10 or later. 

Example 2: Configuration without context path 

Use this example if you skipped step 1, and will access Confluence without a context path like this http://www.example.com.

As in the previous example, users will connect to Synchrony, which is required for collaborative editing, directly via WebSockets. 

(warning) The order of directives in the config is important. 

Apache HTTP server 2.4
# Put this after the other LoadModule directives
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule proxy_wstunnel_module /usr/lib/apache2/modules/mod_proxy_wstunnel.so
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

# Put this in the main section of your configuration (or virtual host, if using Apache virtual hosts)
 
  ProxyRequests Off
  ProxyPreserveHost On
    
  RewriteEngine On
  RewriteCond %{REQUEST_URI} !^/synchrony
  RewriteRule ^/(.*) http://<domain>:8090/$1 [P]

  <Proxy *>
      Require all granted
  </Proxy>

  ProxyPass /synchrony http://<domain>:8091/synchrony

  <Location /synchrony>
      Require all granted
      RewriteEngine on
      RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
      RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
      RewriteRule .* ws://<domain>:8091%{REQUEST_URI} [P]
  </Location>

  ProxyPass / http://<domain>:8090
  ProxyPassReverse / http://<domain>:8090
   
  <Location />
      Require all granted
  </Location>

Note: It's not possible to use Apache HTTP Server 2.2 with Confluence 6.0 or later. If you plan to use SSL, you will need version 2.4.10 or later. 

4 重启 Apache

This is needed to pick up on the new configuration. To restart Apache, run the following command:

sudo apachectl graceful

5 禁用 HTTP 压缩

Having compression run on both the proxy and Tomcat can cause problems integrating with other Atlassian applications, such as Jira. Please disable HTTP compression as per our Using Apache with mod_proxy docs.

6 修改 Confluence 基础 URL

The last stage is to set the Base URL to the address you're using within the proxy, for example http://www.example.com/confluence.

添加 SSL

If you plan to enable HTTPS, see Using Apache with mod_proxy, and make sure you choose the HTTPS sample connector. 

更多信息

  • No labels