# Nginx configuration for reverse proxy

**URL:** <https://help.nextcloud.com/t/nginx-configuration-for-reverse-proxy/23777>\
**Category:** 📄 Office\
**Tags:** onlyoffice\
**Created:** [November 20, 2017, 12:55pm UTC](https://help.nextcloud.com/t/nginx-configuration-for-reverse-proxy/23777 "2017-11-20T12:55:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Abela](https://help.nextcloud.com/user_avatar/help.nextcloud.com/chris_abela/32/14657_2.png) [@Chris\_Abela](https://help.nextcloud.com/u/Chris_Abela)\
**Post date:** [November 20, 2017, 12:55pm UTC](https://help.nextcloud.com/t/nginx-configuration-for-reverse-proxy/23777/1 "2017-11-20T12:55:34Z")

</div>

I managed to place my nextcloud cloud server and onyoffice document servers behind another reverse proxy server running nginx. I have zero experience on nginx and I am not entirely satisfied with my set-up.

Right now the nextcloud server is running under the /nextloud ROOT directory and I can reach it under [http://example.org/nextcloud/](http://example.org/nextcloud/). That seems good enough, but my document server is accessible under [http://example.org/](http://example.org/) which not practical as I would like to set-up another service at that address.

This is my current nginx.conf:

> worker\_processes 4; # Default 1  
> error\_log logs/error.log;  
> error\_log logs/error.log notice;  
> error\_log logs/error.log info;
> 
> ```
> events {
> worker_connections 512; # Default 1024
> }
> 
> http {
> include mime.types;
> default_type application/octet-stream;
> 
> keepalive_timeout 65;
> 
> ## Compression
> gzip on;
> gzip_buffers 16 8k;
> gzip_comp_level 9;
> gzip_http_version 1.1;
> gzip_min_length 10;
> gzip_types text/plain text/css application/x-javascript text/xml;
> gzip_vary on;
> gzip_static on; #Needs compilation with gzip_static support
> gzip_proxied any;
> gzip_disable "MSIE [1-6]\.";
> 
> ## Server configuration 
> server {
> listen 80;
> server_name example.org;
> server_name_in_redirect off;
> access_log logs/access.log;
> client_body_buffer_size 1m;
> proxy_buffering on;
> proxy_buffer_size 4k;
> proxy_buffers 8 32k;
> 
> ## proxy the PHP scripts to Apache listening on 127.0.0.1:80
> location /nextcloud {
> 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://cloudserver:80;
> }
> #location /doc {
> 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_redirect off;
> proxy_pass http://documentserver:80/;
> }
> }
> 
> ```
> 
> }

As you may see from the commented line, I tried to redirect the document server to [http://example.org/doc/](http://example.org/doc/) via

> location /doc

but I am getting a 404 Error. Does anyone know how to redirect the document server to another ROOT?

.

---

<div class="post-metadata">

**Author:** ![karthikjoe](https://help.nextcloud.com/letter_avatar/karthikjoe/32/6_22734026db12803ebb3e059622ac3534.png) [@karthikjoe](https://help.nextcloud.com/u/karthikjoe)\
**Post date:** [November 20, 2017, 2:32pm UTC](https://help.nextcloud.com/t/nginx-configuration-for-reverse-proxy/23777/2 "2017-11-20T14:32:24Z")

</div>

Try this on your nextcloud installed machine…  
To give Nginx user (www-data) write permission

sudo chown www-data:www-data /usr/share/nginx/nextcloud/ -R

---

<div class="post-metadata">

**Author:** ![Chris\_Abela](https://help.nextcloud.com/user_avatar/help.nextcloud.com/chris_abela/32/14657_2.png) [@Chris\_Abela](https://help.nextcloud.com/u/Chris_Abela)\
**Post date:** [November 21, 2017, 8:23pm UTC](https://help.nextcloud.com/t/nginx-configuration-for-reverse-proxy/23777/3 "2017-11-21T20:23:43Z")

</div>

I suppose that I did not explain my question as much as I should have.

1. I installed NextCloud on a Slackware Linux Server, while I think that you are referring to a Debian/Ubuntu Apache installation. On Slack, NC Server installation is very easy and fool-proof because it is supported by the awesome the [https://slackbuilds.org/](https://slackbuilds.org/) community.

2. My NextCloud server works fine. My concern is only that I failed to redirect my OnlyOffice Document ROOT directory (on a another server - running on Debian) from [http://example.org](http://example.org) to [http://example.org/doc](http://example.org/doc). This is minor inconvenience, but my Document Server works fine and my NC integration also works fine.

3. I have an Nginx Slackware Reverse Proxy Server (a third server), and despite that I have no experience with nginx, it’s working fine. I should be able to redirect the Debian OnlyOffice Document Server to [http://example.org/doc](http://example.org/doc) but I have not managed yet.

Thanks for your hint anyway. Naturally my real URL is not [http://example.org](http://example.org).

---

<div class="post-metadata">

**Author:** ![Chris\_Abela](https://help.nextcloud.com/user_avatar/help.nextcloud.com/chris_abela/32/14657_2.png) [@Chris\_Abela](https://help.nextcloud.com/u/Chris_Abela)\
**Post date:** [November 23, 2017, 7:02am UTC](https://help.nextcloud.com/t/nginx-configuration-for-reverse-proxy/23777/4 "2017-11-23T07:02:46Z")

</div>

For the sake of any reader that is deploying a separate reverse proxy server, this is my production nginx.conf file for HTTPS that works for me:

worker\_processes 4; # Default 1  
error\_log logs/error.log;  
error\_log logs/error.log notice;  
error\_log logs/error.log info;

```
     events {
         worker_connections 512; # Default 1024
     }

     http {
             include mime.types;
             default_type application/octet-stream;

             keepalive_timeout 65;

             ## Compression
             gzip on;
             gzip_buffers 16 8k;
             gzip_comp_level 9;
             gzip_http_version 1.1;
             gzip_min_length 10;
             gzip_types text/plain text/css application/x-javascript text/xml;
             gzip_vary on;
             gzip_static on; #Needs compilation with gzip_static support
             gzip_proxied any;
             gzip_disable "MSIE [1-6]\.";

     ## Server configuration 
             server {
                     listen 443 ssl;
                     server_name example.org
                     ssl on;
                     ssl_certificate /root/fullchain.pem;
                     ssl_certificate_key /root/privkey.pem;
                     server_name_in_redirect off;
                     access_log logs/access.log;
                     # A suitable client_max_body_size has to be set or you will get errors
                     client_max_body_size 10G ;

     ## proxy the PHP scripts to Apache listening on 127.0.0.1:80
         location /nextcloud {
         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_buffering off;
         proxy_pass https://cloudserver:443;
         }
         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_buffering off;
         proxy_pass https://documentserver:443/;
         }
     }

```

}

---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 2, 2024, 3:24pm UTC](https://help.nextcloud.com/t/nginx-configuration-for-reverse-proxy/23777/5 "2024-12-02T15:24:49Z")

</div>



---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 4, 2024, 2:11pm UTC](https://help.nextcloud.com/t/nginx-configuration-for-reverse-proxy/23777/6 "2024-12-04T14:11:30Z")

</div>


