post(caddy-v2): add 'defer' example

This commit is contained in:
MDLeom 2020-05-28 04:49:18 +01:00
parent f994ac0043
commit 3e00112fe4
No known key found for this signature in database
GPG Key ID: 5D9DB57A25D34EE3
1 changed files with 13 additions and 0 deletions

View File

@ -2,6 +2,7 @@
title: Upgrading Caddy reverse proxy from v1 to v2 syntax title: Upgrading Caddy reverse proxy from v1 to v2 syntax
excerpt: route, strip_prefix, rewrite excerpt: route, strip_prefix, rewrite
date: 2020-05-23 date: 2020-05-23
lastUpdated: 2020-05-28
tags: tags:
- server - server
- caddy - caddy
@ -172,6 +173,18 @@ example.com www.example.com {
} }
``` ```
## header and reverse_proxy
`header` directive still keeps similar syntax, but operates a bit different. In v2, when used alongside with `reverse_proxy`, Caddy modifies the header _before_ receiving header response from the backend. This behaviour is apparent when you want to replace existing header(s); instead of replacing, Caddy adds the header and results in duplicate headers. To avoid this issue, you should use `defer`:
``` plain v2
header {
-server
Referrer-Policy "no-referrer"
defer
}
```
## Disable HTTP -> HTTPS redirects ## Disable HTTP -> HTTPS redirects
In v2, Caddy automatically listens on HTTP (port 80) and redirects to HTTPS, whereas in v1, you need add a separate `redir 301`. This is handy is most use cases, but doesn't apply to my {% post_link caddy-nixos-part-3 'use case' %}--listens on HTTPS only. In v2, Caddy automatically listens on HTTP (port 80) and redirects to HTTPS, whereas in v1, you need add a separate `redir 301`. This is handy is most use cases, but doesn't apply to my {% post_link caddy-nixos-part-3 'use case' %}--listens on HTTPS only.