Purpose
This page describes a possible way to use NGINX to proxy requests for Confluence running in a standard Tomcat container. You can find additional documentation that explains how to use Apache mod_proxy for the very same purpose. For Confluence 6.0 or later you’ll need a version of NGINX that supports WebSockets (1.3 or later).
Solution
Configuring Tomcat
Set context path
Set your Confluence application path (the part after hostname and port) in Tomcat. Edit <CONFLUENCE-INSTALL>/conf/server.xml
, locate the “Context” definition:
1 |
<span class="cm-tag cm-bracket"><</span><span class="cm-tag">Context</span> <span class="cm-attribute">path</span>=<span class="cm-string" style="color: #aa2222;">""</span> <span class="cm-attribute">docBase</span>=<span class="cm-string" style="color: #aa2222;">"../confluence"</span> <span class="cm-attribute">debug</span>=<span class="cm-string" style="color: #aa2222;">"0"</span> <span class="cm-attribute">reloadable</span>=<span class="cm-string" style="color: #aa2222;">"false"</span><span class="cm-tag cm-bracket">></span> |
and change it to:
1 |
<span class="cm-tag cm-bracket"><</span><span class="cm-tag">Context</span> <span class="cm-attribute">path</span>=<span class="cm-string" style="color: #aa2222;">"/confluence"</span> <span class="cm-attribute">docBase</span>=<span class="cm-string" style="color: #aa2222;">"../confluence"</span> <span class="cm-attribute">debug</span>=<span class="cm-string" style="color: #aa2222;">"0"</span> <span class="cm-attribute">reloadable</span>=<span class="cm-string" style="color: #aa2222;">"false"</span><span class="cm-tag cm-bracket">></span> |
Restart Confluence, and check you can access it at http://example:8090/confluence
Set the URL for redirection
Next, set the URL for redirection. In the same <CONFLUENCE-INSTALL>/conf/server.xml
file, locate this code segment:
1 |
<Connector port="8090" connectionTimeout="20000" redirectPort="8443" |
1 |
maxThreads="48" minSpareThreads="10" |
1 |
enableLookups="false" acceptCount="10" debug="0" URIEncoding="UTF-8" |
1 |
protocol="org.apache.coyote.http11.Http11NioProtocol"/> |
And append the last line:
1 |
<Connector port="8090" connectionTimeout="20000" redirectPort="8443" |
1 |
maxThreads="48" minSpareThreads="10" |
1 |
enableLookups="false" acceptCount="10" debug="0" URIEncoding="UTF-8" |
1 |
protocol="org.apache.coyote.http11.Http11NioProtocol" |
1 |
proxyName="www.example.com" proxyPort="80"/> |
Configure NGINX
You will need to specify a listening server in NGINX, as in the example below. Add the following to your NGINX configuration:
For Confluence 6.0 and later:
1 |
server { |
1 |
listen www.example.com:80; |
1 |
server_name www.example.com; |
1 |
location /confluence { |
1 |
proxy_set_header X-Forwarded-Host $host; |
1 |
proxy_set_header X-Forwarded-Server $host; |
1 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
1 |
proxy_pass http://localhost:8090/confluence; |
1 |
} |
1 |
location /synchrony { |
1 |
proxy_set_header X-Forwarded-Host $host; |
1 |
proxy_set_header X-Forwarded-Server $host; |
1 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
1 |
proxy_pass http://localhost:8091/synchrony; |
1 |
proxy_http_version 1.1; |
1 |
proxy_set_header Upgrade $http_upgrade; |
1 |
proxy_set_header Connection "Upgrade"; |
1 |
} |
1 |
} |
For Confluence 5.10 and earlier
1 |
server { |
1 |
listen www.example.com:80; |
1 |
server_name www.example.com; |
1 |
location /confluence { |
1 |
proxy_set_header X-Forwarded-Host $host; |
1 |
proxy_set_header X-Forwarded-Server $host; |
1 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
1 |
proxy_pass http://localhost:8090/confluence; |
1 |
} |
1 |
} |
If the NGINX proxy is not listening to the same IP that the hostname resolves, please use the IP address that the proxy is listening to instead of the application hostname.
Set base URL
For normal operation of Confluence you will also need to set the base URL accordingly. In this example the base URL would be set to http://www.example.com/confluence.
Notes
- For the settings above to take effect you need to restart both Confluence (including Synchrony) and NGINX.
- If you encounter problems with input validation, it might be caused by the gzip compression enabled in reverse proxying. Such an issue is described in the Create Space button inactive in Add Space dialog article.