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:
56 > The certificate to use, by default is
61 > The root directory to serve.
63 > won't serve any file that is outside that directory.
69 > stays and log in the foreground, do not daemonize the process.
73 > Print the usage and exit.
77 > The key for the certificate, by default is
82 > The port to bind to, by default 1965.
86 > Enable execution of CGI scripts inside the given directory (relative
87 > to the document root.) Cannot be provided more than once.
91 When CGI scripts are enabled for a directory, a request for an
92 executable file will execute it and fed its output to the client.
94 The CGI scripts will inherit the environment from
96 with these additional variables set:
108 > The (public) path to the script.
112 > The full path to the executable.
116 > The user request (without the query parameters.)
120 > The request relative to the script.
124 > The query parameters.
128 > The remote IP address.
132 > The remote IP address.
136 > The root directory being served, the one provided with the
143 > The string "Certificate" if the client used a certificate, otherwise unset.
147 > The subject of the client certificate if provided, otherwise unset.
151 > The is the issuer of the client certificate if provided, otherwise unset.
155 > The hash of the client certificate if provided, otherwise unset.
156 > The format is "ALGO:HASH".
158 Let's say you have a script in
160 and the user request is
161 */cgi-bin/script/foo/bar?quux*.
168 *$DOCUMENT\_ROOT/cgi-bin/script*,
171 */cgi-bin/script/foo/bar*,
181 To quickly getting started
183 $ # generate a cert and a key
184 $ openssl req -x509 -newkey rsa:4096 -keyout key.pem \
185 -out cert.pem -days 365 -nodes
187 $ cat <<EOF > docs/index.gmi
191 $ gmid -c cert.pem -k key.pem -d docs
193 Now you can visit gemini://localhost/ with your preferred gemini
196 To add some CGI scripts, assuming a setup similar to the previous
200 $ cat <<EOF > docs/cgi-bin/hello-world
202 printf "20 text/plain\r\n"
207 Note that the argument to the
213 since it's relative to the document root.
218 uses the "Flexible and Economical" UTF-8 decoder written by
223 * it doesn't support virtual hosts: the host part of the request URL is
226 * a %2F sequence in the path part is indistinguishable from a literal
227 slash: this is not RFC3986-compliant.
229 * a %00 sequence either in the path or in the query part is treated as
230 invalid character and thus rejected.