Fix nginx conf

This commit is contained in:
Catalin Constantin Mititiuc 2025-05-19 15:21:50 -07:00
parent 212d555b51
commit 9f7ce7ad15

View File

@ -6,59 +6,25 @@ events {
} }
http { http {
init_by_lua_block {
require "routes"
}
server { server {
listen 8080; listen 8080;
include mime.types; include mime.types;
charset utf-8; charset utf-8;
try_files $uri $uri/ $uri.html =404;
location = /posts { location = /posts {
# rewrite ^ /posts/ last; # loads "/posts/" rewrite ^ /posts/ break;
# rewrite ^ /posts/ break; # loads "/posts/index.html"
rewrite_by_lua_block {
local flag = { ["break"] = false };
-- equivalent to `rewrite ^ /posts/ break;`
ngx.req.set_uri("/posts/", flag["break"])
}
} }
location = /posts/ { location ~ ^/(.+)/$ {
content_by_lua_block { return 302 /$1;
return ngx.redirect("/posts", ngx.HTTP_MOVED_PERMANENTLY)
}
}
location /posts/ {
rewrite_by_lua_block {
local uri = ngx.re.sub(ngx.var.uri, "^/posts/(.*)", "$1", "o")
-- ngx.req.set_uri(uri)
local ext = string.match(uri, "[%w%-%_]+$")
ngx.say("request path " .. uri)
if ext == uri then
ngx.say("no extension")
else
ngx.say("extension " .. ext)
end
ngx.say(ngx.var.uri)
}
# rewrite ^ /posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html break;
} }
location /css { location /css {
expires 1h; expires 1h;
alias css; alias css;
} }
location /blah {
rewrite ^/posts$ /posts/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.html break;
}
} }
} }