1 3e4749f7 2020-10-02 op .\" Copyright (c) 2020 Omar Polo <op@omarpolo.com>
3 3e4749f7 2020-10-02 op .\" Permission to use, copy, modify, and distribute this software for any
4 3e4749f7 2020-10-02 op .\" purpose with or without fee is hereby granted, provided that the above
5 3e4749f7 2020-10-02 op .\" copyright notice and this permission notice appear in all copies.
7 3e4749f7 2020-10-02 op .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 3e4749f7 2020-10-02 op .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 3e4749f7 2020-10-02 op .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 3e4749f7 2020-10-02 op .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 3e4749f7 2020-10-02 op .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 3e4749f7 2020-10-02 op .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 3e4749f7 2020-10-02 op .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 3e4749f7 2020-10-02 op .Dd $Mdocdate: October 2 2020$
19 fab952e1 2020-10-03 op .Nd dead simple zero configuration gemini server
24 3e4749f7 2020-10-02 op .Op Fl c Ar cert.pem
25 3e4749f7 2020-10-02 op .Op Fl d Ar docs
26 3e4749f7 2020-10-02 op .Op Fl k Ar key.pem
27 0ed56567 2020-11-06 op .Op Fl l Ar logfile
28 721e2325 2020-11-18 op .Op Fl p Ar port
29 0ed56567 2020-11-06 op .Op Fl x Ar cgi-bin
31 3e4749f7 2020-10-02 op .Sh DESCRIPTION
33 0ed56567 2020-11-06 op is a very simple and minimal gemini server that can serve static files
34 0ed56567 2020-11-06 op and execute CGI scripts.
37 3e4749f7 2020-10-02 op will strip any sequence of
41 a5d310bc 2020-11-10 op in the requests made by clients and will refuse to follow symlinks.
42 6980aad6 2020-10-02 op Furthermore, on
47 3e4749f7 2020-10-02 op are used to ensure that
49 0ed56567 2020-11-06 op dosen't do anything else than read files from the given directory,
50 0ed56567 2020-11-06 op accept network connections and, optionally, execute CGI scripts.
52 3e4749f7 2020-10-02 op It should be noted that
54 3e4749f7 2020-10-02 op is very simple in its implementation, and so it may not be appropriate
55 0ed56567 2020-11-06 op for serving sites with lots of users.
56 0ed56567 2020-11-06 op After all, the code is single threaded and use a single process,
57 0ed56567 2020-11-06 op although it can handle multiple requests concurrently.
59 fab952e1 2020-10-03 op If a user request path is a directory,
61 fab952e1 2020-10-03 op will try to serve a
63 fab952e1 2020-10-03 op file inside that directory.
65 3e4749f7 2020-10-02 op The options are as follows:
66 3e4749f7 2020-10-02 op .Bl -tag -width 12m
67 3e4749f7 2020-10-02 op .It Fl c Ar cert.pem
68 3e4749f7 2020-10-02 op The certificate to use, by default is
69 fab952e1 2020-10-03 op .Pa cert.pem .
70 3e4749f7 2020-10-02 op .It Fl d Ar docs
71 3e4749f7 2020-10-02 op The root directory to serve.
73 a5d310bc 2020-11-10 op won't serve any file that is outside that directory.
77 fab952e1 2020-10-03 op Print the usage and exit.
78 3e4749f7 2020-10-02 op .It Fl k Ar key.pem
79 3e4749f7 2020-10-02 op The key for the certificate, by default is
81 0ed56567 2020-11-06 op .It Fl l Ar logfile
82 2c3a40fa 2020-11-06 op log to the given file instead of the standard error.
83 721e2325 2020-11-18 op .It Fl p Ar port
84 721e2325 2020-11-18 op The port to bind to, by default 1965.
85 0ed56567 2020-11-06 op .It Fl x Ar dir
86 0ed56567 2020-11-06 op Enable execution of CGI scripts inside the given directory (relative
87 0ed56567 2020-11-06 op to the document root.) Cannot be provided more than once.
90 0ed56567 2020-11-06 op When CGI scripts are enabled for a directory, a request for an
91 0ed56567 2020-11-06 op executable file will execute it and fed its output to the client.
93 0ed56567 2020-11-06 op The CGI scripts will inherit the environment from
95 0ed56567 2020-11-06 op with these additional variables set:
96 a5d310bc 2020-11-10 op .Bl -tag -width 18m
97 0ed56567 2020-11-06 op .It Ev SERVER_SOFTWARE
99 0ed56567 2020-11-06 op .It Ev SERVER_PORT
101 a5d310bc 2020-11-10 op .It Ev SCRIPT_NAME
102 a5d310bc 2020-11-10 op The (public) path to the script.
103 a5d310bc 2020-11-10 op .It Ev SCRIPT_EXECUTABLE
104 a5d310bc 2020-11-10 op The full path to the executable.
105 a5d310bc 2020-11-10 op .It Ev REQUEST_URI
106 a5d310bc 2020-11-10 op The user request (without the query parameters.)
107 a5d310bc 2020-11-10 op .It Ev REQUEST_RELATIVE
108 a5d310bc 2020-11-10 op The request relative to the script.
109 0ed56567 2020-11-06 op .It Ev QUERY_STRING
110 a5d310bc 2020-11-10 op The query parameters.
111 a5d310bc 2020-11-10 op .It Ev REMOTE_HOST
112 a5d310bc 2020-11-10 op The remote IP address.
113 a5d310bc 2020-11-10 op .It Ev DOCUMENT_ROOT
114 a5d310bc 2020-11-10 op The root directory being served, the one provided with the
120 a5d310bc 2020-11-10 op Let's say you have a script in
121 a5d310bc 2020-11-10 op .Pa /cgi-bin/script
122 a5d310bc 2020-11-10 op and the user request is
123 a5d310bc 2020-11-10 op .Pa /cgi-bin/script/foo/bar?quux .
125 a5d310bc 2020-11-10 op .Ev SCRIPT_NAME
127 a5d310bc 2020-11-10 op .Pa /cgi-bin/script ,
128 a5d310bc 2020-11-10 op .Ev SCRIPT_EXECUTABLE
130 a5d310bc 2020-11-10 op .Pa $DOCUMENT_ROOT/cgi-bin/script ,
131 a5d310bc 2020-11-10 op .Ev REQUEST_URI
133 a5d310bc 2020-11-10 op .Pa /cgi-bin/script/foo/bar ,
134 a5d310bc 2020-11-10 op .Ev REQUEST_RELATIVE
136 a5d310bc 2020-11-10 op .Pa foo/bar and
137 a5d310bc 2020-11-10 op .Ev QUERY_STRING
141 3e4749f7 2020-10-02 op To quickly getting started
142 6980aad6 2020-10-02 op .Bd -literal -offset indent
143 3e4749f7 2020-10-02 op $ # generate a cert and a key
144 3e4749f7 2020-10-02 op $ openssl req -x509 -newkey rsa:4096 -keyout key.pem \\
145 3e4749f7 2020-10-02 op -out cert.pem -days 365 -nodes
147 3e4749f7 2020-10-02 op $ cat <<EOF > docs/index.gmi
148 3e4749f7 2020-10-02 op # Hello world
149 3e4749f7 2020-10-02 op test paragraph...
151 3e4749f7 2020-10-02 op $ gmid -c cert.pem -k key.pem -d docs
154 0ed56567 2020-11-06 op Now you can visit gemini://localhost/ with your preferred gemini
157 0ed56567 2020-11-06 op To add some CGI scripts, assuming a setup similar to the previous
158 0ed56567 2020-11-06 op example, you can
159 0ed56567 2020-11-06 op .Bd -literal -offset indent
160 0ed56567 2020-11-06 op $ mkdir docs/cgi-bin
161 0ed56567 2020-11-06 op $ cat <<EOF > docs/cgi-bin/hello-world
163 0ed56567 2020-11-06 op printf "20 text/plain\\r\\n"
164 0ed56567 2020-11-06 op echo "hello world!"
166 0ed56567 2020-11-06 op $ gmid -x cgi-bin
169 0ed56567 2020-11-06 op Note that the argument to the
174 0ed56567 2020-11-06 op .Pa docs/cgi-bin ,
175 a5d310bc 2020-11-10 op since it's relative to the document root.
179 fab952e1 2020-10-03 op it doesn't support virtual hosts: the host part of the request URL is
180 3e4749f7 2020-10-02 op completely ignored.
182 3e4749f7 2020-10-02 op it doesn't fork in the background or anything like that.