4 **gmid** - dead simple zero configuration gemini server
10 \[**-c** *cert.pem*]
12 \[**-k** *key.pem*]
14 \[**-x** *cgi-bin*]
19 is a very simple and minimal gemini server that can serve static files
20 and execute CGI scripts.
23 won't serve files outside the given directory and won't follow
30 are used to ensure that
32 dosen't do anything else than read files from the given directory,
33 accept network connections and, optionally, execute CGI scripts.
36 fully supports IRIs (Internationalized Resource Identifiers, see
39 It should be noted that
41 is very simple in its implementation, and so it may not be appropriate
42 for serving sites with lots of users.
43 After all, the code is single threaded and use a single process,
44 although it can handle multiple clients at the same time.
46 If a user request path is a directory,
50 file inside that directory.
52 The options are as follows:
60 > The certificate to use, by default is
65 > The root directory to serve.
67 > won't serve any file that is outside that directory.
73 > stays and log in the foreground, do not daemonize the process.
77 > Print the usage and exit.
81 > The key for the certificate, by default is
86 > The port to bind to, by default 1965.
90 > Enable execution of CGI scripts inside the given directory (relative
91 > to the document root.) Cannot be provided more than once.
95 When CGI scripts are enabled for a directory, a request for an
96 executable file will execute it and fed its output to the client.
98 The CGI scripts will inherit the environment from
100 with these additional variables set:
112 > The (public) path to the script.
116 > The full path to the executable.
120 > The user request (without the query parameters.)
124 > The request relative to the script.
128 > The query parameters.
132 > The remote IP address.
136 > The remote IP address.
140 > The root directory being served, the one provided with the
147 > The string "Certificate" if the client used a certificate, otherwise unset.
151 > The subject of the client certificate if provided, otherwise unset.
155 > The is the issuer of the client certificate if provided, otherwise unset.
159 > The hash of the client certificate if provided, otherwise unset.
160 > The format is "ALGO:HASH".
162 Let's say you have a script in
164 and the user request is
165 */cgi-bin/script/foo/bar?quux*.
172 *$DOCUMENT\_ROOT/cgi-bin/script*,
175 */cgi-bin/script/foo/bar*,
185 To quickly getting started
187 $ # generate a cert and a key
188 $ openssl req -x509 -newkey rsa:4096 -keyout key.pem \
189 -out cert.pem -days 365 -nodes
191 $ cat <<EOF > docs/index.gmi
195 $ gmid -c cert.pem -k key.pem -d docs
197 Now you can visit gemini://localhost/ with your preferred gemini
200 To add some CGI scripts, assuming a setup similar to the previous
204 $ cat <<EOF > docs/cgi-bin/hello-world
206 printf "20 text/plain\r\n"
211 Note that the argument to the
217 since it's relative to the document root.
222 uses the "Flexible and Economical" UTF-8 decoder written by
227 * it doesn't support virtual hosts: the host part of the request URL is
230 * a %2F sequence in the path part is indistinguishable from a literal
231 slash: this is not RFC3986-compliant.
233 * a %00 sequence either in the path or in the query part is treated as
234 invalid character and thus rejected.