diff --git a/source/_posts/caddy-nixos-part-3.md b/source/_posts/caddy-nixos-part-3.md index 1d2dfa0..7d856d9 100644 --- a/source/_posts/caddy-nixos-part-3.md +++ b/source/_posts/caddy-nixos-part-3.md @@ -2,6 +2,7 @@ title: "Setup Caddy as a reverse proxy on NixOS (Part 3: Caddy)" excerpt: "Part 3: Configure Caddy" date: 2020-03-14 +lastUpdated: 2020-04-08 tags: - web - linux @@ -217,7 +218,6 @@ If you prefer to redirect apex to www, Aside from reverse proxy to curben.netlify.com, I also configured my Netlify website to use Statically CDN for on-the-fly image processing. My current [config](https://gitlab.com/curben/blog) is: ``` plain source/_redirects https://gitlab.com/curben/blog/-/blob/master/source/_redirects _redirects -/libs/* https://cdn.statically.io/libs/:splat 200 /img/* https://cdn.statically.io/img/gitlab.com/curben/blog/raw/site/:splat 200 /screenshot/* https://cdn.statically.io/screenshot/mdleom.com/:splat?mobile=true 200 ``` @@ -225,10 +225,6 @@ Aside from reverse proxy to curben.netlify.com, I also configured my Netlify web In Caddyfile, the config can be expressed as: ``` plain - proxy /libs https://cdn.statically.io/libs { - without /libs - } - proxy /img https://cdn.statically.io/img/gitlab.com/curben/blog/raw/site { without /img } @@ -254,11 +250,6 @@ For `/screenshot`, since the `proxy` doesn't support variable like the Netlify ` To make sure Caddy sends the correct `Host:` header to the upstream/backend locations, I use `header_upstream` option, ``` plain - proxy /libs https://cdn.statically.io/libs { - without /libs - header_upstream Host cdn.statically.io - } - proxy /img https://cdn.statically.io/img/gitlab.com/curben/blog/raw/site { without /img header_upstream Host cdn.statically.io @@ -287,10 +278,6 @@ There are a few repetitions for rewriting the header for Statically. I can group } mdleom.com { - proxy /libs ... { - import staticallyCfg - } - proxy /img ... { import staticallyCfg } @@ -322,10 +309,6 @@ To prevent any unnecessary request headers from being sent to the upstreams, I u } mdleom.com { - proxy /libs ... { - import removeHeaders - } - proxy /img ... { import removeHeaders } @@ -359,28 +342,7 @@ I also add the `Cache-Control` and `Referrer-Policy` to the response header. Use ### header and header_downstream -`/lib` location is used to grab javascript libraries from Statically CDN. Since the library is usually requested by a specific version, we can safely assume that the response would remain the same. This means I can set long expiration and `immutable` on the response. [`immutable`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Revalidation_and_reloading) is to tell the browser that revalidation is not needed. - -``` - proxy /libs ... { - header_downstream Cache-Control "public, max-age=31536000, immutable" - } -``` - -However, one issue I noticed is that `header` directive takes precedent over `header_downstream` option in `proxy` directive. - -``` - header / { - Cache-Control "max-age=604800, public" - } - - proxy /libs ... { - # Doesn't work - header_downstream Cache-Control "public, max-age=31536000, immutable" - } -``` - -To solve that, I specify another `header` directive, +`/libs` folder contains third-party libraries. Since the library is usually requested by a specific version, we can safely assume that the response would remain the same. This means I can set long expiration and `immutable` on the response. [`immutable`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Revalidation_and_reloading) is to tell the browser that revalidation is not needed. ``` header / { @@ -390,10 +352,6 @@ To solve that, I specify another `header` directive, header /libs { Cache-Control "public, max-age=31536000, immutable" } - - proxy /libs ... { - # header_downstream no longer needed here - } ``` ### Complete Caddyfile @@ -454,12 +412,6 @@ mdleom.com:4430 www.mdleom.com:4430 { Cache-Control "public, max-age=31536000, immutable" } - proxy /libs https://cdn.statically.io/libs { - without /libs - import removeHeaders - import staticallyCfg - } - proxy /img https://cdn.statically.io/img/gitlab.com/curben/blog/raw/site { without /img import removeHeaders diff --git a/source/_posts/i2p-eepsite-nixos.md b/source/_posts/i2p-eepsite-nixos.md index 8c4d0a0..5462744 100644 --- a/source/_posts/i2p-eepsite-nixos.md +++ b/source/_posts/i2p-eepsite-nixos.md @@ -249,12 +249,6 @@ ggucqf2jmtfxcw7us5sts3x7u2qljseocfzlhzebfpihkyvhcqfa.b32.i2p:8081 mdleom.i2p:808 Cache-Control "public, max-age=31536000, immutable" } - proxy /libs https://cdn.statically.io/libs { - without /libs - import removeHeaders - import staticallyCfg - } - proxy /img https://cdn.statically.io/img/gitlab.com/curben/blog/raw/site { without /img import removeHeaders diff --git a/source/_posts/tor-hidden-onion-nixos.md b/source/_posts/tor-hidden-onion-nixos.md index 46e7e84..24bd7a6 100644 --- a/source/_posts/tor-hidden-onion-nixos.md +++ b/source/_posts/tor-hidden-onion-nixos.md @@ -224,12 +224,6 @@ xw226dvxac7jzcpsf4xb64r4epr6o5hgn46dxlqk7gnjptakik6xnzqd.onion:8080 { Cache-Control "public, max-age=31536000, immutable" } - proxy /libs https://cdn.statically.io/libs { - without /libs - import removeHeaders - import staticallyCfg - } - proxy /img https://cdn.statically.io/img/gitlab.com/curben/blog/raw/site { without /img import removeHeaders diff --git a/source/_redirects b/source/_redirects index 0681a60..843e6a7 100644 --- a/source/_redirects +++ b/source/_redirects @@ -1,4 +1,3 @@ # Reverse proxy to cdn -/libs/* https://cdn.statically.io/libs/:splat 200 /img/* https://cdn.statically.io/img/gitlab.com/curben/blog/raw/site/:splat 200 /screenshot/* https://cdn.statically.io/screenshot/mdleom.com/:splat?mobile=true 200 diff --git a/themes/chameleon/layout/_partial/after-footer.ejs b/themes/chameleon/layout/_partial/after-footer.ejs index 5057f2b..9c98718 100644 --- a/themes/chameleon/layout/_partial/after-footer.ejs +++ b/themes/chameleon/layout/_partial/after-footer.ejs @@ -1,6 +1,6 @@ <% if (is_post()) { %> <%- js([ - { src: '/libs/clipboard.js/2.0.6/clipboard.min.js', 'data-sri-fallback': '/js/clipboard.min.js', integrity: 'sha384-x6nRSkfSsKGBsvlLFHHNju+buS3zYUztVnTRz/0JKgOIk3ulS6bNce/vHOvYE2eY', crossorigin: 'anonymous', defer: true }, + { src: '/libs/clipboard-2.0.6.min.js', defer: true }, '/js/copy-button.js' ]) %> <% } %> diff --git a/themes/chameleon/layout/_partial/head.ejs b/themes/chameleon/layout/_partial/head.ejs index 5668554..0ce5a86 100644 --- a/themes/chameleon/layout/_partial/head.ejs +++ b/themes/chameleon/layout/_partial/head.ejs @@ -53,6 +53,6 @@ <%- css('/css/chameleon.css') %> <% if (theme.icons) { %> - <%- css({ href: '/libs/fork-awesome/1.1.7/css/fork-awesome.min.css', 'data-sri-fallback': '/forkawesome/css/fork-awesome.min.css', integrity: 'sha384-mByhW6NjnxyShh67P9+fepUvYSd7Uz/qV6e2u4kA2Fi4ZkjXxIP2mRkyK9dwK24W', crossorigin: 'anonymous' }) %> + <%- css('/libs/forkawesome/css/forkawesome-1.1.7.min.css') %> <% } %> diff --git a/themes/chameleon/source/js/clipboard.min.js b/themes/chameleon/source/libs/clipboard-2.0.6.min.js similarity index 100% rename from themes/chameleon/source/js/clipboard.min.js rename to themes/chameleon/source/libs/clipboard-2.0.6.min.js diff --git a/themes/chameleon/source/forkawesome/css/fork-awesome.min.css b/themes/chameleon/source/libs/forkawesome/css/forkawesome-1.1.7.min.css similarity index 100% rename from themes/chameleon/source/forkawesome/css/fork-awesome.min.css rename to themes/chameleon/source/libs/forkawesome/css/forkawesome-1.1.7.min.css diff --git a/themes/chameleon/source/forkawesome/fonts/forkawesome-webfont.eot b/themes/chameleon/source/libs/forkawesome/fonts/forkawesome-webfont.eot similarity index 100% rename from themes/chameleon/source/forkawesome/fonts/forkawesome-webfont.eot rename to themes/chameleon/source/libs/forkawesome/fonts/forkawesome-webfont.eot diff --git a/themes/chameleon/source/forkawesome/fonts/forkawesome-webfont.svg b/themes/chameleon/source/libs/forkawesome/fonts/forkawesome-webfont.svg similarity index 100% rename from themes/chameleon/source/forkawesome/fonts/forkawesome-webfont.svg rename to themes/chameleon/source/libs/forkawesome/fonts/forkawesome-webfont.svg diff --git a/themes/chameleon/source/forkawesome/fonts/forkawesome-webfont.ttf b/themes/chameleon/source/libs/forkawesome/fonts/forkawesome-webfont.ttf similarity index 100% rename from themes/chameleon/source/forkawesome/fonts/forkawesome-webfont.ttf rename to themes/chameleon/source/libs/forkawesome/fonts/forkawesome-webfont.ttf diff --git a/themes/chameleon/source/forkawesome/fonts/forkawesome-webfont.woff b/themes/chameleon/source/libs/forkawesome/fonts/forkawesome-webfont.woff similarity index 100% rename from themes/chameleon/source/forkawesome/fonts/forkawesome-webfont.woff rename to themes/chameleon/source/libs/forkawesome/fonts/forkawesome-webfont.woff diff --git a/themes/chameleon/source/forkawesome/fonts/forkawesome-webfont.woff2 b/themes/chameleon/source/libs/forkawesome/fonts/forkawesome-webfont.woff2 similarity index 100% rename from themes/chameleon/source/forkawesome/fonts/forkawesome-webfont.woff2 rename to themes/chameleon/source/libs/forkawesome/fonts/forkawesome-webfont.woff2 diff --git a/themes/chameleon/source/js/sri.min.js b/themes/chameleon/source/libs/sri.min.js similarity index 100% rename from themes/chameleon/source/js/sri.min.js rename to themes/chameleon/source/libs/sri.min.js