Last active
January 9, 2023 11:02
-
-
Save reitzig/4e3f10a77d77e2474f20d426a00d2869 to your computer and use it in GitHub Desktop.
Minimal nginx Docker image with antora redirects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# snip | |
urls: | |
latest_version_segment_strategy: redirect:from | |
latest_version_segment: latest # your choice, doesn't impact the script below | |
redirect_facility: nginx | |
# snip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM nginxinc/nginx-unprivileged:alpine | |
COPY build/site /usr/share/nginx/html/ | |
# Inject the rewrite rules antora generates into the nginx config: | |
# 1. Add \ to the end of every line (to make the multi-line sed command in 3. work), and | |
# indent all lines (cosmetics). | |
# 2. Append another ("escaped") empty line (cosmetics). | |
# 3. Insert what we got before the final closing brace in the default config file. | |
# NB: Using % as separator for the replace command because rewrite.conf contains many / | |
# 4. Clean up | |
RUN sed -e 's/$/\\/' \ | |
-e 's/^/ /' \ | |
< /usr/share/nginx/html/.etc/nginx/rewrite.conf \ | |
> /tmp/rewrite.conf \ | |
&& echo -e "\\" >> /tmp/rewrite.conf \ | |
&& sed -i -e "s%^}%\n$(cat /tmp/rewrite.conf)}\n%" \ | |
/etc/nginx/conf.d/default.conf \ | |
&& rm -rf /tmp/rewrite.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Route
, in my case), further steps are needed (cf. antora/antora#1035). In some cases, it may be enough to extend the above script; add-r
and-e 's% (/[^ ]*)( redirect)?;% \$scheme://\$http_host\1\2;%'
to the
sed
command in step 1.