# Enable CORS for NextCloud

**URL:** https://forum.yunohost.org/t/enable-cors-for-nextcloud/14508
**Category:** Support apps
**Tags:** english
**Created:** [February 12, 2021, 12:39am UTC](https://forum.yunohost.org/t/enable-cors-for-nextcloud/14508 "2021-02-12T00:39:49Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Tio](https://forum.yunohost.org/user_avatar/forum.yunohost.org/tio/32/4026_2.png) [@Tio](https://forum.yunohost.org/u/Tio)
#### Post date: [February 12, 2021, 12:39am UTC](https://forum.yunohost.org/t/enable-cors-for-nextcloud/14508/1 "2021-02-12T00:39:50Z")

</div>

### My YunoHost server

**Hardware:** VPS bought online  
**YunoHost version:** latest  
**I have access to my server :** Through SSH | through the webadmin | direct access via keyboard / screen | …  
**Are you in a special context or did you perform some particular tweaking on your YunoHost instance ?** : no

### Description of my issue

I would like to enable CORS for our PDF books stored on our NextCloud. I tried so many methods but didn’t manage to. I tried adding CORS nginx code to /etc/nginx/conf.d/www.drive.tromsite.com.d/nextcloud.conf …

I come from Apache and we had this:

```
SetEnvIf Origin "^http(s)?://(.+\.)?(tromsite\.com|tromsite\.de)$" origin_is=$0 
Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is

Header always set Access-Control-Allow-Headers "range" 

Header always set Access-Control-Expose-Headers: "Accept-Ranges, Content-Encoding, Content-Length, Content-Range"

Header always set Access-Control-Allow-Methods: "POST, GET, OPTIONS"

Header always set Accept-Ranges "bytes"

Header always set Access-Control-Allow-Credentials "true"

Header always set Strict-Transport-Security: "max-age=31536000"

```

It worked, but on nginx I do not know how to do it.

---

<div class="post-metadata">

### Author: ![Aleks](https://forum.yunohost.org/user_avatar/forum.yunohost.org/aleks/32/1704_2.png) [@Aleks](https://forum.yunohost.org/u/Aleks)
#### Post date: [February 12, 2021, 1:01am UTC](https://forum.yunohost.org/t/enable-cors-for-nextcloud/14508/2 "2021-02-12T01:01:48Z")

</div>

You probably need to add something like

```auto
more_set_headers "Access-Control-Allow-Origin: some value";

```

and similar line for other headers in /etc/nginx/conf.d/yourdomain.tld.d/nextcloud.conf

---

<div class="post-metadata">

### Author: ![Tio](https://forum.yunohost.org/user_avatar/forum.yunohost.org/tio/32/4026_2.png) [@Tio](https://forum.yunohost.org/u/Tio)
#### Post date: [February 12, 2021, 1:05am UTC](https://forum.yunohost.org/t/enable-cors-for-nextcloud/14508/3 "2021-02-12T01:05:47Z")

</div>

Yup thanks. Works with:

```
  more_set_headers "Access-Control-Allow-Origin https://www.tromsite.com";
  more_set_headers "Access-Control-Max-Age 3600";
  more_set_headers "Access-Control-Expose-Headers Content-Length";
  more_set_headers "Access-Control-Allow-Headers Range";
  more_set_headers "Accept-Ranges bytes";

```

But now I am struggling to find a way to allow bytes. Meaning, we have some huge books and it is better to be able to download a few bits then to display the books, instead of downloading the entire book before displaying it. We managed to do it with the httaccess code.

---

<div class="post-metadata">

### Author: ![Tio](https://forum.yunohost.org/user_avatar/forum.yunohost.org/tio/32/4026_2.png) [@Tio](https://forum.yunohost.org/u/Tio)
#### Post date: [February 12, 2021, 12:33pm UTC](https://forum.yunohost.org/t/enable-cors-for-nextcloud/14508/4 "2021-02-12T12:33:35Z")

</div>

With the above set, nginx: worker process was eating some 5GB of RAM… Had to restart it.

---

<div class="post-metadata">

### Author: ![system](https://forum.yunohost.org/uploads/default/original/2X/f/f59fe8e3ee6b100b4f574d30d6e30479c68b89f0.png) [@system](https://forum.yunohost.org/u/system)
#### Post date: [February 27, 2021, 12:34pm UTC](https://forum.yunohost.org/t/enable-cors-for-nextcloud/14508/5 "2021-02-27T12:34:03Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
