Blob


1 .\" Copyright (c) 2022 Omar Polo <op@omarpolo.com>
2 .\"
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.
6 .\"
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 September 8, 2022
15 .Dt GMID.CONF 5
16 .Os
17 .Sh NAME
18 .Nm gmid.conf
19 .Nd gmid Gemini server configuration file
20 .Sh DESCRIPTION
21 .Nm
22 is the configuration file format for the
23 .Xr gmid 8
24 Gemini server.
25 .Pp
26 The configuration file is divided into three sections:
27 .Bl -tag -width xxxx
28 .It Sy Macros
29 User-defined variables may be defined and used later, simplifying the
30 configuration file.
31 .It Sy Global Options
32 Global settings for
33 .Nm .
34 .It Sy Servers
35 Virtual hosts definition.
36 .It Sy Types
37 Media types and extensions.
38 .El
39 .Pp
40 Within the sections, empty lines are ignored and comments can be put
41 anywhere in the file using a hash mark
42 .Pq Sq # ,
43 and extend to the end of the current line.
44 A boolean is either the symbol
45 .Sq on
46 or
47 .Sq off .
48 A string is a sequence of characters wrapped in double quotes,
49 .Dq like this .
50 Multiple strings one next to the other are joined into a single
51 string:
52 .Bd -literal -offset indent
53 # equivalent to "temporary-failure"
54 block return 40 "temporary" "-" "failure"
55 .Ed
56 .Pp
57 Furthermore, quoting is necessary only when a string needs to contain
58 special characters
59 .Pq like spaces or punctuation ,
60 something that looks like a number or a reserved keyword.
61 The last example could have been written also as:
62 .Bd -literal -offset indent
63 block return 40 temporary "-" failure
64 .Ed
65 .Pp
66 Strict ordering of the sections is not enforced, so that is possible
67 to mix macros, options and
68 .Ic server
69 blocks.
70 However, defining all the
71 .Ic server
72 blocks after the macros and the global options is recommended.
73 .Pp
74 Newlines are often optional, except around top-level instructions, and
75 semicolons
76 .Dq \&;
77 can also be optionally used to separate options.
78 .Pp
79 Additional configuration files can be included with the
80 .Ic include
81 keyword, for example:
82 .Bd -literal -offset indent
83 include "/etc/gmid.conf.local"
84 .Ed
85 .Ss Macros
86 Macros can be defined that will later be expanded in context.
87 Macro names must start with a letter, digit or underscore and may
88 contain any of those characters.
89 Macros names may not be reserved words.
90 Macros are not expanded inside quotes.
91 .Pp
92 Two kinds of macros are supported: variable-like and proper macros.
93 When a macro is invoked with a
94 .Dq $
95 before its name its expanded as a string, whereas when it's invoked
96 with a
97 .Dq @
98 its expanded in-place.
99 .Pp
100 For example:
101 .Bd -literal -offset indent
102 dir = "/var/gemini"
103 certdir = "/etc/keys"
104 common = "lang it; auto index on"
106 server "foo" {
107 root $dir "/foo" # -> /var/gemini/foo
108 cert $certdir "/foo.pem" # -> /etc/keys/foo.pem
109 key $certdir "/foo.key" # -> /etc/keys/foo.key
110 @common
112 .Ed
113 .Ss Global Options
114 .Bl -tag -width 12m
115 .It Ic chroot Ar path
116 .Xr chroot 2
117 the process to the given
118 .Ar path .
119 The daemon has to be run with root privileges and thus the option
120 .Ic user
121 needs to be provided, so privileges can be dropped.
122 Note that
123 .Nm
124 will enter the chroot after loading the TLS keys, but before opening
125 the virtual host root directories.
126 It's recommended to keep the TLS keys outside the chroot.
127 Future version of
128 .Nm
129 may enforce this.
130 .It Ic ipv6 Ar bool
131 Enable or disable IPv6 support, off by default.
132 .It Ic port Ar portno
133 The port to listen on.
134 1965 by default.
135 .It Ic prefork Ar number
136 Run the specified number of server processes.
137 This increases the performance and prevents delays when connecting to
138 a server.
139 When not in config-less mode,
140 .Nm
141 runs 3 server processes by default.
142 The maximum number allowed is 16.
143 .It Ic protocols Ar string
144 Specify the TLS protocols to enable.
145 Refer to
146 .Xr tls_config_parse_protocols 3
147 for the valid protocol string values.
148 By default, both TLSv1.3 and TLSv1.2 are enabled.
149 Use
150 .Dq tlsv1.3
151 to enable only TLSv1.3.
152 .It Ic user Ar string
153 Run the daemon as the given user.
154 .El
155 .Ss Servers
156 Every virtual host is defined by a
157 .Ic server
158 block:
159 .Bl -tag -width Ds
160 .It Ic server Ar hostname Brq ...
161 Match the server name using shell globbing rules.
162 It can be an explicit name,
163 .Ar www.example.com ,
164 or a name including a wildcards,
165 .Ar *.example.com .
166 .El
167 .Pp
168 Followed by a block of options that is enclosed in curly brackets:
169 .Bl -tag -width Ds
170 .It Ic alias Ar name
171 Specify an additional alias
172 .Ar name
173 for this server.
174 .It Ic auto Ic index Ar bool
175 If no index file is found, automatically generate a directory listing.
176 Disabled by default.
177 .It Ic block Op Ic return Ar code Op Ar meta
178 Send a reply and close the connection;
179 by default
180 .Ar code
181 is 40
182 and
183 .Ar meta
184 is
185 .Dq temporary failure .
186 If
187 .Ar code
188 is in the 3x range, then
189 .Ar meta
190 is mandatory.
191 Inside
192 .Ar meta ,
193 the following special sequences are supported:
194 .Bl -tag -width Ds -compact
195 .It \&%\&%
196 is replaced with a single
197 .Sq \&% .
198 .It \&%p
199 is replaced with the request path.
200 .It \&%q
201 is replaced with the query string of the request.
202 .It \&%P
203 is replaced with the server port.
204 .It \&%N
205 is replaced with the server name.
206 .El
207 .It Ic cert Ar file
208 Path to the certificate to use for this server.
209 .Ar file
210 should contain a PEM encoded certificate.
211 This option is mandatory.
212 .It Ic default type Ar string
213 Set the default media type that is used if the media type for a
214 specified extension is not found.
215 If not specified, the
216 .Ic default type
217 is set to
218 .Dq application/octet-stream .
219 .It Ic fastcgi Oo Ic tcp Oc Ar socket Oo Cm port Ar port Oc
220 Enable
221 .Sx FastCGI
222 instead of serving files.
223 The
224 .Ar socket
225 can either be a UNIX-domain socket or a TCP socket.
226 If the FastCGI application is listening on a UNIX domain socket,
227 .Ar socket
228 is a local path name within the
229 .Xr chroot 2
230 root directory of
231 .Nm .
232 Otherwise, the
233 .Ic tcp
234 keyword must be provided and
235 .Ar socket
236 is interpreted as a hostname or an IP address.
237 .Ar port
238 can be either a port number or the name of a service enclosed in
239 double quotes.
240 If not specified defaults to 9000.
241 .It Ic index Ar string
242 Set the directory index file.
243 If not specified, it defaults to
244 .Pa index.gmi .
245 .It Ic key Ar file
246 Specify the private key to use for this server.
247 .Ar file
248 should contain a PEM encoded private key.
249 This option is mandatory.
250 .It Ic lang Ar string
251 Specify the language tag for the text/gemini content served.
252 If not specified, no
253 .Dq lang
254 parameter will be added in the response.
255 .It Ic location Ar path Brq ...
256 Specify server configuration rules for a specific location.
257 .Ar path
258 argument will be matched against the request path with shell globbing
259 rules.
260 In case of multiple location statements in the same context, the first
261 matching location will be put into effect and the later ones ignored.
262 Therefore is advisable to match for more specific paths first and for
263 generic ones later on.
265 .Ic location
266 section may include most of the server configuration rules
267 except
268 .Ic alias , Ic cert , Ic key , Ic location , Ic param No and Ic proxy .
269 .It Ic log Ar bool
270 Enable or disable the logging for the current server or location block.
271 .It Ic param Ar name Cm = Ar value
272 Set the param
273 .Ar name
274 to
275 .Ar value
276 for FastCGI.
277 By default the following parameters are defined:
278 .Bl -tag -width 24m
279 .It Ev GATEWAY_INTERFACE
280 .Dq CGI/1.1
281 .It Ev GEMINI_DOCUMENT_ROOT
282 The root directory of the virtual host.
283 .It Ev GEMINI_SCRIPT_FILENAME
284 Full path to the FastCGI script being executed.
285 .It Ev GEMINI_URL
286 The full IRI of the request.
287 .It Ev GEMINI_URL_PATH
288 The path of the request.
289 .It Ev GEMINI_SEARCH_STRING
290 The decoded
291 .Ev QUERY_STRING
292 if defined in the request and if it doesn't contain any unencoded
293 .Sq =
294 characters, otherwise unset.
295 .It Ev PATH_INFO
296 The portion of the requested path that is derived from the the IRI
297 path hierarchy following the part that identifies the script itself.
298 Can be unset.
299 .It Ev PATH_TRANSLATED
300 Present if and only if
301 .Ev PATH_INFO
302 is set.
303 It represent the translation of the
304 .Ev PATH_INFO .
305 .Nm gmid
306 builds this by appending the
307 .Ev PATH_INFO
308 to the virtual host directory root.
309 .It Ev QUERY_STRING
310 The URL-encoded search or parameter string.
311 .It Ev REMOTE_ADDR , Ev REMOTE_HOST
312 Textual representation of the client IP.
313 .It Ev REQUEST_METHOD
314 This is present only for RFC3875 (CGI) compliance.
315 It's always set to the empty string.
316 .It Ev SCRIPT_NAME
317 The virtual URI path to the script.
318 .It Ev SERVER_NAME
319 The name of the server
320 .It Ev SERVER_PORT
321 The port the server is listening on.
322 .It Ev SERVER_PROTOCOL
323 .Dq GEMINI
324 .It Ev SERVER_SOFTWARE
325 The name and version of the server, i.e.
326 .Dq gmid/1.8.4
327 .It Ev AUTH_TYPE
328 The string "Certificate" if the client used a certificate, otherwise
329 unset.
330 .It Ev REMOTE_USER
331 The subject of the client certificate if provided, otherwise unset.
332 .It Ev TLS_CLIENT_ISSUER
333 The is the issuer of the client certificate if provided, otherwise
334 unset.
335 .It Ev TLS_CLIENT_HASH
336 The hash of the client certificate if provided, otherwise unset.
337 The format is
338 .Dq ALGO:HASH .
339 .It Ev TLS_VERSION
340 The TLS version negotiated with the peer.
341 .It Ev TLS_CIPHER
342 The cipher suite negotiated with the peer.
343 .It Ev TLS_CIPHER_STRENGTH
344 The strength in bits for the symmetric cipher that is being used with
345 the peer.
346 .It Ev TLS_CLIENT_NOT_AFTER
347 The time corresponding to the end of the validity period of the peer
348 certificate in the ISO 8601 format
349 .Pq e.g. Dq 2021-02-07T20:17:41Z .
350 .It Ev TLS_CLIENT_NOT_BEFORE
351 The time corresponding to the start of the validity period of the peer
352 certificate in the ISO 8601 format.
353 .El
354 .It Ic ocsp Ar file
355 Specify an OCSP response to be stapled during TLS handshakes
356 with this server.
357 The
358 .Ar file
359 should contain a DER-format OCSP response retrieved from an
360 OCSP server for the
361 .Ic cert
362 in use.
363 If the OCSP response in
364 .Ar file
365 is empty, OCSP stapling will not be used.
366 The default is to not use OCSP stapling.
367 .It Ic proxy Oo Cm proto Ar name Oc Oo Cm for-host Ar host Oo Cm port Ar port Oc Oc Brq ...
368 Set up a reverse proxy.
369 The optional matching rules
370 .Cm proto
371 and
372 .Cm for-host
373 can be used to enable proxying only for protocols matching
374 .Ar name
375 .Po Dq gemini
376 by default
377 .Pc
378 and/or whose request IRI matches
379 .Ar host
380 and
381 .Ar port
382 .Pq 1965 by default .
383 Matching happens using shell globbing rules.
384 .Pp
385 In case of multiple matching proxy blocks in the same context, the
386 first matching proxy will be put into effect and the later ones
387 ignored.
388 .Pp
389 Valid options are:
390 .Bl -tag -width Ds
391 .It Ic cert Ar file
392 Specify the client certificate to use when making requests.
393 .It Ic key Ar file
394 Specify the client certificate key to use when making requests.
395 .It Ic protocols Ar string
396 Specify the TLS protocols allowed when making remote requests.
397 Refer to the
398 .Xr tls_config_parse_protocols 3
399 function for the valid protocol string values.
400 By default, both TLSv1.2 and TLSv1.3 are enabled.
401 .It Ic relay-to Ar host Op Cm port Ar port
402 Relay the request to the given
403 .Ar host
404 at the given
405 .Ar port ,
406 1965 by default.
407 This is the only mandatory option in a
408 .Ic proxy
409 block.
410 .It Ic require Ic client Ic ca Ar file
411 Allow the proxying only from clients that provide a certificate
412 signed by the CA certificate in
413 .Ar file .
414 .It Ic sni Ar hostname
415 Use the given
416 .Ar hostname
417 instead of the one extracted from the
418 .Ic relay-to
419 rule for the TLS handshake with the proxied gemini server.
420 .It Ic use-tls Ar bool
421 Specify whether to use TLS when connecting to the proxied host.
422 Enabled by default.
423 .It Ic verifyname Ar bool
424 Enable or disable the TLS server name verification.
425 Enabled by default.
426 .El
427 .It Ic root Ar directory
428 Specify the root directory for this server
429 .Pq alas the current Dq document root .
430 It's relative to the chroot if enabled.
431 .It Ic require Ic client Ic ca Ar path
432 Allow requests only from clients that provide a certificate signed by
433 the CA certificate in
434 .Ar path .
435 It needs to be a PEM-encoded certificate and it's not relative to the
436 chroot.
437 .It Ic strip Ar number
438 Strip
439 .Ar number
440 components from the beginning of the path before doing a lookup in the
441 root directory.
442 It's also considered for the
443 .Ar meta
444 parameter in the scope of a
445 .Ic block return .
446 .El
447 .Ss Types
448 The
449 .Ic types
450 section must include one or more lines of the following syntax, enclosed
451 in curly brances:
452 .Bl -tag -width Ds
453 .It Ar type/subtype Ar name Op Ar name ...
454 Set the media
455 .Ar type
456 and
457 .Ar subtype
458 to the specified extension
459 .Ar name .
460 One or more names can be specified per line.
461 Earch line may end with an optional semicolon.
462 .It Ic include Ar file
463 Include types definition from an external file, for example
464 .Pa /usr/share/misc/mime.types .
465 .El
466 .Pp
467 By default
468 .Nm gmid
469 uses the following mapping if no
470 .Ic types
471 block is defined:
472 .Bl -tag -offset indent -width 15m -compact
473 .It application/pdf
474 pdf
475 .It image/gif
476 gif
477 .It image/jpeg
478 jpg jpeg
479 .It image/png
480 png
481 .It image/svg+xml
482 svg
483 .It text/gemini
484 gemini gmi
485 .It text/markdown
486 markdown md
487 .It text/x-patch
488 diff patch
489 .It text/xml
490 xml
491 .El
492 .Pp
493 As an exception,
494 .Nm gmid
495 uses the MIME type
496 .Ar text/gemini
497 for file extensions
498 .Ar gemini
499 or
500 .Ar gmi
501 if no mapping was found.
502 .Sh EXAMPLES
503 The following is an example of a possible configuration for a site
504 that enables only TLSv1.3, adds the MIME types mapping from
505 .Pa /usr/share/misc/mime.types
506 and defines two virtual host:
507 .Bd -literal -offset indent
508 ipv6 on # enable ipv6
510 protocols "tlsv1.3"
512 types {
513 include "/usr/share/misc/mime.types"
516 server "example.com" {
517 cert "/etc/ssl/example.com.pem"
518 key "/etc/ssl/private/example.com.key"
519 root "/var/gemini/example.com"
522 server "example.it" {
523 cert "/etc/ssl/example.it.pem"
524 key "/etc/ssl/private/example.it.key"
525 root "/var/gemini/example.it"
527 # set the language for text/gemini files
528 lang "it"
530 .Ed
531 .Pp
532 Yet another example, showing how to enable a
533 .Ic chroot
534 and use
535 .Ic location
536 rule
537 .Bd -literal -offset indent
538 chroot "/var/gemini"
539 user "_gmid"
541 server "example.com" {
542 # absolute paths:
543 cert "/etc/ssl/example.com.pem"
544 key "/etc/ssl/private/example.com.key"
546 # relative to the chroot:
547 root "/example.com"
549 location "/static/*" {
550 # load the following rules only for
551 # requests that matches "/static/*"
553 auto index on
554 index "index.gemini"
557 .Ed
558 .Sh SEE ALSO
559 .Xr gmid 8 ,
560 .Xr slowcgi 8
561 .Sh AUTHORS
562 .An -nosplit
563 The
564 .Nm gmid
565 program was written by
566 .An Omar Polo Aq Mt op@omarpolo.com .