1 .\" Copyright (c) 2022, 2023 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.
19 .Nd gmid Gemini server configuration file
22 is the configuration file format for the
26 The configuration file is divided into the following sections:
29 User-defined variables may be defined and used later, simplifying the
35 Virtual hosts definition.
37 Media types and extensions.
40 Within the sections, empty lines are ignored and comments can be put
41 anywhere in the file using a hash mark
43 and extend to the end of the current line.
44 A boolean is either the symbol
48 A string is a sequence of characters wrapped in double quotes,
50 Multiple strings one next to the other are joined into a single
52 .Bd -literal -offset indent
53 # equivalent to "temporary-failure"
54 block return 40 "temporary" "-" "failure"
57 Furthermore, quoting is necessary only when a string needs to contain
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
66 Strict ordering of the sections is not enforced, so that is possible
67 to mix macros, options and
70 However, defining all the
72 blocks after the macros and the global options is recommended.
74 Newlines are often optional, except around top-level instructions, and
77 can also be optionally used to separate options.
79 Additional configuration files can be included with the
82 .Bd -literal -offset indent
83 include "/etc/gmid.conf.local"
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.
92 Two kinds of macros are supported: variable-like and proper macros.
93 When a macro is invoked with a
95 before its name its expanded as a string, whereas when it's invoked
98 its expanded in-place.
101 .Bd -literal -offset indent
104 certdir = "/etc/keys"
105 common = "lang it; auto index on"
109 root $dir "/foo" # "/var/gemini/foo"
110 cert $certdir "/foo.pem" # "/etc/keys/foo.pem"
111 key $certdir "/foo.key" # "/etc/keys/foo.key"
117 .It Ic chroot Ar path
119 the process to the given
121 The daemon has to be run with root privileges and thus the option
123 needs to be provided too, so privileges can be dropped afterwards.
124 All the paths in the configuration file are relative to the chroot
125 directory, except for the
133 home directory, if provided.
134 .It Ic log Ar options
135 Specify logging options.
136 Multiple options may be provided within curly braces.
137 The available options are as follows:
139 .It Ic access Ar file
142 The path is relative to the
144 .It Ic style Ar style
145 Set the logging style, defaults to
152 Attempt to be compatible with the default Apache httpd log format.
153 Each line is formatted as follows: the matching host name,
154 the remote IP address, one dash
156 Common Name of the client certificate
157 .Pq if provided, '-' otherwise ,
158 the timestamp of the request, the request URI wrapped in double quotes,
159 the response code and the size of the response.
161 Attempt to be compatible with the default nginx log format.
162 Each line is formatted as follows: the remote IP address, one dash
164 Common Name of the client certificate
165 .Pq if provided, '-' otherwise ,
166 the timestamp wrapped in square brackets, the request URI wrapped in
167 double quotes, the response code, the size of the response, a dash
168 wrapped in double quotes and "".
169 The strangness of these two last fields is because Gemini doesn't have
177 .\" format since 2.0.
178 .\" Each line is formatted as follows: RFC 3339 date time,
179 .\" remote IP address, Common Name of the client certificate
180 .\" .Pq if provided, '-' otherwise ,
181 .\" the matching host name, the request URI, the size of the request,
182 .\" the size of the response, the response code and meta.
184 Each line is formatted as follows: the remote IP address and port, the
186 keyword, the request URI, the response code and meta.
188 .It Ic syslog Op Ic off
190 It is enabled by default, use the
193 .It Ic syslog facility Ar facility
198 Available facilities are as follows: daemon, ftp, local0 through local7 and
200 These are case insensitive and can be prefixed with
202 Not all level may be available on all operating systems.
203 The default facility is
206 .It Ic prefork Ar number
207 Run the specified number of server processes.
208 This increases the performance and prevents delays when connecting to
211 runs 3 server processes by default.
212 The maximum number allowed is 16.
213 .It Ic protocols Ar string
214 Specify the TLS protocols to enable.
216 .Xr tls_config_parse_protocols 3
217 for the valid protocol string values.
218 By default, both TLSv1.3 and TLSv1.2 are enabled.
221 to enable only TLSv1.3.
222 .It Ic user Ar string
223 Run the daemon as the given user.
229 Every virtual host is defined by a
233 .It Ic server Ar hostname Brq ...
234 Match the server name using shell globbing rules.
235 It can be an explicit name,
236 .Ar www.example.com ,
237 or a name including a wildcards,
241 Followed by a block of options that is enclosed in curly brackets:
244 Specify an additional alias
247 .It Ic auto Ic index Ar bool
248 If no index file is found, automatically generate a directory listing.
250 .It Ic block Op Ic return Ar code Op Ar meta
251 Send a reply and close the connection;
258 .Dq temporary failure .
261 is in the 3x range, then
266 the following special sequences are supported:
267 .Bl -tag -width Ds -compact
269 is replaced with a single
272 is replaced with the request path.
274 is replaced with the query string of the request.
276 is replaced with the server port.
278 is replaced with the server name.
281 Path to the certificate to use for this server.
283 should contain a PEM encoded certificate.
284 This option is mandatory.
285 .It Ic default type Ar string
286 Set the default media type that is used if the media type for a
287 specified extension is not found.
288 If not specified, the
291 .Dq application/octet-stream .
292 .It Ic fastcgi Ar option
293 Enable FastCGI instead of serving files.
294 Multiple options may be specified within curly braces.
297 .It Ic param Ar name Cm = Ar value
302 .It Ic socket Oo Ic tcp Oc Ar socket Oo Cm port Ar port Oc
305 can either be a UNIX-domain socket or a TCP socket.
306 If the FastCGI application is listening on a UNIX domain socket,
308 is a local path name within the
314 keyword must be provided and
316 is interpreted as a hostname or an IP address.
318 can be either a port number or the name of a service enclosed in
320 If not specified defaults to 9000.
321 .It Ic strip Ar number
324 leading path components from the
327 The FastCGI handler will be given the following variables by default:
329 .It Ev GATEWAY_INTERFACE
331 .It Ev GEMINI_DOCUMENT_ROOT
332 The root directory of the virtual host.
333 .It Ev GEMINI_SCRIPT_FILENAME
334 Full path to the FastCGI script being executed.
336 The full IRI of the request.
337 .It Ev GEMINI_URL_PATH
338 The path of the request.
339 .It Ev GEMINI_SEARCH_STRING
342 if defined in the request and if it doesn't contain any unencoded
344 characters, otherwise unset.
346 The portion of the requested path that is derived from the the IRI
347 path hierarchy following the part that identifies the script itself.
349 .It Ev PATH_TRANSLATED
350 Present if and only if
353 It represent the translation of the
356 builds this by appending the
358 to the virtual host directory root.
360 The URL-encoded search or parameter string.
361 .It Ev REMOTE_ADDR , Ev REMOTE_HOST
362 Textual representation of the client IP.
363 .It Ev REQUEST_METHOD
364 This is present only for RFC3875 (CGI) compliance.
365 It's always set to the empty string.
367 The virtual URI path to the script.
369 The name of the server
371 The port the server is listening on.
372 .It Ev SERVER_PROTOCOL
374 .It Ev SERVER_SOFTWARE
375 The name and version of the server, i.e.
378 The string "Certificate" if the client used a certificate, otherwise
381 The subject of the client certificate if provided, otherwise unset.
382 .It Ev TLS_CLIENT_ISSUER
383 The is the issuer of the client certificate if provided, otherwise
385 .It Ev TLS_CLIENT_HASH
386 The hash of the client certificate if provided, otherwise unset.
390 The TLS version negotiated with the peer.
392 The cipher suite negotiated with the peer.
393 .It Ev TLS_CIPHER_STRENGTH
394 The strength in bits for the symmetric cipher that is being used with
396 .It Ev TLS_CLIENT_NOT_AFTER
397 The time corresponding to the end of the validity period of the peer
398 certificate in the ISO 8601 format
399 .Pq e.g. Dq 2021-02-07T20:17:41Z .
400 .It Ev TLS_CLIENT_NOT_BEFORE
401 The time corresponding to the start of the validity period of the peer
402 certificate in the ISO 8601 format.
405 Disable FastCGI handling in the current location.
406 .It Ic index Ar string
407 Set the directory index file.
408 If not specified, it defaults to
411 Specify the private key to use for this server.
413 should contain a PEM encoded private key.
414 This option is mandatory.
415 .It Ic lang Ar string
416 Specify the language tag for the text/gemini content served.
419 parameter will be added in the response.
420 .It Ic listen on Ar address Op Ic port Ar number
427 This statement can be specified multiple times.
434 will listen on all IPv4 and IPv6 addresses.
436 can be used to listen on all IPv4 addresses and
438 on all IPv6 addresses.
439 .It Ic location Ar path Brq ...
440 Specify server configuration rules for a specific location.
442 argument will be matched against the request path with shell globbing
444 In case of multiple location statements in the same context, the first
445 matching location will be put into effect and the later ones ignored.
446 Therefore is advisable to match for more specific paths first and for
447 generic ones later on.
450 section may include most of the server configuration rules
452 .Ic alias , Ic cert , Ic key , Ic listen , Ic location
456 Enable or disable the logging for the current server or location block.
458 Specify an OCSP response to be stapled during TLS handshakes
462 should contain a DER-format OCSP response retrieved from an
466 If the OCSP response in
468 is empty, OCSP stapling will not be used.
469 The default is to not use OCSP stapling.
470 .It Ic proxy Oo Cm proto Ar name Oc Oo Cm for-host Ar host Oo Cm port Ar port Oc Oc Brq ...
471 Set up a reverse proxy.
472 The optional matching rules
476 can be used to enable proxying only for protocols matching
481 and/or whose request IRI matches
485 .Pq 1965 by default .
486 Matching happens using shell globbing rules.
488 In case of multiple matching proxy blocks in the same context, the
489 first matching proxy will be put into effect and the later ones
495 Specify the client certificate to use when making requests.
497 Specify the client certificate key to use when making requests.
498 .It Ic protocols Ar string
499 Specify the TLS protocols allowed when making remote requests.
501 .Xr tls_config_parse_protocols 3
502 function for the valid protocol string values.
503 By default, both TLSv1.2 and TLSv1.3 are enabled.
504 .It Ic relay-to Ar host Op Cm port Ar port
505 Relay the request to the given
510 This is the only mandatory option in a
513 .It Ic require Ic client Ic ca Ar file
514 Allow the proxying only from clients that provide a certificate
515 signed by the CA certificate in
517 .It Ic sni Ar hostname
520 instead of the one extracted from the
522 rule for the TLS handshake with the proxied gemini server.
523 .It Ic use-tls Ar bool
524 Specify whether to use TLS when connecting to the proxied host.
526 .It Ic verifyname Ar bool
527 Enable or disable the TLS server name verification.
530 .It Ic root Ar directory
531 Specify the root directory for this server
532 .Pq alas the current Dq document root .
533 It's relative to the chroot if enabled.
534 .It Ic require Ic client Ic ca Ar path
535 Allow requests only from clients that provide a certificate signed by
536 the CA certificate in
538 It needs to be a PEM-encoded certificate and it's not relative to the
540 .It Ic strip Ar number
543 components from the beginning of the path before doing a lookup in the
545 It's also considered for the
547 parameter in the scope of a
553 section must include one or more lines of the following syntax, enclosed
556 .It Ar type Ns / Ns Ar subtype Ar name Op Ar name ...
561 to the specified extension
563 One or more names can be specified per line.
564 Earch line may end with an optional semicolon.
565 .It Ic include Ar file
566 Include types definition from an external file, for example
567 .Pa /usr/share/misc/mime.types .
572 uses the following mapping if no
576 .Bl -tag -offset indent -width 15m -compact
605 if no mapping was found.
607 The following is an example of a possible configuration for a site
608 that enables only TLSv1.3, adds the MIME types mapping from
609 .Pa /usr/share/misc/mime.types
610 and defines two virtual host:
611 .Bd -literal -offset indent
615 include "/usr/share/misc/mime.types"
618 server "example.com" {
619 listen on * port 1965
620 cert "/etc/ssl/example.com.pem"
621 key "/etc/ssl/private/example.com.key"
622 root "/var/gemini/example.com"
625 server "example.it" {
626 listen on * port 1965
627 cert "/etc/ssl/example.it.pem"
628 key "/etc/ssl/private/example.it.key"
629 root "/var/gemini/example.it"
631 # set the language for text/gemini files
636 Yet another example, showing how to enable a
641 .Bd -literal -offset indent
645 server "example.com" {
646 listen on * port 1965
649 cert "/etc/ssl/example.com.pem"
650 key "/etc/ssl/private/example.com.key"
652 # relative to the chroot:
655 location "/static/*" {
656 # load the following rules only for
657 # requests that matches "/static/*"
665 This shows how to set up a reverse proxy: all request for
667 will be forwarded to 10.0.0.6 transparently.
668 Proxying establish a new TLS connection, so any client-certificates used
671 cannot be provided to the proxied server as well.
672 .Bd -literal -offset indent
673 server "example.com" {
674 listen on * port 1965
675 cert "/etc/ssl/example.com.pem"
676 key "/etc/ssl/private/example.com.key"
678 relay-to 10.0.0.6 port 1965
689 program was written by
690 .An Omar Polo Aq Mt op@omarpolo.com .