Monday, September 16, 2024

OpenBSD httpd configuration for cgit with lua support

Hello there,

I've been trying to setup cgit on my OpenBSD server and encountered an
issue with running my own compiled version of `cgit.cgi`. Here's some
context:

I followed the official instructions from the cgit README
[https://git.zx2c4.com/cgit/tree/README] and comiled cgit with lua
support using:

`gmake LUA_PKGCONFIG=luajit CFLAGS="-I/usr/local/include/luajit-2.0" install`

However, when I try to run the `cgit.cgi` with the following OpenBSD
`httpd` configuration, it doesn't work as expected:

```
server "git.example.com" {
listen on * tls port 443
tls {
certificate "/etc/ssl/git.example.com.fullchain.pem"
key "etc/ssl/private/git.example.com.key"
}

location "/cgit.*" {
root "/cgit"
no fastcgi
}

root "/cgi-bin/cgit.cgi"
fastcgi socket "/run/slowcgi.sock"

location "/.well-known/acme-challenge/*" {
root "/acme"
request strip 2
}
}
```

The interesting part is that the official package cgit.cgi works
perfectly fine with this configuration, but as soon as i switch to my
compiled version with Lua support, it fails to load.

For comparision i previously had a similar setup running on Nginx
(Debian), and everything worked smoothly with the following
configuration:

```
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/ssl/nginx/git.example.org.crt;
ssl_certificate_key /etc/ssl/nginx/git.example.org.key;
server_name git.example.org;

root /usr/share/cgit;
try_files $uri @cgit;

location ~ /.+/(info/refs|git-upload-pack) {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param PATH_INFO $uri;
fastcgi_param GIT_HTTP_EXPORT_ALL 1;
fastcgi_param GIT_PROJECT_ROOT /var/git;
fastcgi_param HOME /var/git;
fastcgi_pass unix:/run/fcgiwrap.socket;
}

location @cgit {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/lib/cgit/cgit.cgi;
fastcgi_param PATH_INFO $uri;
fastcgi_param QUERY_STRING $args;
fastcgi_param HTTP_HOST $server_name;
fastcgi_pass unix:/run/fcgiwrap.socket;
}
}
```

PS - I ended up merging the `jd/zx2c4-deployment` branch that uses uwsgi
insted of slowcgi then i recompiled uwsgi from github
[https://github.com/unbit/uwsgi] and setup a config for cgit in
`/var/www/uwgsi/cgit.ini` here's what the config looks like:

```
[uwsgi]
fastcgi-socket = /var/www/run/cgit.socket
fastcgi-modifier1 = 9
plugin-dir = /var/www/uwsgi-git/
plugins = cgi

cgi = /var/www/uwsgi/cgit/cgi/cgit.cgi
need-app = false
CGIT_CONFIG = /etc/cgitrc
gid = www
uid = www
```

then i just ran this:

`./uwsgi --ini /var/www/uwsgi/cgit.ini`

and it worked! so I updated my httpd to use cgit.socket instead of
slowcgi.sock and everything's running fine.

but now i've got an new issue my `cgitrc` file doesn't seem to be
recognising, no matter where i put it. i tried `/var/www/conf/cgitrc`
and `/etc/cgitrc` but still nothing worked. am trying to figure it out
anybody have any idea about it please let me know

NOTE - I wanna use all the filters in the cgit projects that they have
provided

Biswakalyan

No comments:

Post a Comment