From: Landry Breuil Subject: nginx rewrites to migrate from cgit to gotwebd To: gameoftrees@openbsd.org Date: Tue, 28 May 2024 09:37:20 +0200 hi, currently migrating services, i'd like to get rid of cgit because slowcgi, but the urls are handy. i've come up with the following that isn't perfect but is a start, and works for some cgit-like urls. map $arg_h $branch { '' 'HEAD'; ~. $arg_h; } map $arg_id $commit { '' ''; ~. &commit=$arg_id; } location /c/ { rewrite_log on; error_log /tmp/ngx_rewrite.log notice; rewrite /c/(?.*)/diff/$ /gotwebd/?path=$repo$commit&headref=$branch&action=diff? last; rewrite /c/(?.*)/diff/(?.*) /gotwebd/?path=$repo$commit&headref=$branch&action=diff&file=$file&folder=? last; rewrite /c/(?.*)/patch/ /gotwebd/?path=$repo$commit&action=patch? last; rewrite /c/(?.*)/refs/ /gotwebd/?path=$repo$commit&headref=$branch&action=briefs? last; rewrite /c/(?.*)/plain/(?.*) /gotwebd/?path=$repo$commit&action=blobraw&file=$file&folder=? last; rewrite /c/(?.*)/tree/$ /gotwebd/?path=$repo$commit&action=tree? last; rewrite /c/(?.*)/tree/(?.*)/(?[!/]*) /gotwebd/?path=$repo$commit&action=blob&folder=$folder&file=$file? last; rewrite /c/(?.*)/tree/(?[!/]*) /gotwebd/?path=$repo$commit&action=blob&file=$file&folder=? last; rewrite /c/(?.*)/commit/ /gotwebd/?path=$repo$commit&headref=$branch&action=diff? last; rewrite /c/(?.*)/log/ /gotwebd/?path=$repo$commit&headref=$branch&action=commits? last; rewrite /c/(?.*)/ /gotwebd/?path=$repo$commit&headref=$branch&action=summary? last; } the /c/ is for testing rewrites, the final idea is to have this location block at the root to replace cgit. one thing i've noticed is that gotwebd complains with invalid query string when the commit arg is unset, couldn't we assume it's the HEAD commit in that case? Landry