# Mistake in nginx config from documentation?

**URL:** <https://help.nextcloud.com/t/mistake-in-nginx-config-from-documentation/26865>\
**Category:** ℹ️ Support\
**Created:** [February 4, 2018, 2:35pm UTC](https://help.nextcloud.com/t/mistake-in-nginx-config-from-documentation/26865 "2018-02-04T14:35:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lara](https://help.nextcloud.com/letter_avatar/lara/32/6_22734026db12803ebb3e059622ac3534.png) [@lara](https://help.nextcloud.com/u/lara)\
**Post date:** [February 4, 2018, 2:36pm UTC](https://help.nextcloud.com/t/mistake-in-nginx-config-from-documentation/26865/1 "2018-02-04T14:36:00Z")

</div>

The nginx documentation ([https://docs.nextcloud.com/server/12/admin\_manual/installation/nginx.html](https://docs.nextcloud.com/server/12/admin_manual/installation/nginx.html)) shows a lot of headers that we can add:

```
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;

```

and `add_header Strict-Transport-Security`

Lower down the page in the block beginning

`location ~ \.(?:css|js|woff|svg|gif)$ {`

the same headers are there. Are both needed?

---

<div class="post-metadata">

**Author:** ![Bernie\_O](https://help.nextcloud.com/user_avatar/help.nextcloud.com/bernie_o/32/40181_2.png) [@Bernie\_O](https://help.nextcloud.com/u/Bernie_O)\
**Post date:** [February 4, 2018, 5:20pm UTC](https://help.nextcloud.com/t/mistake-in-nginx-config-from-documentation/26865/2 "2018-02-04T17:20:00Z")

</div>

> [@lara](#):
>
> Are both needed?

Yes, they are both needed. See nginx-docu:  
[http://nginx.org/en/docs/http/ngx\_http\_headers\_module.html#add\_header](http://nginx.org/en/docs/http/ngx_http_headers_module.html#add_header)

Because the cache-control is added, all other headers won’t be inherited and thus have to be there as well.

---

<div class="post-metadata">

**Author:** ![lara](https://help.nextcloud.com/letter_avatar/lara/32/6_22734026db12803ebb3e059622ac3534.png) [@lara](https://help.nextcloud.com/u/lara)\
**Post date:** [February 4, 2018, 5:50pm UTC](https://help.nextcloud.com/t/mistake-in-nginx-config-from-documentation/26865/3 "2018-02-04T17:50:15Z")

</div>

> [@Bernie\_O](#):
>
> Yes, they are both needed.

Then they are missing for the other locations block?

---

<div class="post-metadata">

**Author:** ![Bernie\_O](https://help.nextcloud.com/user_avatar/help.nextcloud.com/bernie_o/32/40181_2.png) [@Bernie\_O](https://help.nextcloud.com/u/Bernie_O)\
**Post date:** [February 5, 2018, 5:42am UTC](https://help.nextcloud.com/t/mistake-in-nginx-config-from-documentation/26865/4 "2018-02-05T05:42:42Z")

</div>

> [@lara](#):
>
> Then they are missing for the other locations block?

No. In the other location blocks there are no add\_header directives and the add\_header directives are then inherited from the previous level.

The nginx documentation describes it quite well:  
_„These directives are inherited from the previous level if and only if there are no add\_header directives defined on the current level.“_

---

<div class="post-metadata">

**Author:** ![JonSmith](https://help.nextcloud.com/letter_avatar/jonsmith/32/6_22734026db12803ebb3e059622ac3534.png) [@JonSmith](https://help.nextcloud.com/u/JonSmith)\
**Post date:** [August 28, 2019, 2:24pm UTC](https://help.nextcloud.com/t/mistake-in-nginx-config-from-documentation/26865/5 "2019-08-28T14:24:01Z")

</div>

That means it doesn’t get inherited for this block only because of the “cache-control” line, right?

So if I add headers I have to add them in both blocks, right?

PS: wouldn’t it be more comfortable to set all the headers in a separate file called “headers.conf” and load them with “include headers.conf” at the two locations in the nginx vHost configuration?

How does nginx handle this?  
Will they be inserted in the correct place? That means in the exact place where I put the “include” line?

---

<div class="post-metadata">

**Author:** ![Bernie\_O](https://help.nextcloud.com/user_avatar/help.nextcloud.com/bernie_o/32/40181_2.png) [@Bernie\_O](https://help.nextcloud.com/u/Bernie_O)\
**Post date:** [August 28, 2019, 9:09pm UTC](https://help.nextcloud.com/t/mistake-in-nginx-config-from-documentation/26865/6 "2019-08-28T21:09:55Z")

</div>

> [@JonSmith](#):
>
> That means it doesn’t get inherited for this block only because of the “cache-control” line, right?
> 
> So if I add headers I have to add them in both blocks, right?

Yes and yes.

> [@JonSmith](#):
>
> PS: wouldn’t it be more comfortable to set all the headers in a separate file called “headers.conf” and load them with “include headers.conf” at the two locations in the nginx vHost configuration?

That is possible. It is up to you to decide whether this is more comfortable for you 😉

> [@JonSmith](#):
>
> How does nginx handle this?  
> Will they be inserted in the correct place? That means in the exact place where I put the “include” line?

Basically the line with the `include`-directive will be replaced with the contents of the included file. Thus the included file needs to have correct nginx configuration syntax.

---

<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 3, 2024, 9:17pm UTC](https://help.nextcloud.com/t/mistake-in-nginx-config-from-documentation/26865/7 "2024-12-03T21:17:38Z")

</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 9, 2024, 2:10pm UTC](https://help.nextcloud.com/t/mistake-in-nginx-config-from-documentation/26865/8 "2024-12-09T14:10:07Z")

</div>


