gmifs/README.md

100 lines
3.4 KiB
Markdown
Raw Permalink Normal View History

2024-06-08 22:01:48 +03:00
[![Go Report Card](https://goreportcard.com/badge/gitrepo.ru/neonxp/gmifs)](https://goreportcard.com/report/gitrepo.ru/neonxp/gmifs)
[![GoDoc](https://godoc.org/gitrepo.ru/neonxp/gmifs?status.svg)](https://godoc.org/gitrepo.ru/neonxp/gmifs)
2021-07-29 15:12:18 +03:00
2021-07-06 19:48:20 +03:00
# gmifs
2021-07-08 15:55:09 +03:00
Gemini File Server, short gmifs, is intended to be minimal and serve static files. It is used
2021-07-08 16:44:18 +03:00
to accompany a hugo blog served via httpd and makes it available via the [gemini
2021-07-06 19:48:20 +03:00
protocol](https://gemini.circumlunar.space/docs/specification.gmi). Why built yet another gemini
server? Because it's educational and that's the spirit of the protocol.
2021-07-09 20:09:51 +03:00
**Features**
2021-07-08 16:16:17 +03:00
- **zero conf**, if no certificate is available, gmifs generates a self-signed cert
2021-07-08 15:55:09 +03:00
- **zero dependencies**, Go standard library only
2021-07-10 06:43:59 +03:00
- directory listing support through the auto index flag
2021-07-08 16:16:17 +03:00
- reloads ssl certs and reopens log files on SIGHUP, e.g. after Let's Encrypt renewal
2021-07-09 20:09:51 +03:00
- response writer interceptor and middleware support
2021-07-10 07:28:24 +03:00
- simple middleware for fifo document cache
2021-07-09 20:09:51 +03:00
- concurrent request limiter
2021-07-08 16:16:17 +03:00
- KISS, single file gemini implementation, handler func in main
- modern tls ciphers (from [Mozilla's TLS ciphers recommendations](https://statics.tls.security.mozilla.org/server-side-tls-conf.json))
2021-07-06 19:48:20 +03:00
2021-07-08 15:55:09 +03:00
## Usage
2021-07-10 06:43:59 +03:00
### Installation
Currently only supported through the go toolchain, either check out the repot and build it or use:
```
2024-06-08 22:01:48 +03:00
go install gitrepo.ru/neonxp/gmifs
2021-07-10 06:43:59 +03:00
```
2021-07-10 07:28:24 +03:00
### Development
2021-07-08 15:55:09 +03:00
Test it locally by serving e.g. a `./public` directory on localhost with directory listing turned on
2021-07-06 19:48:20 +03:00
2021-07-08 15:55:09 +03:00
```
2021-07-10 06:43:59 +03:00
./gmifs -root ./public -autoindex
2021-07-06 19:48:20 +03:00
```
2021-07-10 06:43:59 +03:00
If no key pair with the flags `-cert` and `-key` is provided, like in this example, gmifs will auto
provision a self-signed certificate for the hostname `localhost` with 1 day validity.
2021-07-08 15:55:09 +03:00
### Production
2021-07-06 19:48:20 +03:00
2021-07-08 15:55:09 +03:00
In the real world generate a self-signed server certificate with OpenSSL or use a Let's Encrypt
2021-07-10 06:43:59 +03:00
key pair. Generate example:
2021-07-06 19:48:20 +03:00
2021-07-08 15:55:09 +03:00
```bash
openssl req -x509 -newkey rsa:4096 -keyout key.rsa -out cert.pem \
-days 3650 -nodes -subj "/CN=nox.im"
2021-07-06 19:48:20 +03:00
```
2021-07-10 06:43:59 +03:00
start gmifs with a Let's Encrypt key pair on OpenBSD:
2021-07-06 19:48:20 +03:00
```
gmifs -addr 0.0.0.0:1965 -root /var/www/htdocs/nox.im/gemini \
2021-07-09 20:49:39 +03:00
-host nox.im -max-conns 256 -timeout 5 -cache 256 \
2021-07-10 06:43:59 +03:00
-logs /var/www/logs/gemini \
2021-07-06 19:48:20 +03:00
-cert /etc/ssl/nox.im.fullchain.pem \
-key /etc/ssl/private/nox.im.key
```
2021-07-08 15:55:09 +03:00
2021-07-10 06:43:59 +03:00
if need be, send SIGHUP to reload the certificate without cold start, e.g. after certificate renewal
2021-07-08 15:55:09 +03:00
```
pgrep gmifs | awk '{print "kill -1 " $1}' | sh
```
2021-07-09 20:49:39 +03:00
If debug logs are enabled, the certificate rotation will be confirmed.
2021-07-10 06:43:59 +03:00
### Supported flags
```
2021-07-10 07:28:24 +03:00
sage of ./gmifs:
2021-07-10 06:43:59 +03:00
-addr string
address to listen on, e.g. 127.0.0.1:1965 (default ":1965")
-autocertvalidity int
2021-07-10 07:28:24 +03:00
valid days when using a gmifs provisioned certificate (default 1)
2021-07-10 06:43:59 +03:00
-autoindex
enables auto indexing, directory listings
-cache int
2021-07-10 07:28:24 +03:00
simple fifo document cache for n items. Disabled when zero.
2021-07-10 06:43:59 +03:00
-cert string
TLS chain of one or more certificates
-debug
enable verbose logging of the gemini server
-host string
hostname for sni and x509 CN when using temporary self-signed certs (default "localhost")
-key string
TLS private key
-logs string
enables file based logging and specifies the directory
-max-conns int
maximum number of concurrently open connections (default 128)
-root string
server root directory to serve from (default "public")
-timeout int
connection timeout in seconds (default 5)
```