From 98b38376b5488ffd8a357eefdeaf2fbb56e3a361 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 15 Nov 2021 03:28:08 +0400 Subject: [PATCH] A new note added to NGiNX's recipes & tips article. This one tells about variables. --- .../views/articles/nginx_recipes_and_tips.pug | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/homepage/views/articles/nginx_recipes_and_tips.pug b/homepage/views/articles/nginx_recipes_and_tips.pug index e5fafbc..d9d8ce4 100644 --- a/homepage/views/articles/nginx_recipes_and_tips.pug +++ b/homepage/views/articles/nginx_recipes_and_tips.pug @@ -5,14 +5,15 @@ block article h2 NGiNX's recipes & tips div.menu a(href='/stuff#articles') Go back to articles list - time(datetime='2020-12-04') 4 December 2020 + time(datetime='2021-11-15') 15 November 2021 nav h3 Contents ol li #[a(href='#art-1') Introduction] li #[a(href='#art-2') Userdir functionality like Apache's mod_userdir] li #[a(href='#art-3') Note on how NGiNX works with HTTP headers] - li #[a(href='#art-3') Tell a Tor visitor of your clearnet site that you have an onion] + li #[a(href='#art-4') Tell a Tor visitor of your clearnet site that you have an onion] + li #[a(href='#art-5') Variables] h3#art-1 #[a(href='#art-1') 1. Introduction] p Here I'll place recipes for implementing different functionalities and notes on webserver's behaviour. @@ -33,8 +34,24 @@ block article p Let's say in #[code http] block you specified common headers like #[code X-Frame-Options], #[code X-XSS-Protection], and so on for all #[code server] directives to use. But, if you add some other header for a specific #[code server] or #[code location] block then all those headers would be dropped. p For now the only cure for it is to place all that headers in a separate file like #[code common-headers.inc] and using #[code include] directive to include them in all the #[code server] and #[code location] blocks where additional headers are added. - h3#art-4 #[a(href='#art-3') 4. Tell a Tor visitor of your clearnet site that you have an onion] + h3#art-4 #[a(href='#art-4') 4. Tell a Tor visitor of your clearnet site that you have an onion] p There is a custom HTTP header #[code Onion-Location] that is being recognised by Tor Browser and it will show a ".onion available" button in an address bar. p The code for NGiNX is this simple: pre | add_header Onion-Location http://yoursite.onion$request_uri; + + h3#art-5 #[a(href='#art-5') 5. Variables] + p Just wanna tell about this cool feature you can use to reduce code repetition. Alas, you can use them only in #[code server], #[code location] and #[code if] blocks. If only they could be declared in a #[code http] block, they'd be perfect. But still, they help a lot. + p I heavily use aliases pointing to directories within the same base directory. + p Judging from a little testing, variables doesn't decrease performance. Or I just don't notice it. + p Variables could only store strings. To demonstrate the usage I'll just post here a part of my config: + pre + | set $root /srv/http/dwelling; + | ... + | location =/favicon.ico { + | alias $root/shared/static/img/favicon.ico; + | } + | ... + | location /assets/ { + | alias $root/homepage/static/assets/; + | }