Blob


1 .\" Copyright (c) 2022, 2023 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 June 24, 2023
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 the following sections:
27 .Bl -tag -width Ds
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 .Xr gmid 8 .
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 too, so privileges can be dropped afterwards.
122 All the paths in the configuration file are relative to the chroot
123 directory, except for the
124 .Ic cert ,
125 .Ic key
126 and
127 .Ic ocsp
128 paths.
129 Defaults to the
130 .Ic user
131 home directory, if provided.
132 .It Ic prefork Ar number
133 Run the specified number of server processes.
134 This increases the performance and prevents delays when connecting to
135 a server.
136 .Xr gmid 8
137 runs 3 server processes by default.
138 The maximum number allowed is 16.
139 .It Ic protocols Ar string
140 Specify the TLS protocols to enable.
141 Refer to
142 .Xr tls_config_parse_protocols 3
143 for the valid protocol string values.
144 By default, both TLSv1.3 and TLSv1.2 are enabled.
145 Use
146 .Dq tlsv1.3
147 to enable only TLSv1.3.
148 .It Ic user Ar string
149 Run the daemon as the given user.
150 .El
151 .Ss Servers
152 Every virtual host is defined by a
153 .Ic server
154 block:
155 .Bl -tag -width Ds
156 .It Ic server Ar hostname Brq ...
157 Match the server name using shell globbing rules.
158 It can be an explicit name,
159 .Ar www.example.com ,
160 or a name including a wildcards,
161 .Ar *.example.com .
162 .El
163 .Pp
164 Followed by a block of options that is enclosed in curly brackets:
165 .Bl -tag -width Ds
166 .It Ic alias Ar name
167 Specify an additional alias
168 .Ar name
169 for this server.
170 .It Ic auto Ic index Ar bool
171 If no index file is found, automatically generate a directory listing.
172 Disabled by default.
173 .It Ic block Op Ic return Ar code Op Ar meta
174 Send a reply and close the connection;
175 by default
176 .Ar code
177 is 40
178 and
179 .Ar meta
180 is
181 .Dq temporary failure .
182 If
183 .Ar code
184 is in the 3x range, then
185 .Ar meta
186 is mandatory.
187 Inside
188 .Ar meta ,
189 the following special sequences are supported:
190 .Bl -tag -width Ds -compact
191 .It \&%\&%
192 is replaced with a single
193 .Sq \&% .
194 .It \&%p
195 is replaced with the request path.
196 .It \&%q
197 is replaced with the query string of the request.
198 .It \&%P
199 is replaced with the server port.
200 .It \&%N
201 is replaced with the server name.
202 .El
203 .It Ic cert Ar file
204 Path to the certificate to use for this server.
205 .Ar file
206 should contain a PEM encoded certificate.
207 This option is mandatory.
208 .It Ic default type Ar string
209 Set the default media type that is used if the media type for a
210 specified extension is not found.
211 If not specified, the
212 .Ic default type
213 is set to
214 .Dq application/octet-stream .
215 .It Ic fastcgi Oo Ic tcp Oc Ar socket Oo Cm port Ar port Oc
216 Enable
217 .Sx FastCGI
218 instead of serving files.
219 The
220 .Ar socket
221 can either be a UNIX-domain socket or a TCP socket.
222 If the FastCGI application is listening on a UNIX domain socket,
223 .Ar socket
224 is a local path name within the
225 .Xr chroot 2
226 root directory of
227 .Nm .
228 Otherwise, the
229 .Ic tcp
230 keyword must be provided and
231 .Ar socket
232 is interpreted as a hostname or an IP address.
233 .Ar port
234 can be either a port number or the name of a service enclosed in
235 double quotes.
236 If not specified defaults to 9000.
237 .It Ic index Ar string
238 Set the directory index file.
239 If not specified, it defaults to
240 .Pa index.gmi .
241 .It Ic key Ar file
242 Specify the private key to use for this server.
243 .Ar file
244 should contain a PEM encoded private key.
245 This option is mandatory.
246 .It Ic lang Ar string
247 Specify the language tag for the text/gemini content served.
248 If not specified, no
249 .Dq lang
250 parameter will be added in the response.
251 .It Ic listen on Ar address Ic port Ar number
252 Set the listen address and port.
253 This statement can be specified multiple times.
254 If
255 .Ar address
256 is
257 .Sq *
258 then
259 .Xr gmid 8
260 will listen on all IPv4 and IPv6 addresses.
261 .Ar 0.0.0.0
262 means to listen on all IPv4 addresses and
263 .Ar ::
264 all IPv6 addresses.
265 .It Ic location Ar path Brq ...
266 Specify server configuration rules for a specific location.
267 .Ar path
268 argument will be matched against the request path with shell globbing
269 rules.
270 In case of multiple location statements in the same context, the first
271 matching location will be put into effect and the later ones ignored.
272 Therefore is advisable to match for more specific paths first and for
273 generic ones later on.
275 .Ic location
276 section may include most of the server configuration rules
277 except
278 .Ic alias , Ic cert , Ic key , Ic listen , Ic location , Ic param
279 and
280 .Ic proxy .
281 .It Ic log Ar bool
282 Enable or disable the logging for the current server or location block.
283 .It Ic param Ar name Cm = Ar value
284 Set the param
285 .Ar name
286 to
287 .Ar value
288 for FastCGI.
289 By default the following parameters are defined:
290 .Bl -tag -width 24m
291 .It Ev GATEWAY_INTERFACE
292 .Dq CGI/1.1
293 .It Ev GEMINI_DOCUMENT_ROOT
294 The root directory of the virtual host.
295 .It Ev GEMINI_SCRIPT_FILENAME
296 Full path to the FastCGI script being executed.
297 .It Ev GEMINI_URL
298 The full IRI of the request.
299 .It Ev GEMINI_URL_PATH
300 The path of the request.
301 .It Ev GEMINI_SEARCH_STRING
302 The decoded
303 .Ev QUERY_STRING
304 if defined in the request and if it doesn't contain any unencoded
305 .Sq =
306 characters, otherwise unset.
307 .It Ev PATH_INFO
308 The portion of the requested path that is derived from the the IRI
309 path hierarchy following the part that identifies the script itself.
310 Can be unset.
311 .It Ev PATH_TRANSLATED
312 Present if and only if
313 .Ev PATH_INFO
314 is set.
315 It represent the translation of the
316 .Ev PATH_INFO .
317 .Nm gmid
318 builds this by appending the
319 .Ev PATH_INFO
320 to the virtual host directory root.
321 .It Ev QUERY_STRING
322 The URL-encoded search or parameter string.
323 .It Ev REMOTE_ADDR , Ev REMOTE_HOST
324 Textual representation of the client IP.
325 .It Ev REQUEST_METHOD
326 This is present only for RFC3875 (CGI) compliance.
327 It's always set to the empty string.
328 .It Ev SCRIPT_NAME
329 The virtual URI path to the script.
330 .It Ev SERVER_NAME
331 The name of the server
332 .It Ev SERVER_PORT
333 The port the server is listening on.
334 .It Ev SERVER_PROTOCOL
335 .Dq GEMINI
336 .It Ev SERVER_SOFTWARE
337 The name and version of the server, i.e.
338 .Dq gmid/1.8.4
339 .It Ev AUTH_TYPE
340 The string "Certificate" if the client used a certificate, otherwise
341 unset.
342 .It Ev REMOTE_USER
343 The subject of the client certificate if provided, otherwise unset.
344 .It Ev TLS_CLIENT_ISSUER
345 The is the issuer of the client certificate if provided, otherwise
346 unset.
347 .It Ev TLS_CLIENT_HASH
348 The hash of the client certificate if provided, otherwise unset.
349 The format is
350 .Dq ALGO:HASH .
351 .It Ev TLS_VERSION
352 The TLS version negotiated with the peer.
353 .It Ev TLS_CIPHER
354 The cipher suite negotiated with the peer.
355 .It Ev TLS_CIPHER_STRENGTH
356 The strength in bits for the symmetric cipher that is being used with
357 the peer.
358 .It Ev TLS_CLIENT_NOT_AFTER
359 The time corresponding to the end of the validity period of the peer
360 certificate in the ISO 8601 format
361 .Pq e.g. Dq 2021-02-07T20:17:41Z .
362 .It Ev TLS_CLIENT_NOT_BEFORE
363 The time corresponding to the start of the validity period of the peer
364 certificate in the ISO 8601 format.
365 .El
366 .It Ic ocsp Ar file
367 Specify an OCSP response to be stapled during TLS handshakes
368 with this server.
369 The
370 .Ar file
371 should contain a DER-format OCSP response retrieved from an
372 OCSP server for the
373 .Ic cert
374 in use.
375 If the OCSP response in
376 .Ar file
377 is empty, OCSP stapling will not be used.
378 The default is to not use OCSP stapling.
379 .It Ic proxy Oo Cm proto Ar name Oc Oo Cm for-host Ar host Oo Cm port Ar port Oc Oc Brq ...
380 Set up a reverse proxy.
381 The optional matching rules
382 .Cm proto
383 and
384 .Cm for-host
385 can be used to enable proxying only for protocols matching
386 .Ar name
387 .Po Dq gemini
388 by default
389 .Pc
390 and/or whose request IRI matches
391 .Ar host
392 and
393 .Ar port
394 .Pq 1965 by default .
395 Matching happens using shell globbing rules.
396 .Pp
397 In case of multiple matching proxy blocks in the same context, the
398 first matching proxy will be put into effect and the later ones
399 ignored.
400 .Pp
401 Valid options are:
402 .Bl -tag -width Ds
403 .It Ic cert Ar file
404 Specify the client certificate to use when making requests.
405 .It Ic key Ar file
406 Specify the client certificate key to use when making requests.
407 .It Ic protocols Ar string
408 Specify the TLS protocols allowed when making remote requests.
409 Refer to the
410 .Xr tls_config_parse_protocols 3
411 function for the valid protocol string values.
412 By default, both TLSv1.2 and TLSv1.3 are enabled.
413 .It Ic relay-to Ar host Op Cm port Ar port
414 Relay the request to the given
415 .Ar host
416 at the given
417 .Ar port ,
418 1965 by default.
419 This is the only mandatory option in a
420 .Ic proxy
421 block.
422 .It Ic require Ic client Ic ca Ar file
423 Allow the proxying only from clients that provide a certificate
424 signed by the CA certificate in
425 .Ar file .
426 .It Ic sni Ar hostname
427 Use the given
428 .Ar hostname
429 instead of the one extracted from the
430 .Ic relay-to
431 rule for the TLS handshake with the proxied gemini server.
432 .It Ic use-tls Ar bool
433 Specify whether to use TLS when connecting to the proxied host.
434 Enabled by default.
435 .It Ic verifyname Ar bool
436 Enable or disable the TLS server name verification.
437 Enabled by default.
438 .El
439 .It Ic root Ar directory
440 Specify the root directory for this server
441 .Pq alas the current Dq document root .
442 It's relative to the chroot if enabled.
443 .It Ic require Ic client Ic ca Ar path
444 Allow requests only from clients that provide a certificate signed by
445 the CA certificate in
446 .Ar path .
447 It needs to be a PEM-encoded certificate and it's not relative to the
448 chroot.
449 .It Ic strip Ar number
450 Strip
451 .Ar number
452 components from the beginning of the path before doing a lookup in the
453 root directory.
454 It's also considered for the
455 .Ar meta
456 parameter in the scope of a
457 .Ic block return .
458 .El
459 .Ss Types
460 The
461 .Ic types
462 section must include one or more lines of the following syntax, enclosed
463 in curly brances:
464 .Bl -tag -width Ds
465 .It Ar type Ns / Ns Ar subtype Ar name Op Ar name ...
466 Set the media
467 .Ar type
468 and
469 .Ar subtype
470 to the specified extension
471 .Ar name .
472 One or more names can be specified per line.
473 Earch line may end with an optional semicolon.
474 .It Ic include Ar file
475 Include types definition from an external file, for example
476 .Pa /usr/share/misc/mime.types .
477 .El
478 .Pp
479 By default
480 .Nm gmid
481 uses the following mapping if no
482 .Ic types
483 block is defined:
484 .Pp
485 .Bl -tag -offset indent -width 15m -compact
486 .It application/pdf
487 pdf
488 .It image/gif
489 gif
490 .It image/jpeg
491 jpg jpeg
492 .It image/png
493 png
494 .It image/svg+xml
495 svg
496 .It text/gemini
497 gemini gmi
498 .It text/markdown
499 markdown md
500 .It text/x-patch
501 diff patch
502 .It text/xml
503 xml
504 .El
505 .Pp
506 As an exception,
507 .Nm gmid
508 uses the MIME type
509 .Ar text/gemini
510 for file extensions
511 .Ar gemini
512 or
513 .Ar gmi
514 if no mapping was found.
515 .Sh EXAMPLES
516 The following is an example of a possible configuration for a site
517 that enables only TLSv1.3, adds the MIME types mapping from
518 .Pa /usr/share/misc/mime.types
519 and defines two virtual host:
520 .Bd -literal -offset indent
521 protocols "tlsv1.3"
523 types {
524 include "/usr/share/misc/mime.types"
527 server "example.com" {
528 listen on * port 1965
529 cert "/etc/ssl/example.com.pem"
530 key "/etc/ssl/private/example.com.key"
531 root "/var/gemini/example.com"
534 server "example.it" {
535 listen on * port 1965
536 cert "/etc/ssl/example.it.pem"
537 key "/etc/ssl/private/example.it.key"
538 root "/var/gemini/example.it"
540 # set the language for text/gemini files
541 lang "it"
543 .Ed
544 .Pp
545 Yet another example, showing how to enable a
546 .Ic chroot
547 and use
548 .Ic location
549 rule
550 .Bd -literal -offset indent
551 chroot "/var/gemini"
552 user "_gmid"
554 server "example.com" {
555 listen on * port 1965
557 # absolute paths:
558 cert "/etc/ssl/example.com.pem"
559 key "/etc/ssl/private/example.com.key"
561 # relative to the chroot:
562 root "/example.com"
564 location "/static/*" {
565 # load the following rules only for
566 # requests that matches "/static/*"
568 auto index on
569 index "index.gemini"
572 .Ed
573 .Sh SEE ALSO
574 .Xr gmid 8 ,
575 .Xr slowcgi 8
576 .Sh AUTHORS
577 .An -nosplit
578 The
579 .Nm gmid
580 program was written by
581 .An Omar Polo Aq Mt op@omarpolo.com .