How to configure reverse proxy for Nextcloud and ONLYOFFICE editors

28 January 2020By Ivan

Hi everyone!

Most of the ways to integrate ONLYOFFICE with Nextcloud are described in our API documentation, but some cases our users deal with in real life can be quite tricky. In this post, we’ll show you how to configure a proxy server for Nextcloud and ONLYOFFICE if all the three are installed on various servers.

In our case, there are three different machines with:

  • nginx – http://nginx,
  • Nextcloud – http://nextcloud,
  • ONLYOFFICE editors – http://onlyoffice.

Everything was installed using Docker and port 80.

We need to:

  • customize nginx so that a request on http://nginx would open Nextcloud,
  • customize Nextcloud to work with document editors available on http://nginx/editors/.

Let’s do it following this 3-step plan.

Step 1. Setting up a proxy for Nextcloud

To proxy Nextcloud via nginx, change nginx settings and add its address to Nextcloud trusted domains list. More on trusted domains can be found in the documentation.

The needed settings are located in the nginx container at /etc/nginx/conf.d/default.conf. Make this file look like:


server {
        listen 80;
        location / {
            proxy_pass_header   Server;
            proxy_pass          http://nextcloud/;

Pay attention to the slash at the end of the prox_pass path.

Refresh the nginx settings with:

service nginx reload

Now add http://nginx domain. Open the configuration in Nextcloud container at /var/www/html/config/config.php. Find or add trusted_domain section there and add nginx address. After all the changes are effective, this part of the configuration will look like:

‘trusted_domain’ => (0 => ‘nextcloud’, 1 => ‘nginx’
Step 2. Setting up a proxy for document editors

Open again default.conf on the nginx server and add one more location:

location /editors/ {
            proxy_pass http://onlyoffice/;

But that won’t be enough for editors to run. By default, the document editor generates links to resources using the address that comes in a request. So far as the editor is not connected to the proxy server, it will generate links irrespective of the virtual path (e.g. http://nginx/apps/files/). This is not correct as the /apps/files/ are located on the http://onlyoffice/ server.

To fix this, in the request header, you need to indicate the path for generating the links with the ‘X-Forwarded-Host’ header.

Let’s add the following code at the beginning of the configuration file:

proxy_set_header X-Forwarded-Host $http_host/editors;

Two more important headers are Upgrade and Connection. They allow using websocket protocol to effectively run ONLYOFFICE.

The resulting default.conf file will look the following way:

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Forwarded-Host $http_host/editors;
server {
        listen 80;
        location / {
            proxy_pass_header Server;
            proxy_pass http://nextcloud/;
        location /editors/ {
            proxy_pass http://onlyoffice/;
Step 3. Installing ONLYOFFICE-Nextcloud connector

Use our ready connector to link ONLYOFFICE and Nextcloud instances to each other. The connector is available on GitHub, but the easiest way is to install it from Nextcloud app store.

After installation, you will see a new option in the settings menu. There, you’ll need to specify the address of ONLYOFFICE editors – http://nginx/editors/.

Useful links

Download the latest version of the ONLYOFFICE connector for Nextcloud from the Nextcloud App Store.

Get ONLYOFFICE online editors for your Nextcloud -> Fill in this form or Download the free version.

Install ONLYOFFICE-Nextcloud combo all at once using Docker Compose.

Find useful tips on ONLYOFFICE-Nextcloud integration in this beginner’s guide, or watch the replay of our webinar.

If you have any questions, tweet us at @only_office. Your feedback is much appreciated!