mirror of https://gitlab.com/curben/blog
				
				
				
			post(caddy-v2): add 'defer' example
This commit is contained in:
		
							parent
							
								
									f994ac0043
								
							
						
					
					
						commit
						3e00112fe4
					
				| 
						 | 
					@ -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.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue