1 .\" Copyright (c) 2020 Omar Polo <op@omarpolo.com>
3 .\" Permission to use, copy, modify, and distribute this software for any
4 .\" purpose with or without fee is hereby granted, provided that the above
5 .\" copyright notice and this permission notice appear in all copies.
7 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 .Dd $Mdocdate: October 2 2020$
19 .Nd dead simple zero configuration gemini server
32 is a very simple and minimal gemini server that can serve static files
33 and execute CGI scripts.
36 won't serve files outside the given directory and won't follow
43 are used to ensure that
45 dosen't do anything else than read files from the given directory,
46 accept network connections and, optionally, execute CGI scripts.
49 fully supports IRIs (Internationalized Resource Identifiers, see
52 It should be noted that
54 is very simple in its implementation, and so it may not be appropriate
55 for serving sites with lots of users.
56 After all, the code is single threaded and use a single process,
57 although it can handle multiple clients at the same time.
59 If a user request path is a directory,
63 file inside that directory.
65 The options are as follows:
68 The certificate to use, by default is
71 The root directory to serve.
73 won't serve any file that is outside that directory.
77 stays and log in the foreground, do not daemonize the process.
79 Print the usage and exit.
81 The key for the certificate, by default is
84 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.
90 When CGI scripts are enabled for a directory, a request for an
91 executable file will execute it and fed its output to the client.
93 The CGI scripts will inherit the environment from
95 with these additional variables set:
97 .It Ev SERVER_SOFTWARE
102 The (public) path to the script.
103 .It Ev SCRIPT_EXECUTABLE
104 The full path to the executable.
106 The user request (without the query parameters.)
107 .It Ev REQUEST_RELATIVE
108 The request relative to the script.
110 The query parameters.
112 The remote IP address.
114 The remote IP address.
116 The root directory being served, the one provided with the
121 The string "Certificate" if the client used a certificate, otherwise unset.
123 The subject of the client certificate if provided, otherwise unset.
124 .It Ev TLS_CLIENT_ISSUER
125 The is the issuer of the client certificate if provided, otherwise unset.
126 .It Ev TLS_CLIENT_HASH
127 The hash of the client certificate if provided, otherwise unset.
128 The format is "ALGO:HASH".
131 Let's say you have a script in
133 and the user request is
134 .Pa /cgi-bin/script/foo/bar?quux .
138 .Pa /cgi-bin/script ,
139 .Ev SCRIPT_EXECUTABLE
141 .Pa $DOCUMENT_ROOT/cgi-bin/script ,
144 .Pa /cgi-bin/script/foo/bar ,
152 To quickly getting started
153 .Bd -literal -offset indent
154 $ # generate a cert and a key
155 $ openssl req -x509 -newkey rsa:4096 -keyout key.pem \\
156 -out cert.pem -days 365 -nodes
158 $ cat <<EOF > docs/index.gmi
162 $ gmid -c cert.pem -k key.pem -d docs
165 Now you can visit gemini://localhost/ with your preferred gemini
168 To add some CGI scripts, assuming a setup similar to the previous
170 .Bd -literal -offset indent
172 $ cat <<EOF > docs/cgi-bin/hello-world
174 printf "20 text/plain\\r\\n"
180 Note that the argument to the
186 since it's relative to the document root.
189 uses the "Flexible and Economical" UTF-8 decoder written by
190 .An Bjoern Hoehrmann .
194 it doesn't support virtual hosts: the host part of the request URL is
197 a %2F sequence in the path part is indistinguishable from a literal
198 slash: this is not RFC3986-compliant.
200 a %00 sequence either in the path or in the query part is treated as
201 invalid character and thus rejected.