# Nginx Proxy in front of Companion

**URL:** <https://community.transloadit.com/t/nginx-proxy-in-front-of-companion/14746>\
**Category:** Uppy\
**Created:** [September 17, 2018, 3:32pm UTC](https://community.transloadit.com/t/nginx-proxy-in-front-of-companion/14746 "2018-09-17T15:32:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Craytor](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/craytor/32/74_2.png) [@Craytor](https://community.transloadit.com/u/Craytor)\
**Post date:** [September 17, 2018, 3:32pm UTC](https://community.transloadit.com/t/nginx-proxy-in-front-of-companion/14746/1 "2018-09-17T15:32:52Z")

</div>

Hey all,

I am trying to setup Companion, but am having issues with my integration.

I have an nginx reverse proxy sitting in front of Companion stand-alone so that I can provide valid https. So far everything works (as in connecting to oauth service such as dropbox), but I cannot actually initialize the upload. When I try to do so, in the browser console I get the following error:

 ![53%20AM](https://canada1.discourse-cdn.com/flex032/uploads/transloadit/original/1X/f1d08cae4b93844632dfc93790bfab4e2a76439c.png).

However, if I upload using the “My Device” option which uses TUS, there is no issues. I have TUS setup the same way as I’m trying to set up Companion (behind a nignx reverse proxy).

Here is my nginx reverse proxy config (just the location block):

```auto
    location / {
        # Forward incoming requests to local companion instance
        proxy_pass http://localhost:3020;

        # Disable request and response buffering
        proxy_request_buffering off;
        proxy_buffering off;
        proxy_http_version 1.1;

        # Add X-Forwarded-* headers
        proxy_set_header X-Forwarded-Host $hostname;
        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        client_max_body_size 0;

    }

```

Thanks!

---

<div class="post-metadata">

**Author:** ![kvz](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/kvz/32/606_2.png) [@kvz](https://community.transloadit.com/u/kvz)\
**Post date:** [September 17, 2018, 3:37pm UTC](https://community.transloadit.com/t/nginx-proxy-in-front-of-companion/14746/2 "2018-09-17T15:37:14Z")

</div>

Hi Tyler, do you mind sharing the full Nginx conf? It seems to do a 301 redirect. Looking at the full config might help us understand why that is

---

<div class="post-metadata">

**Author:** ![Craytor](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/craytor/32/74_2.png) [@Craytor](https://community.transloadit.com/u/Craytor)\
**Post date:** [September 17, 2018, 3:39pm UTC](https://community.transloadit.com/t/nginx-proxy-in-front-of-companion/14746/3 "2018-09-17T15:39:18Z")

</div>

Sure thing.

```auto
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/upload-companion.livestormsvideo.com/before/*;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name upload-companion.livestormsvideo.com;
    root /home/forge/upload-companion.livestormsvideo.com/;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/upload-companion.livestormsvideo.com/412376/server.crt;
    ssl_certificate_key /etc/nginx/ssl/upload-companion.livestormsvideo.com/412376/server.key;

    ssl_protocols TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/upload-companion.livestormsvideo.com/server/*;

    location / {
        # Forward incoming requests to local companion instance
        proxy_pass http://localhost:3020;

        # Disable request and response buffering
        proxy_request_buffering off;
        proxy_buffering off;
        proxy_http_version 1.1;

        # Add X-Forwarded-* headers
        proxy_set_header X-Forwarded-Host $hostname;
        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        client_max_body_size 0;

    }
    
}

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/upload-companion.livestormsvideo.com/after/*;

```

Thanks!

---

<div class="post-metadata">

**Author:** ![kvz](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/kvz/32/606_2.png) [@kvz](https://community.transloadit.com/u/kvz)\
**Post date:** [September 17, 2018, 3:42pm UTC](https://community.transloadit.com/t/nginx-proxy-in-front-of-companion/14746/4 "2018-09-17T15:42:58Z")

</div>

What about your includes? I’m mostly looking for a bit that e.g. redirects to use trailing slashes. That could throw a 301 that we’re not expecting, maybe.

I’m also wondering what happens when you target Companion directly, does it work then? Or also throws the 301?

---

<div class="post-metadata">

**Author:** ![Craytor](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/craytor/32/74_2.png) [@Craytor](https://community.transloadit.com/u/Craytor)\
**Post date:** [September 17, 2018, 3:58pm UTC](https://community.transloadit.com/t/nginx-proxy-in-front-of-companion/14746/5 "2018-09-17T15:58:16Z")

</div>

I just went through and found nothing about trailing slashes.

Also, I’m not sure how I would target Companion directly as Dropbox only allows https as redirects.

---

<div class="post-metadata">

**Author:** ![Craytor](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/craytor/32/74_2.png) [@Craytor](https://community.transloadit.com/u/Craytor)\
**Post date:** [September 17, 2018, 6:09pm UTC](https://community.transloadit.com/t/nginx-proxy-in-front-of-companion/14746/6 "2018-09-17T18:09:24Z")

</div>

Ok, I tried it without https and nginx proxy and it works fine. Is there anyway to get it to work with valid https?

---

<div class="post-metadata">

**Author:** ![Craytor](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/craytor/32/74_2.png) [@Craytor](https://community.transloadit.com/u/Craytor)\
**Post date:** [September 17, 2018, 6:36pm UTC](https://community.transloadit.com/t/nginx-proxy-in-front-of-companion/14746/7 "2018-09-17T18:36:03Z")

</div>

Ok, I went ahead and spun up a server and only installed nginx and done the reverse proxy that way and everything works fine. I’m thinking it’s something conflicting on the main box.

---

<div class="post-metadata">

**Author:** ![kvz](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/kvz/32/606_2.png) [@kvz](https://community.transloadit.com/u/kvz)\
**Post date:** [September 18, 2018, 7:02am UTC](https://community.transloadit.com/t/nginx-proxy-in-front-of-companion/14746/8 "2018-09-18T07:02:59Z")

</div>

Is there maybe also HAProxy installed or is it behind a service like ALB or CloudFlare which can do 301 redirects on your behalf? If not and it’s really nginx, enabling the debug log on Nginx will reveal why it is redirecting.
