2020-02-08 14:33:13 +01:00
|
|
|
# This file creates an nginx server that serves the blog on port 8080.
|
|
|
|
#
|
|
|
|
# It's not intended to be the user-facing nginx.
|
2020-02-08 15:06:57 +01:00
|
|
|
{
|
|
|
|
# third_party attributes supplied by callPackage
|
|
|
|
writeText, writeShellScriptBin, nginx, lib,
|
|
|
|
|
|
|
|
# website content
|
2020-02-09 01:01:07 +01:00
|
|
|
blog, website
|
2020-02-08 15:06:57 +01:00
|
|
|
}:
|
2020-02-08 14:33:13 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
inherit (builtins) hasAttr filter map;
|
2020-02-08 15:06:57 +01:00
|
|
|
inherit (pkgs.third_party) ;
|
2020-02-08 14:33:13 +01:00
|
|
|
|
|
|
|
oldRedirects = lib.concatStringsSep "\n" (map (post: ''
|
2020-02-09 01:30:51 +01:00
|
|
|
location ~* ^(/en)?/${post.oldKey} {
|
2020-02-08 14:33:13 +01:00
|
|
|
# TODO(tazjin): 301 once this works
|
2020-02-09 02:48:59 +01:00
|
|
|
return 302 https://tazj.in/blog/${post.key};
|
2020-02-08 14:33:13 +01:00
|
|
|
}
|
2020-02-08 15:06:57 +01:00
|
|
|
'') (filter (hasAttr "oldKey") blog.posts));
|
2020-02-08 14:33:13 +01:00
|
|
|
|
2020-02-08 15:06:57 +01:00
|
|
|
config = writeText "homepage-nginx.conf" ''
|
2020-02-08 14:33:13 +01:00
|
|
|
daemon off;
|
|
|
|
worker_processes 1;
|
|
|
|
error_log stderr;
|
2020-02-08 15:06:57 +01:00
|
|
|
pid /tmp/nginx-homepage.pid;
|
2020-02-08 14:33:13 +01:00
|
|
|
|
|
|
|
events {
|
|
|
|
worker_connections 1024;
|
|
|
|
}
|
|
|
|
|
|
|
|
http {
|
|
|
|
include ${nginx}/conf/mime.types;
|
2020-02-08 15:06:57 +01:00
|
|
|
fastcgi_temp_path /tmp/nginx-homepage;
|
|
|
|
uwsgi_temp_path /tmp/nginx-homepage;
|
|
|
|
scgi_temp_path /tmp/nginx-homepage;
|
|
|
|
client_body_temp_path /tmp/nginx-homepage;
|
|
|
|
proxy_temp_path /tmp/nginx-homepage;
|
2020-02-08 14:33:13 +01:00
|
|
|
sendfile on;
|
|
|
|
|
|
|
|
# Logging is handled by the primary nginx server
|
|
|
|
access_log off;
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 8080 default_server;
|
2020-02-09 02:48:59 +01:00
|
|
|
server_name tazj.in;
|
2020-02-09 01:01:07 +01:00
|
|
|
root ${website};
|
2020-02-08 14:33:13 +01:00
|
|
|
|
|
|
|
${oldRedirects}
|
|
|
|
|
2020-02-09 22:05:03 +01:00
|
|
|
location ~* \.(webp|woff2)$ {
|
|
|
|
add_header Cache-Control "public, max-age=31536000";
|
|
|
|
}
|
|
|
|
|
2020-02-09 01:01:07 +01:00
|
|
|
location /blog {
|
|
|
|
alias ${blog.rendered};
|
|
|
|
|
2020-02-08 14:33:13 +01:00
|
|
|
if ($request_uri ~ ^/(.*)\.html$) {
|
|
|
|
return 302 /$1;
|
|
|
|
}
|
|
|
|
|
|
|
|
try_files $uri $uri.html $uri/ =404;
|
|
|
|
}
|
|
|
|
}
|
2020-02-09 02:48:59 +01:00
|
|
|
|
|
|
|
server {
|
|
|
|
listen 8080;
|
|
|
|
server_name www.tazj.in;
|
|
|
|
return 301 https://tazj.in$request_uri;
|
|
|
|
}
|
2020-02-08 14:33:13 +01:00
|
|
|
}
|
|
|
|
'';
|
2020-02-08 15:06:57 +01:00
|
|
|
in writeShellScriptBin "homepage" ''
|
2020-02-08 14:33:13 +01:00
|
|
|
if [[ -v CONTAINER_SETUP ]]; then
|
|
|
|
cd /run
|
|
|
|
echo 'nogroup:x:30000:nobody' >> /etc/group
|
|
|
|
echo 'nobody:x:30000:30000:nobody:/tmp:/bin/bash' >> /etc/passwd
|
|
|
|
fi
|
|
|
|
|
2020-02-08 15:06:57 +01:00
|
|
|
mkdir -p /tmp/nginx-homepage
|
|
|
|
exec ${nginx}/bin/nginx -c ${config}
|
2020-02-08 14:33:13 +01:00
|
|
|
''
|