Blame


1 f28d96d3 2021-01-25 op .\" Copyright (c) 2021 Omar Polo <op@omarpolo.com>
2 3e4749f7 2020-10-02 op .\"
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.
6 3e4749f7 2020-10-02 op .\"
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 39a7b611 2021-01-30 op .Dd $Mdocdate: January 30 2021$
15 3f47867e 2021-04-16 op .Dt GMID 1
16 3e4749f7 2020-10-02 op .Os
17 3e4749f7 2020-10-02 op .Sh NAME
18 3e4749f7 2020-10-02 op .Nm gmid
19 714685c1 2021-01-30 op .Nd simple and secure Gemini server
20 3e4749f7 2020-10-02 op .Sh SYNOPSIS
21 3e4749f7 2020-10-02 op .Nm
22 3e4749f7 2020-10-02 op .Bk -words
23 38d4db74 2021-02-04 op .Op Fl fnv
24 15902770 2021-01-15 op .Op Fl c Ar config
25 8b743dda 2021-06-29 op .Op Fl D Ar macro Ns = Ns Ar value
26 8e8b2e25 2021-04-28 op .Op Fl P Ar pidfile
27 38d4db74 2021-02-04 op .Ek
28 38d4db74 2021-02-04 op .Nm
29 38d4db74 2021-02-04 op .Bk -words
30 ba65dcc8 2021-06-29 op .Op Fl 6hVv
31 f28d96d3 2021-01-25 op .Op Fl d Pa certs-dir
32 f28d96d3 2021-01-25 op .Op Fl H Ar hostname
33 721e2325 2020-11-18 op .Op Fl p Ar port
34 f28d96d3 2021-01-25 op .Op Fl x Pa cgi
35 f28d96d3 2021-01-25 op .Op Pa dir
36 3e4749f7 2020-10-02 op .Ek
37 3e4749f7 2020-10-02 op .Sh DESCRIPTION
38 3e4749f7 2020-10-02 op .Nm
39 8ff40039 2021-05-24 op is a simple and minimal gemini server that can serve static files,
40 8ff40039 2021-05-24 op execute CGI scripts and talk to FastCGI applications.
41 eb699783 2021-01-18 op It can run without a configuration file with a limited set of features
42 eb699783 2021-01-18 op available.
43 3007f565 2021-02-04 op .Pp
44 3007f565 2021-02-04 op .Nm
45 3007f565 2021-02-04 op rereads the configuration file when it receives
46 3007f565 2021-02-04 op .Dv SIGHUP .
47 3e4749f7 2020-10-02 op .Pp
48 eb699783 2021-01-18 op The options are as follows:
49 f28d96d3 2021-01-25 op .Bl -tag -width 14m
50 eb699783 2021-01-18 op .It Fl c Pa config
51 f28d96d3 2021-01-25 op Specify the configuration file.
52 8b743dda 2021-06-29 op .It Fl D Ar macro Ns = Ns Ar value
53 8b743dda 2021-06-29 op Define
54 8b743dda 2021-06-29 op .Ar macro
55 8b743dda 2021-06-29 op to be set to
56 8b743dda 2021-06-29 op .Ar value
57 8b743dda 2021-06-29 op on the command line.
58 8b743dda 2021-06-29 op Overrides the definition of
59 8b743dda 2021-06-29 op .Ar macro
60 8b743dda 2021-06-29 op in the config file if present.
61 46af8c6c 2021-01-27 op .It Fl f
62 46af8c6c 2021-01-27 op Stays and logs on the foreground.
63 eb699783 2021-01-18 op .It Fl n
64 eb699783 2021-01-18 op Check that the configuration is valid, but don't start the server.
65 8e8b2e25 2021-04-28 op .It Fl P Pa pidfile
66 8e8b2e25 2021-04-28 op Write
67 8e8b2e25 2021-04-28 op .Nm
68 8e8b2e25 2021-04-28 op pid to the given path.
69 eb699783 2021-01-18 op .El
70 3e4749f7 2020-10-02 op .Pp
71 eb699783 2021-01-18 op If no configuration file is given,
72 fab952e1 2020-10-03 op .Nm
73 f28d96d3 2021-01-25 op will look for the following options
74 f28d96d3 2021-01-25 op .Bl -tag -width 14m
75 85dff1f9 2021-01-11 op .It Fl 6
76 85dff1f9 2021-01-11 op Enable IPv6.
77 f28d96d3 2021-01-25 op .It Fl d Pa certs-path
78 f28d96d3 2021-01-25 op Directory where certificates for the config-less mode are stored.
79 f28d96d3 2021-01-25 op By default is
80 f28d96d3 2021-01-25 op .Pa $XDG_DATA_HOME/gmid ,
81 f28d96d3 2021-01-25 op i.e.
82 f28d96d3 2021-01-25 op .Pa ~/.local/share/gmid .
83 71cf3975 2021-01-25 op .It Fl H Ar hostname
84 f28d96d3 2021-01-25 op The hostname, by default
85 f28d96d3 2021-01-25 op .Ar localhost .
86 f28d96d3 2021-01-25 op Certificates for the given
87 f28d96d3 2021-01-25 op .Ar hostname
88 f28d96d3 2021-01-25 op are searched inside the
89 f28d96d3 2021-01-25 op .Pa certs-dir
90 f28d96d3 2021-01-25 op directory given with the
91 f28d96d3 2021-01-25 op .Fl d
92 f28d96d3 2021-01-25 op option.
93 714685c1 2021-01-30 op They have the form
94 f28d96d3 2021-01-25 op .Pa hostname.cert.pem
95 f28d96d3 2021-01-25 op and
96 f28d96d3 2021-01-25 op .Pa hostname.key.pem .
97 1de92289 2021-04-15 op If a certificate or key don't exists for a given hostname they
98 714685c1 2021-01-30 op will be automatically generated.
99 ba65dcc8 2021-06-29 op .It Fl h , Fl -help
100 fab952e1 2020-10-03 op Print the usage and exit.
101 721e2325 2020-11-18 op .It Fl p Ar port
102 eb699783 2021-01-18 op The port to listen on, by default 1965.
103 ba65dcc8 2021-06-29 op .It Fl V , Fl -version
104 ba65dcc8 2021-06-29 op Print the version and exit.
105 8904fa0e 2021-01-27 op .It Fl v
106 3abf91b0 2021-02-07 op Verbose mode.
107 3abf91b0 2021-02-07 op Multiple
108 3abf91b0 2021-02-07 op .Fl v
109 3abf91b0 2021-02-07 op options increase the verbosity.
110 f28d96d3 2021-01-25 op .It Fl x Pa path
111 eb699783 2021-01-18 op Enable execution of CGI scripts.
112 eb699783 2021-01-18 op See the description of the
113 eb699783 2021-01-18 op .Ic cgi
114 eb699783 2021-01-18 op option in the section
115 eb699783 2021-01-18 op .Sq Servers
116 eb699783 2021-01-18 op below to learn how
117 f28d96d3 2021-01-25 op .Pa path
118 eb699783 2021-01-18 op is processed.
119 eb699783 2021-01-18 op Cannot be provided more than once.
120 f28d96d3 2021-01-25 op .It Pa dir
121 f28d96d3 2021-01-25 op The root directory to serve.
122 f28d96d3 2021-01-25 op By default the current working directory is assumed.
123 3e4749f7 2020-10-02 op .El
124 eb699783 2021-01-18 op .Sh CONFIGURATION FILE
125 8b743dda 2021-06-29 op The configuration file is divided into three sections:
126 eb699783 2021-01-18 op .Bl -tag -width xxxx
127 8b743dda 2021-06-29 op .It Sy Macros
128 8b743dda 2021-06-29 op User-defined variables may be defined and used later, simplifying the
129 8b743dda 2021-06-29 op configuration file.
130 eb699783 2021-01-18 op .It Sy Global Options
131 eb699783 2021-01-18 op Global settings for
132 eb699783 2021-01-18 op .Nm .
133 eb699783 2021-01-18 op .It Sy Servers
134 f28d96d3 2021-01-25 op Virtual hosts definition.
135 eb699783 2021-01-18 op .El
136 eb699783 2021-01-18 op .Pp
137 eb699783 2021-01-18 op Within the sections, empty lines are ignored and comments can be put
138 eb699783 2021-01-18 op anywhere in the file using a hash mark
139 eb699783 2021-01-18 op .Pq Sq # ,
140 eb699783 2021-01-18 op and extend to the end of the current line.
141 eb699783 2021-01-18 op A boolean is either the symbol
142 eb699783 2021-01-18 op .Sq on
143 eb699783 2021-01-18 op or
144 eb699783 2021-01-18 op .Sq off .
145 f28d96d3 2021-01-25 op A string is a sequence of characters wrapped in double quotes,
146 f28d96d3 2021-01-25 op .Dq like this .
147 8b743dda 2021-06-29 op .Pp
148 8b743dda 2021-06-29 op Strict ordering of the sections is not enforced, so that is possible
149 8b743dda 2021-06-29 op to mix macros, options and
150 8b743dda 2021-06-29 op .Ic server
151 8b743dda 2021-06-29 op blocks.
152 8b743dda 2021-06-29 op However, defining all the
153 8b743dda 2021-06-29 op .Ic server
154 8b743dda 2021-06-29 op blocks after the macros and the global options is recommended.
155 8b743dda 2021-06-29 op .Ss Macros
156 8b743dda 2021-06-29 op Macros can be defined that will later be expanded in context.
157 8b743dda 2021-06-29 op Macro names must start with a letter, digit or underscore and may
158 8b743dda 2021-06-29 op contain any of those characters.
159 8b743dda 2021-06-29 op Macro names may not be reserved words.
160 8b743dda 2021-06-29 op Macros are expanded inside the quotes too.
161 8b743dda 2021-06-29 op .Pp
162 8b743dda 2021-06-29 op For example:
163 8b743dda 2021-06-29 op .Bd -literal -offset indent
164 8b743dda 2021-06-29 op dir = "/var/gemini"
165 8b743dda 2021-06-29 op cert = "/etc/keys"
166 8b743dda 2021-06-29 op
167 8b743dda 2021-06-29 op server "foo" {
168 8b743dda 2021-06-29 op root "$dir/foo" # -> /var/gemini/foo
169 8b743dda 2021-06-29 op cert "$cert/foo.crt" # -> /etc/keys/foo.crt
170 8b743dda 2021-06-29 op key "$cert/foo.pem" # -> /etc/keys/foo.pem
171 8b743dda 2021-06-29 op }
172 8b743dda 2021-06-29 op .Ed
173 eb699783 2021-01-18 op .Ss Global Options
174 eb699783 2021-01-18 op .Bl -tag -width 12m
175 ae08ec7d 2021-01-25 op .It Ic chroot Pa path
176 ae08ec7d 2021-01-25 op .Xr chroot 2
177 ae08ec7d 2021-01-25 op the process to the given
178 ae08ec7d 2021-01-25 op .Pa path .
179 ae08ec7d 2021-01-25 op The daemon has to be run with root privileges and thus the option
180 ae08ec7d 2021-01-25 op .Ic user
181 714685c1 2021-01-30 op needs to be provided, so privileges can be dropped.
182 714685c1 2021-01-30 op Note that
183 ae08ec7d 2021-01-25 op .Nm
184 714685c1 2021-01-30 op will enter the chroot after loading the TLS keys, but before opening
185 714685c1 2021-01-30 op the virtual host root directories.
186 714685c1 2021-01-30 op It's recommended to keep the TLS keys outside the chroot.
187 ae08ec7d 2021-01-25 op Future version of
188 ae08ec7d 2021-01-25 op .Nm
189 1de92289 2021-04-15 op may enforce this.
190 2b92a447 2021-02-06 op .It Ic ipv6 Ar bool
191 2b92a447 2021-02-06 op Enable or disable IPv6 support.
192 2b92a447 2021-02-06 op By default is off.
193 2b92a447 2021-02-06 op .It Ic mime Ar mime-type Ar file-extension
194 2b92a447 2021-02-06 op Add a mapping for the given
195 2b92a447 2021-02-06 op .Ar file-extension
196 2b92a447 2021-02-06 op to the given
197 2b92a447 2021-02-06 op .Ar mime-type .
198 2b92a447 2021-02-06 op Both argument are strings.
199 2b92a447 2021-02-06 op .It Ic port Ar portno
200 2b92a447 2021-02-06 op The port to listen on.
201 2b92a447 2021-02-06 op By default is 1965.
202 a709ddf5 2021-02-07 op .It Ic prefork Ar number
203 a709ddf5 2021-02-07 op Run the specified number of server processes.
204 a709ddf5 2021-02-07 op This increases the performance and prevents delays when connecting to
205 a709ddf5 2021-02-07 op a server.
206 a709ddf5 2021-02-07 op .Nm
207 a709ddf5 2021-02-07 op runs 3 server processes by default, when not in config-less mode.
208 2c3e53da 2021-03-03 op The maximum number allowed is 16.
209 2b92a447 2021-02-06 op .It Ic protocols Ar string
210 2b92a447 2021-02-06 op Specify the TLS protocols to enable.
211 2b92a447 2021-02-06 op Refer to
212 2b92a447 2021-02-06 op .Xr tls_config_parse_protocols 3
213 2b92a447 2021-02-06 op for the valid protocol string values.
214 2b92a447 2021-02-06 op By default, both TLSv1.3 and TLSv1.2 are enabled.
215 2b92a447 2021-02-06 op Use
216 2b92a447 2021-02-06 op .Dq tlsv1.3
217 2b92a447 2021-02-06 op to enable only TLSv1.3.
218 ae08ec7d 2021-01-25 op .It Ic user Ar string
219 ae08ec7d 2021-01-25 op Run the daemon as the given user.
220 eb699783 2021-01-18 op .El
221 eb699783 2021-01-18 op .Ss Servers
222 eb699783 2021-01-18 op Every virtual host is defined by a
223 eb699783 2021-01-18 op .Ic server
224 eb699783 2021-01-18 op block:
225 eb699783 2021-01-18 op .Bl -tag -width Ds
226 eb699783 2021-01-18 op .It Ic server Ar hostname Brq ...
227 75fbb178 2021-01-28 op Match the server name using shell globbing rules.
228 75fbb178 2021-01-28 op This can be an explicit name,
229 de27389e 2021-01-21 op .Ar www.example.com ,
230 de27389e 2021-01-21 op or a name including a wildcards,
231 de27389e 2021-01-21 op .Ar *.example.com .
232 eb699783 2021-01-18 op .El
233 eb699783 2021-01-18 op .Pp
234 eb699783 2021-01-18 op Followed by a block of options that is enclosed in curly brackets:
235 eb699783 2021-01-18 op .Bl -tag -width Ds
236 cc8c2901 2021-04-29 op .It Ic alias Ar name
237 cc8c2901 2021-04-29 op Specify an additional alias
238 cc8c2901 2021-04-29 op .Ar name
239 cc8c2901 2021-04-29 op for this server.
240 2b92a447 2021-02-06 op .It Ic auto Ic index Ar bool
241 2b92a447 2021-02-06 op If no index file is found, automatically generate a directory listing.
242 2b92a447 2021-02-06 op It's disabled by default.
243 2b92a447 2021-02-06 op .It Ic block Op Ic return Ar code Op Ar meta
244 2b92a447 2021-02-06 op Send a reply and close the connection;
245 2b92a447 2021-02-06 op .Ar code
246 2b92a447 2021-02-06 op is 40
247 2b92a447 2021-02-06 op and
248 2b92a447 2021-02-06 op .Ar meta
249 2b92a447 2021-02-06 op is
250 2b92a447 2021-02-06 op .Dq temporary failure
251 2b92a447 2021-02-06 op by default.
252 2b92a447 2021-02-06 op If
253 2b92a447 2021-02-06 op .Ar code
254 2b92a447 2021-02-06 op is in the 3x range, then
255 2b92a447 2021-02-06 op .Ar meta
256 2b92a447 2021-02-06 op must be provided.
257 2b92a447 2021-02-06 op Inside
258 2b92a447 2021-02-06 op .Ar meta ,
259 2b92a447 2021-02-06 op the following special sequences are replaced:
260 fd1ae83d 2021-06-11 op .Bl -tag -width Ds -compact
261 2b92a447 2021-02-06 op .It \&%\&%
262 2b92a447 2021-02-06 op is replaced with a single
263 2b92a447 2021-02-06 op .Sq \&% .
264 2b92a447 2021-02-06 op .It \&%p
265 2b92a447 2021-02-06 op is replaced with the request path.
266 2b92a447 2021-02-06 op .It \&%q
267 2b92a447 2021-02-06 op is replaced with the query string of the request.
268 2b92a447 2021-02-06 op .It \&%P
269 2b92a447 2021-02-06 op is replaced with the server port.
270 2b92a447 2021-02-06 op .It \&%N
271 2b92a447 2021-02-06 op is replaced with the server name.
272 2b92a447 2021-02-06 op .El
273 eb699783 2021-01-18 op .It Ic cert Pa file
274 eb699783 2021-01-18 op Path to the certificate to use for this server.
275 eb699783 2021-01-18 op The
276 eb699783 2021-01-18 op .Pa file
277 eb699783 2021-01-18 op should contain a PEM encoded certificate.
278 eb699783 2021-01-18 op This option is mandatory.
279 eb699783 2021-01-18 op .It Ic cgi Pa path
280 87f2b68b 2021-02-02 op Execute CGI scripts that matches
281 eb699783 2021-01-18 op .Pa path
282 87f2b68b 2021-02-02 op using shell globbing rules.
283 6119e13e 2021-01-19 op .It Ic default type Ar string
284 6119e13e 2021-01-19 op Set the default media type that is used if the media type for a
285 6119e13e 2021-01-19 op specified extension is not found.
286 6119e13e 2021-01-19 op If not specified, the
287 6119e13e 2021-01-19 op .Ic default type
288 6119e13e 2021-01-19 op is set to
289 6119e13e 2021-01-19 op .Dq application/octet-stream .
290 2b92a447 2021-02-06 op .It Ic entrypoint Pa path
291 dafaf467 2021-04-15 op Handle all the requests for the current virtual host using the
292 dafaf467 2021-04-15 op CGI script at
293 dafaf467 2021-04-15 op .Pa path .
294 9cc630aa 2021-04-28 op .It Ic env Ar name Ar value
295 9cc630aa 2021-04-28 op Set the environment variable
296 9cc630aa 2021-04-28 op .Ar name
297 9cc630aa 2021-04-28 op to
298 9cc630aa 2021-04-28 op .Ar value
299 9cc630aa 2021-04-28 op when executing CGI scripts.
300 9cc630aa 2021-04-28 op Can be provided more than once.
301 8ff40039 2021-05-24 op .\" don't document the "spawn <prog>" form because it probably won't
302 ada16f87 2021-06-11 op .\" be kept.
303 8ff40039 2021-05-24 op .It Ic fastcgi Oo Ic tcp Oc Pa socket Oo Ar port Oc
304 8ff40039 2021-05-24 op Enable FastCGI instead of serving files.
305 8ff40039 2021-05-24 op The
306 8ff40039 2021-05-24 op .Pa socket
307 8ff40039 2021-05-24 op can either be a UNIX domain socket or a TCP socket.
308 8ff40039 2021-05-24 op If the FastCGI application is listening on a UNIX domain socket,
309 8ff40039 2021-05-24 op .Pa socket
310 8ff40039 2021-05-24 op is a local path name within the
311 8ff40039 2021-05-24 op .Xr chroot 2
312 8ff40039 2021-05-24 op root directory of
313 8ff40039 2021-05-24 op .Nm .
314 8ff40039 2021-05-24 op Otherwise, the
315 8ff40039 2021-05-24 op .Ic tcp
316 8ff40039 2021-05-24 op keyword must be provided and
317 8ff40039 2021-05-24 op .Pa socket
318 8ff40039 2021-05-24 op is interpreted as a hostname or an IP address.
319 8ff40039 2021-05-24 op .Ar port
320 8ff40039 2021-05-24 op can be either a port number or the name of a service enclosed in
321 8ff40039 2021-05-24 op double quotes.
322 8ff40039 2021-05-24 op If it's not specified defaults to 9000.
323 2b92a447 2021-02-06 op .It Ic index Ar string
324 2b92a447 2021-02-06 op Set the directory index file.
325 2b92a447 2021-02-06 op If not specified, it defaults to
326 2b92a447 2021-02-06 op .Pa index.gmi .
327 2b92a447 2021-02-06 op .It Ic key Pa file
328 2b92a447 2021-02-06 op Specify the private key to use for this server.
329 2b92a447 2021-02-06 op The
330 2b92a447 2021-02-06 op .Pa file
331 2b92a447 2021-02-06 op should contain a PEM encoded private key.
332 2b92a447 2021-02-06 op This option is mandatory.
333 05c23a54 2021-01-19 op .It Ic lang Ar string
334 05c23a54 2021-01-19 op Specify the language tag for the text/gemini content served.
335 05c23a54 2021-01-19 op If not specified, no
336 05c23a54 2021-01-19 op .Dq lang
337 05c23a54 2021-01-19 op parameter will be added in the response.
338 c8b74339 2021-01-24 op .It Ic location Pa path Brq ...
339 c8b74339 2021-01-24 op Specify server configuration rules for a specific location.
340 c8b74339 2021-01-24 op The
341 c8b74339 2021-01-24 op .Pa path
342 c8b74339 2021-01-24 op argument will be matched against the request path with shell globbing
343 c8b74339 2021-01-24 op rules.
344 6016a593 2021-01-30 op In case of multiple location statements in the same context, the first
345 6016a593 2021-01-30 op matching location will be put into effect and the later ones ignored.
346 6016a593 2021-01-30 op Therefore is advisable to match for more specific paths first and for
347 6016a593 2021-01-30 op generic ones later on.
348 c8b74339 2021-01-24 op A
349 c8b74339 2021-01-24 op .Ic location
350 c8b74339 2021-01-24 op section may include most of the server configuration rules
351 c8b74339 2021-01-24 op except
352 fdea6aa0 2021-04-30 op .Ic alias , Ic cert , Ic env , Ic key , Ic location ,
353 e3ddf390 2021-02-06 op .Ic entrypoint No and Ic cgi .
354 2c43dcce 2021-06-17 op .It Ic log Ar bool
355 2c43dcce 2021-06-17 op Enable or disable the logging for the current server or location block.
356 ada16f87 2021-06-11 op .It Ic param Ar name Ar value
357 ada16f87 2021-06-11 op Set the param
358 ada16f87 2021-06-11 op .Ar name
359 ada16f87 2021-06-11 op to
360 ada16f87 2021-06-11 op .Ar value
361 ada16f87 2021-06-11 op for FastCGI.
362 2b92a447 2021-02-06 op .It Ic root Pa directory
363 2b92a447 2021-02-06 op Specify the root directory for this server.
364 2b92a447 2021-02-06 op It's relative to the chroot, if enabled.
365 02be96c6 2021-02-09 op .It Ic require Ic client Ic ca Pa path
366 02be96c6 2021-02-09 op Allow requests only from clients that provide a certificate signed by
367 02be96c6 2021-02-09 op the CA certificate in
368 02be96c6 2021-02-09 op .Pa path .
369 02be96c6 2021-02-09 op It needs to be a PEM-encoded certificate and it's not relative to the
370 02be96c6 2021-02-09 op chroot.
371 6abda252 2021-02-06 op .It Ic strip Ar number
372 6abda252 2021-02-06 op Strip
373 6abda252 2021-02-06 op .Ar number
374 0773413c 2021-05-15 op components from the beginning of the path before doing a lookup in the
375 0773413c 2021-05-15 op root directory.
376 0773413c 2021-05-15 op It's also considered for the
377 6abda252 2021-02-06 op .Ar meta
378 2b92a447 2021-02-06 op parameter in the scope of a
379 6abda252 2021-02-06 op .Ic block return .
380 6abda252 2021-02-06 op .El
381 72342dc9 2020-11-06 op .Sh CGI
382 87f2b68b 2021-02-02 op When a request for an executable file matches the
383 87f2b68b 2021-02-02 op .Ic cgi
384 87f2b68b 2021-02-02 op rule, that file will be execute and its output fed to the client.
385 72342dc9 2020-11-06 op .Pp
386 ee655e64 2021-02-01 op The CGI scripts are executed in the directory they reside and inherit
387 a7b9bb4d 2021-01-24 op the environment from
388 0ed56567 2020-11-06 op .Nm
389 0ed56567 2020-11-06 op with these additional variables set:
390 ee655e64 2021-02-01 op .Bl -tag -width 24m
391 28ec6178 2021-01-24 op .It Ev GATEWAY_INTERFACE
392 ee655e64 2021-02-01 op .Dq CGI/1.1
393 ee655e64 2021-02-01 op .It Ev GEMINI_DOCUMENT_ROOT
394 ee655e64 2021-02-01 op The root directory of the virtual host.
395 ee655e64 2021-02-01 op .It Ev GEMINI_SCRIPT_FILENAME
396 ee655e64 2021-02-01 op Full path to the CGI script being executed.
397 ee655e64 2021-02-01 op .It Ev GEMINI_URL
398 ee655e64 2021-02-01 op The full IRI of the request.
399 ee655e64 2021-02-01 op .It Ev GEMINI_URL_PATH
400 ee655e64 2021-02-01 op The path of the request.
401 ee655e64 2021-02-01 op .It Ev PATH_INFO
402 ee655e64 2021-02-01 op The portion of the requested path that is derived from the the IRI
403 ee655e64 2021-02-01 op path hierarchy following the part that identifies the script itself.
404 ee655e64 2021-02-01 op Can be unset.
405 ee655e64 2021-02-01 op .It Ev PATH_TRANSLATED
406 ee655e64 2021-02-01 op Present if and only if
407 ee655e64 2021-02-01 op .Ev PATH_INFO
408 ee655e64 2021-02-01 op is set.
409 ee655e64 2021-02-01 op It represent the translation of the
410 ee655e64 2021-02-01 op .Ev PATH_INFO .
411 ee655e64 2021-02-01 op .Nm
412 ee655e64 2021-02-01 op builds this by appending the
413 ee655e64 2021-02-01 op .Ev PATH_INFO
414 ee655e64 2021-02-01 op to the virtual host directory root.
415 ee655e64 2021-02-01 op .It Ev QUERY_STRING
416 ee655e64 2021-02-01 op The decoded query string.
417 ee655e64 2021-02-01 op .It Ev REMOTE_ADDR , Ev REMOTE_HOST
418 ee655e64 2021-02-01 op Textual representation of the client IP.
419 ee655e64 2021-02-01 op .It Ev REQUEST_METHOD
420 ee655e64 2021-02-01 op This is present only for RFC3875 (CGI) compliance.
421 ee655e64 2021-02-01 op It's always set to the empty string.
422 ee655e64 2021-02-01 op .It Ev SCRIPT_NAME
423 ee655e64 2021-02-01 op The part of the
424 ee655e64 2021-02-01 op .Ev GEMINI_URL_PATH
425 ee655e64 2021-02-01 op that identifies the current CGI script.
426 ee655e64 2021-02-01 op .It Ev SERVER_NAME
427 ee655e64 2021-02-01 op The name of the server
428 ee655e64 2021-02-01 op .It Ev SERVER_PORT
429 ee655e64 2021-02-01 op The port the server is listening on.
430 28ec6178 2021-01-24 op .It Ev SERVER_PROTOCOL
431 ee655e64 2021-02-01 op .Dq GEMINI
432 0ed56567 2020-11-06 op .It Ev SERVER_SOFTWARE
433 ee655e64 2021-02-01 op The name and version of the server, i.e.
434 ee655e64 2021-02-01 op .Dq gmid/1.5
435 677afbd3 2020-12-02 op .It Ev AUTH_TYPE
436 28ec6178 2021-01-24 op The string "Certificate" if the client used a certificate, otherwise
437 28ec6178 2021-01-24 op unset.
438 677afbd3 2020-12-02 op .It Ev REMOTE_USER
439 677afbd3 2020-12-02 op The subject of the client certificate if provided, otherwise unset.
440 677afbd3 2020-12-02 op .It Ev TLS_CLIENT_ISSUER
441 28ec6178 2021-01-24 op The is the issuer of the client certificate if provided, otherwise
442 28ec6178 2021-01-24 op unset.
443 677afbd3 2020-12-02 op .It Ev TLS_CLIENT_HASH
444 677afbd3 2020-12-02 op The hash of the client certificate if provided, otherwise unset.
445 ee655e64 2021-02-01 op The format is
446 ee655e64 2021-02-01 op .Dq ALGO:HASH .
447 89541eee 2021-04-13 op .It Ev TLS_VERSION
448 89541eee 2021-04-13 op The TLS version negotiated with the peer.
449 89541eee 2021-04-13 op .It Ev TLS_CIPHER
450 89541eee 2021-04-13 op The cipher suite negotiated with the peer.
451 89541eee 2021-04-13 op .It Ev TLS_CIPHER_STRENGTH
452 89541eee 2021-04-13 op The strength in bits for the symmetric cipher that is being used with
453 89541eee 2021-04-13 op the peer.
454 b63e30ff 2021-02-07 op .It Ev TLS_CLIENT_NOT_AFTER
455 b63e30ff 2021-02-07 op The time corresponding to the end of the validity period of the peer
456 b63e30ff 2021-02-07 op certificate in the ISO 8601 format
457 b63e30ff 2021-02-07 op .Pq e.g. Dq 2021-02-07T20:17:41Z .
458 b63e30ff 2021-02-07 op .It Ev TLS_CLIENT_NOT_BEFORE
459 b63e30ff 2021-02-07 op The time corresponding to the start of the validity period of the peer
460 b63e30ff 2021-02-07 op certificate in the ISO 8601 format.
461 0ed56567 2020-11-06 op .El
462 ada16f87 2021-06-11 op .Sh FastCGI
463 ada16f87 2021-06-11 op .Nm
464 ada16f87 2021-06-11 op optionally supports FastCGI.
465 ada16f87 2021-06-11 op A
466 ada16f87 2021-06-11 op .Ic fastcgi
467 ada16f87 2021-06-11 op rule must be present in a server or location block.
468 ada16f87 2021-06-11 op Then, all requests matching that server or location will be handled
469 ada16f87 2021-06-11 op via the specified FastCGI backend.
470 a5d310bc 2020-11-10 op .Pp
471 ada16f87 2021-06-11 op By default the following variables
472 ada16f87 2021-06-11 op .Pq parameters
473 ada16f87 2021-06-11 op are sent, and carry the same semantics as with CGI.
474 ada16f87 2021-06-11 op More parameters can be added with the
475 ada16f87 2021-06-11 op .Ic param
476 ada16f87 2021-06-11 op option.
477 ada16f87 2021-06-11 op .Bl -bullet -compact
478 ada16f87 2021-06-11 op .It
479 ada16f87 2021-06-11 op GATEWAY_INTERFACE
480 ada16f87 2021-06-11 op .It
481 ada16f87 2021-06-11 op GEMINI_URL_PATH
482 ada16f87 2021-06-11 op .It
483 ada16f87 2021-06-11 op QUERY_STRING
484 ada16f87 2021-06-11 op .It
485 ada16f87 2021-06-11 op REMOTE_ADDR
486 ada16f87 2021-06-11 op .It
487 ada16f87 2021-06-11 op REMOTE_HOST
488 ada16f87 2021-06-11 op .It
489 ada16f87 2021-06-11 op REQUEST_METHOD
490 ada16f87 2021-06-11 op .It
491 ada16f87 2021-06-11 op SERVER_NAME
492 ada16f87 2021-06-11 op .It
493 ada16f87 2021-06-11 op SERVER_PROTOCOL
494 ada16f87 2021-06-11 op .It
495 ada16f87 2021-06-11 op SERVER_SOFTWARE
496 ada16f87 2021-06-11 op .It
497 ada16f87 2021-06-11 op AUTH_TYPE
498 ada16f87 2021-06-11 op .It
499 ada16f87 2021-06-11 op REMOTE_USER
500 ada16f87 2021-06-11 op .It
501 ada16f87 2021-06-11 op TLS_CLIENT_ISSUER
502 ada16f87 2021-06-11 op .It
503 ada16f87 2021-06-11 op TLS_CLIENT_HASH
504 ada16f87 2021-06-11 op .It
505 ada16f87 2021-06-11 op TLS_VERSION
506 ada16f87 2021-06-11 op .It
507 ada16f87 2021-06-11 op TLS_CIPHER
508 ada16f87 2021-06-11 op .It
509 ada16f87 2021-06-11 op TLS_CIPHER_STRENGTH
510 ada16f87 2021-06-11 op .It
511 ada16f87 2021-06-11 op TLS_CLIENT_NOT_BEFORE
512 ada16f87 2021-06-11 op .It
513 ada16f87 2021-06-11 op TLS_CLIENT_NOT_AFTER
514 ada16f87 2021-06-11 op .El
515 75fbb178 2021-01-28 op .Sh MIME
516 75fbb178 2021-01-28 op To auto-detect the MIME type of the response
517 75fbb178 2021-01-28 op .Nm
518 75fbb178 2021-01-28 op looks at the file extension and consults its internal table.
519 75fbb178 2021-01-28 op By default the following mappings are loaded, but they can be
520 75fbb178 2021-01-28 op overridden or extended using the
521 75fbb178 2021-01-28 op .Ic mime
522 75fbb178 2021-01-28 op configuration option.
523 75fbb178 2021-01-28 op If no MIME is found, the value of
524 75fbb178 2021-01-28 op .Ic default type
525 75fbb178 2021-01-28 op matching the file
526 75fbb178 2021-01-28 op .Ic location
527 75fbb178 2021-01-28 op will be used, which is
528 75fbb178 2021-01-28 op .Dq application/octet-stream
529 75fbb178 2021-01-28 op by default.
530 75fbb178 2021-01-28 op .Pp
531 75fbb178 2021-01-28 op .Bl -tag -offset indent -width 14m -compact
532 4d820b6c 2021-04-21 op .It diff
533 4d820b6c 2021-04-21 op text/x-patch
534 75fbb178 2021-01-28 op .It gemini, gmi
535 75fbb178 2021-01-28 op text/gemini
536 75fbb178 2021-01-28 op .It gif
537 75fbb178 2021-01-28 op image/gif
538 75fbb178 2021-01-28 op .It jpeg
539 75fbb178 2021-01-28 op image/jpeg
540 75fbb178 2021-01-28 op .It jpg
541 75fbb178 2021-01-28 op image/jpeg
542 75fbb178 2021-01-28 op .It markdown, md
543 75fbb178 2021-01-28 op text/markdown
544 4d820b6c 2021-04-21 op .It patch
545 4d820b6c 2021-04-21 op text/x-patch
546 75fbb178 2021-01-28 op .It pdf
547 75fbb178 2021-01-28 op application/pdf
548 75fbb178 2021-01-28 op .It png
549 75fbb178 2021-01-28 op image/png
550 75fbb178 2021-01-28 op .It svg
551 75fbb178 2021-01-28 op image/svg+xml
552 75fbb178 2021-01-28 op .It txt
553 75fbb178 2021-01-28 op text/plain
554 75fbb178 2021-01-28 op .It xml
555 75fbb178 2021-01-28 op text/xml
556 75fbb178 2021-01-28 op .El
557 3e4749f7 2020-10-02 op .Sh EXAMPLES
558 f28d96d3 2021-01-25 op Serve the current directory
559 6980aad6 2020-10-02 op .Bd -literal -offset indent
560 f28d96d3 2021-01-25 op $ gmid .
561 6980aad6 2020-10-02 op .Ed
562 3e4749f7 2020-10-02 op .Pp
563 f28d96d3 2021-01-25 op To serve the directory
564 f28d96d3 2021-01-25 op .Pa docs
565 f28d96d3 2021-01-25 op and enable CGI scripts inside
566 f28d96d3 2021-01-25 op .Pa docs/cgi ,
567 f28d96d3 2021-01-25 op you can
568 0ed56567 2020-11-06 op .Bd -literal -offset indent
569 f28d96d3 2021-01-25 op $ mkdir docs/cgi
570 b7a99061 2021-04-15 op $ cat <<EOF > docs/cgi/hello
571 0ed56567 2020-11-06 op #!/bin/sh
572 0ed56567 2020-11-06 op printf "20 text/plain\\r\\n"
573 f28d96d3 2021-01-25 op echo "hello world"
574 0ed56567 2020-11-06 op EOF
575 f28d96d3 2021-01-25 op $ chmod +x docs/cgi/hello
576 b890467e 2021-03-20 op $ gmid -x '/cgi/*' docs
577 0ed56567 2020-11-06 op .Ed
578 0ed56567 2020-11-06 op .Pp
579 eb699783 2021-01-18 op The following is an example of a possible configuration for a site
580 eb699783 2021-01-18 op that enables only TLSv1.3, adds a mime type for the file extension
581 eb699783 2021-01-18 op "rtf" and defines two virtual host:
582 eb699783 2021-01-18 op .Bd -literal -offset indent
583 eb699783 2021-01-18 op ipv6 on # enable ipv6
584 eb699783 2021-01-18 op
585 eb699783 2021-01-18 op protocols "tlsv1.3"
586 eb699783 2021-01-18 op
587 eb699783 2021-01-18 op mime "application/rtf" "rtf"
588 eb699783 2021-01-18 op
589 eb699783 2021-01-18 op server "example.com" {
590 eb699783 2021-01-18 op cert "/path/to/cert.pem"
591 eb699783 2021-01-18 op key "/path/to/key.pem"
592 eb699783 2021-01-18 op root "/var/gemini/example.com"
593 eb699783 2021-01-18 op }
594 eb699783 2021-01-18 op
595 eb699783 2021-01-18 op server "it.example.com" {
596 eb699783 2021-01-18 op cert "/path/to/cert.pem"
597 eb699783 2021-01-18 op key "/path/to/key.pem"
598 eb699783 2021-01-18 op root "/var/gemini/it.example.com"
599 87f2b68b 2021-02-02 op cgi "/cgi-bin/*"
600 de27389e 2021-01-21 op lang "it"
601 eb699783 2021-01-18 op }
602 eb699783 2021-01-18 op .Ed
603 f28d96d3 2021-01-25 op .Pp
604 f28d96d3 2021-01-25 op Yet another example, showing how to enable a
605 f28d96d3 2021-01-25 op .Ic chroot
606 f28d96d3 2021-01-25 op and use
607 f28d96d3 2021-01-25 op .Ic location
608 f28d96d3 2021-01-25 op rule
609 f28d96d3 2021-01-25 op .Bd -literal -offset indent
610 f28d96d3 2021-01-25 op chroot "/var/gemini"
611 f28d96d3 2021-01-25 op user "_gmid"
612 f28d96d3 2021-01-25 op
613 f28d96d3 2021-01-25 op server "example.com" {
614 f28d96d3 2021-01-25 op cert "/path/to/cert.pem"
615 f28d96d3 2021-01-25 op key "/path/to/key.pem"
616 714685c1 2021-01-30 op root "/example.com" # in the /var/gemini chroot
617 f28d96d3 2021-01-25 op
618 4ee08bd1 2021-02-03 op location "/static/*" {
619 f28d96d3 2021-01-25 op auto index on
620 f28d96d3 2021-01-25 op index "index.gemini"
621 f28d96d3 2021-01-25 op }
622 f28d96d3 2021-01-25 op }
623 f28d96d3 2021-01-25 op .Ed
624 ef04b551 2021-01-09 op .Sh ACKNOWLEDGEMENTS
625 ef04b551 2021-01-09 op .Nm
626 eb699783 2021-01-18 op uses the
627 eb699783 2021-01-18 op .Dq Flexible and Economical
628 eb699783 2021-01-18 op UTF-8 decoder written by
629 f28d96d3 2021-01-25 op .An Bjoern Hoehrmann .
630 714685c1 2021-01-30 op .Sh AUTHORS
631 714685c1 2021-01-30 op .An -nosplit
632 714685c1 2021-01-30 op The
633 714685c1 2021-01-30 op .Nm
634 714685c1 2021-01-30 op program was written by
635 714685c1 2021-01-30 op .An Omar Polo Aq Mt op@omarpolo.com .
636 3e4749f7 2020-10-02 op .Sh CAVEATS
637 3e4749f7 2020-10-02 op .Bl -bullet
638 3e4749f7 2020-10-02 op .It
639 eb699783 2021-01-18 op The root directories of all virtual hosts are opened during the daemon
640 eb699783 2021-01-18 op startup; this means that if a root directory gets deleted and then
641 eb699783 2021-01-18 op re-created,
642 eb699783 2021-01-18 op .Nm
643 eb699783 2021-01-18 op won't be able to serve files inside that directory until a restart.
644 eb699783 2021-01-18 op This restriction applies only to the root directories and not their content.
645 043acc97 2020-12-25 op .It
646 714685c1 2021-01-30 op a %2F sequence is indistinguishable from a literal slash: this is not
647 714685c1 2021-01-30 op RFC3986-compliant.
648 00781742 2020-12-25 op .It
649 714685c1 2021-01-30 op a %00 sequence is treated as invalid character and thus rejected.
650 3e4749f7 2020-10-02 op .El