.gitignorecommits | blame
ChangeLogcommits | blame
INSTALL.gmicommits | blame
LICENSEcommits | blame
Makefilecommits | blame
README.mdcommits | blame
gmid.1commits | blame
gmid.ccommits | blame
gmid.hcommits | blame
uri.ccommits | blame
uri_test.ccommits | blame
utf8.ccommits | blame


**gmid** - dead simple zero configuration gemini server


\[**-c** *cert.pem*]
\[**-d** *docs*]
\[**-k** *key.pem*]
\[**-p** *port*]
\[**-x** *cgi-bin*]


is a very simple and minimal gemini server that can serve static files
and execute CGI scripts.

won't serve files outside the given directory and won't follow
Furthermore, on
are used to ensure that
dosen't do anything else than read files from the given directory,
accept network connections and, optionally, execute CGI scripts.

fully supports IRIs (Internationalized Resource Identifiers, see

It should be noted that
is very simple in its implementation, and so it may not be appropriate
for serving sites with lots of users.
After all, the code is single threaded and use a single process,
although it can handle multiple clients at the same time.

If a user request path is a directory,
will try to serve a
file inside that directory.

The options are as follows:

**-c** *cert.pem*

> The certificate to use, by default is
> *cert.pem*.

**-d** *docs*

> The root directory to serve.
> **gmid**
> won't serve any file that is outside that directory.
> By default is
> *docs*.


> stays and log in the foreground, do not daemonize the process.


> Print the usage and exit.

**-k** *key.pem*

> The key for the certificate, by default is
> *key.pem*.

**-p** *port*

> The port to bind to, by default 1965.

**-x** *dir*

> Enable execution of CGI scripts inside the given directory (relative
> to the document root.)  Cannot be provided more than once.


When CGI scripts are enabled for a directory, a request for an
executable file will execute it and fed its output to the client.

The CGI scripts will inherit the environment from
with these additional variables set:


> "gmid"


> "1965"


> The (public) path to the script.


> The full path to the executable.


> The user request (without the query parameters.)


> The request relative to the script.


> The query parameters.


> The remote IP address.


> The remote IP address.


> The root directory being served, the one provided with the
> *d*
> parameter to
> **gmid**


> The string "Certificate" if the client used a certificate, otherwise unset.


> The subject of the client certificate if provided, otherwise unset.


> The is the issuer of the client certificate if provided, otherwise unset.


> The hash of the client certificate if provided, otherwise unset.
> The format is "ALGO:HASH".

Let's say you have a script in
and the user request is
will be
will be
will be
will be
*foo/bar and*
will be


To quickly getting started

	$ # generate a cert and a key
	$ openssl req -x509 -newkey rsa:4096 -keyout key.pem \
	        -out cert.pem -days 365 -nodes
	$ mkdir docs
	$ cat <<EOF > docs/index.gmi
	# Hello world
	test paragraph...
	$ gmid -c cert.pem -k key.pem -d docs

Now you can visit gemini://localhost/ with your preferred gemini

To add some CGI scripts, assuming a setup similar to the previous
example, you can

	$ mkdir docs/cgi-bin
	$ cat <<EOF > docs/cgi-bin/hello-world
	printf "20 text/plain\r\n"
	echo "hello world!"
	$ gmid -x cgi-bin

Note that the argument to the
option is
and not
since it's relative to the document root.


uses the "Flexible and Economical" UTF-8 decoder written by
Bjoern Hoehrmann.


*	it doesn't support virtual hosts: the host part of the request URL is
	completely ignored.

*	a %2F sequence in the path part is indistinguishable from a literal
	slash: this is not RFC3986-compliant.

*	a %00 sequence either in the path or in the query part is treated as
	invalid character and thus rejected.