From be52884226866fc49fc98acc186647867c834124 Mon Sep 17 00:00:00 2001 From: Catalin Constantin Mititiuc Date: Thu, 26 Jun 2025 18:14:32 -0700 Subject: [PATCH] Update post --- .../2025-06-22-test-nginx-conf-directives.md | 55 +++++++++++++++---- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/posts/2025-06-22-test-nginx-conf-directives.md b/posts/2025-06-22-test-nginx-conf-directives.md index 6ed6b58..07f9336 100644 --- a/posts/2025-06-22-test-nginx-conf-directives.md +++ b/posts/2025-06-22-test-nginx-conf-directives.md @@ -8,22 +8,32 @@ $index We'll need nginx and luarocks. Buildpack has luarocks installed. -docker pull openresty/openresty:bookworm-buildpack +```console +$ docker pull openresty/openresty:bookworm-buildpack +``` +Start a server on `localhost`: + +```console $ docker run --rm -it -p 80:80 openresty/openresty:bookworm-buildpack +``` Visit `localhost` in browser. Should see OpenResty splash page. ![OpenResty default nginx index page](/images/openresty-default-index-page.png) -https://openresty.org/en/getting-started.html#prepare-directory-layout +[Prepare directory layout](ehttps://openresty.org/en/getting-started.html#prepare-directory-layout) +```console $ mkdir -p logs/ conf/conf.d/ html/ +``` -https://github.com/openresty/docker-openresty?tab=readme-ov-file#nginx-config-files +[Copy config file](https://github.com/openresty/docker-openresty?tab=readme-ov-file#nginx-config-files) +```console $ docker run --rm -it -w /opt -v $PWD:/opt openresty/openresty:bookworm-buildpack \ cp /etc/nginx/conf.d/default.conf /opt/conf.d/ +``` edit default.conf change `root /usr/local/openresty/nginx/html;` to: @@ -149,7 +159,9 @@ container does not have access to the internet, otherwise we might unintentionally get a response from a domain's server on the internet rather than from our test server. +```console $ docker network create --internal no-internet +``` Now we can start the test server with our host: @@ -287,8 +299,7 @@ server { Rebuild the image: ```console -$ make image-rm -$ make image-build +$ make image-rm image-build ``` Run tests: @@ -323,7 +334,7 @@ $ make test 3 successes / 0 failures / 0 errors / 0 pending : 0.017065 seconds ``` -## Reverse proxy a subdomain to a Gitea unix socket +## Reverse proxy a subdomain to a unix socket Add to `default.conf`: @@ -351,13 +362,13 @@ Add subdomain to certs in Dockerfile: -addext "subjectAltName=DNS:domain.abc,DNS:git.domain.abc" ``` -Add a test socket server: +Add a test socket server (copied and modified from [here](https://github.com/lunarmodules/luasocket/blob/4844a48fbf76b0400fd7b7e4d15d244484019df1/test/unixstreamsrvr.lua)): +::: filename-for-code-block `spec/unixstreamsrvr.moon` +::: ```moonscript --- modified from --- https://github.com/lunarmodules/luasocket/blob/4844a48fbf76b0400fd7b7e4d15d244484019df1/test/unixstreamsrvr.lua socket = require "socket" socket.unix = require "socket.unix" u = assert socket.unix.stream! @@ -384,7 +395,7 @@ describe "https://git.domain.abc", -> os.execute "install -o #{socket.owner} -d #{socket.dir}" cmd = "su -s /bin/bash -c 'moon %s' %s" server = io.popen cmd\format "#{basepath}/#{socket.fname}", socket.owner - os.execute "sleep #{seconds}" + os.execute "sleep #{seconds}" -- wait for server to start f = io.popen "find #{socket.dir} -type s -ls", "r" result = with f\read "*a" f\close! @@ -423,4 +434,28 @@ $ make test ## Bonus!: Issues We Ran Into Just Trying To Make This Post 1. `$host$request_uri` + + `renderers/markdown.moon` + + ```moonscript + dollar_temp = "0000sitegen_markdown00dollar0000" + ``` + + So, when two cosmo selectors had no space between them, it was ambiguous + to which selector the numbers belonged. + + ``` + 0000sitegen_markdown00dollar0000.10000sitegen_markdown00dollar0000.2 + ``` + + Solution was to change the first `0` to a letter `z`: + + ``` + z000sitegen_markdown00dollar0000.1z000sitegen_markdown00dollar0000.2 + ``` + + Because `dollar_temp` is a private attribute, I had to copy every function + from the sitegen markdown renderer. Which makes my renderer a copy with + some additions. + 2. `$$ct`