How to use NGINX to proxy requests for Confluence
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Atlassian applications allow the use of reverse-proxies within our products, however Atlassian Support does not provide assistance for configuring them. Consequently, Atlassian can not guarantee providing any support for them.
If assistance with configuration is required, please raise a question on Atlassian Community.
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 with Collaborative Editing enabled, you'll need a version of NGINX that supports WebSockets (1.3 or later).
Solution
Configuring Tomcat
In this example, we'll set up Confluence to be accessed at the address http://www.example.com/confluence (on standard HTTP port 80), while Confluence itself listens on port 8090 with context path /confluence.
For Confluence 6.0 or later we also need to include Synchrony, the service that powers collaborative editing, which listens on port 8091 with the context path /synchrony.
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:
<Context path="" docBase="../confluence" debug="0" reloadable="false">
and change it to:
<Context path="/confluence" docBase="../confluence" debug="0" reloadable="false">
Restart Confluence, and check you can access it at http://www.example.com: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:
<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"/>
And append the last line:
<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"
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+ with Collaborative Editing enabled:
server {
listen 80;
server_name www.example.com;
location /confluence {
client_max_body_size 100m;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8090/confluence;
}
location /synchrony {
client_max_body_size 100m;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8091/synchrony;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
For Confluence 5.10 and earlier:
server {
listen 80;
server_name www.example.com;
location /confluence {
client_max_body_size 100m;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8090/confluence;
}
}
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.
For Confluence 5.10 and earlier if large pages are not loading completely, you can try to disable proxy_request_buffering & proxy_buffering in the NGINX config as below (These directives are enabled by default).
proxy_request_buffering off; proxy_buffering off;
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.
If you do not have a context path for Confluence, ensure there is no trailing slash '
/
' symbol at the URL in theproxy_pass
line. Otherwise, you might run into this issue. For example:server { listen 80; server_name www.example.com; location / { proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://localhost:8090; } }
- If you experience 413 Request Entity Too Large errors, make sure that the client_max_body_size in the
/confluence
location block matches Confluence's maximum attachment size. You may also need to increase the client_max_body_size in the/synchrony
location block if you experience errors when editing large pages.