worker_processes 1; error_log logs/error.log; events { worker_connections 1024; } http { init_by_lua_block { require "routes" } server { listen 8080; include mime.types; charset utf-8; location = /posts { # rewrite ^ /posts/ last; # loads "/posts/" # rewrite ^ /posts/ break; # loads "/posts/index.html" rewrite_by_lua_block { -- equivalent to `rewrite ^ /posts/ break;` ngx.req.set_uri("/posts/", false) } } location = /posts/ { content_by_lua_block { return ngx.redirect("/posts", ngx.HTTP_MOVED_PERMANENTLY) } } location /posts/ { content_by_lua_block { require "routes":dispatch() -- ngx.req.set_uri("/posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html") -- ngx.req.set_uri(ngx.var.uri, false) -- ngx.req.set_uri("/posts/index.html", false) } # rewrite ^ /posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html break; } location /css { expires 1h; alias css; } location /blah { rewrite ^/posts$ /posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html break; } } }