xref: /openbsd-src/usr.sbin/httpd/httpd.conf.5 (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1.\"	$OpenBSD: httpd.conf.5,v 1.73 2016/05/09 19:36:54 tj Exp $
2.\"
3.\" Copyright (c) 2014, 2015 Reyk Floeter <reyk@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: May 9 2016 $
18.Dt HTTPD.CONF 5
19.Os
20.Sh NAME
21.Nm httpd.conf
22.Nd HTTP daemon configuration file
23.Sh DESCRIPTION
24.Nm
25is the configuration file for the HTTP daemon,
26.Xr httpd 8 .
27.Sh SECTIONS
28.Nm
29is divided into four main sections:
30.Bl -tag -width xxxx
31.It Sy Macros
32User-defined variables may be defined and used later, simplifying the
33configuration file.
34.It Sy Global Configuration
35Global settings for
36.Xr httpd 8 .
37.It Sy Servers
38Listening HTTP web servers.
39.It Sy Types
40Media types and extensions.
41.El
42.Pp
43Within the sections,
44a host
45.Ar address
46can be specified by IPv4 address, IPv6 address, interface name,
47interface group, or DNS hostname.
48If the address is an interface name,
49.Xr httpd 8
50will look up the first IPv4 address and any other IPv4 and IPv6
51addresses of the specified network interface.
52If
53.Sq *
54is given as an address,
55it will be used as an alias for
56.Ar 0.0.0.0
57to listen on all IPv4 addresses.
58Likewise,
59.Sq ::
60can be used to listen on all IPv6 addresses.
61A
62.Ar port
63can be specified by number or name.
64The port name to number mappings are found in the file
65.Pa /etc/services ;
66see
67.Xr services 5
68for details.
69.Pp
70The current line can be extended over multiple lines using a backslash
71.Pq Sq \e .
72Comments can be put anywhere in the file using a hash mark
73.Pq Sq # ,
74and extend to the end of the current line.
75Care should be taken when commenting out multi-line text:
76the comment is effective until the end of the entire block.
77.Pp
78Argument names not beginning with a letter, digit, or underscore
79must be quoted.
80.Pp
81Additional configuration files can be included with the
82.Ic include
83keyword, for example:
84.Bd -literal -offset indent
85include "/etc/httpd.conf.local"
86.Ed
87.Sh MACROS
88Macros can be defined that will later be expanded in context.
89Macro names must start with a letter, digit, or underscore,
90and may contain any of those characters.
91Macro names may not be reserved words (for example,
92.Ic directory ,
93.Ic log ,
94or
95.Ic root ) .
96Macros are not expanded inside quotes.
97.Pp
98For example:
99.Bd -literal -offset indent
100ext_ip="10.0.0.1"
101server "default" {
102	listen on $ext_ip port 80
103}
104.Ed
105.Sh GLOBAL CONFIGURATION
106Here are the settings that can be set globally:
107.Bl -tag -width Ds
108.It Ic chroot Ar directory
109Set the
110.Xr chroot 2
111directory.
112If not specified, it defaults to
113.Pa /var/www ,
114the home directory of the www user.
115.It Ic default type Ar type/subtype
116Set the default media type that is used if the media type for a
117specified extension is not found in the configured types or for files
118without a file extension;
119see the
120.Sx TYPES
121section below.
122If not specified, the default type is set to
123.Ar application/octet-stream .
124.It Ic logdir Ar directory
125Specifies the full path of the directory in which log files will be written.
126If not specified, it defaults to
127.Pa /logs
128within the
129.Xr chroot 2
130directory.
131.It Ic prefork Ar number
132Run the specified number of server processes.
133This increases the performance and prevents delays when connecting
134to a server.
135.Xr httpd 8
136runs 3 server processes by default.
137.El
138.Sh SERVERS
139The configured web servers.
140.Pp
141Each
142.Ic server
143section starts with a declaration of the server
144.Ar name :
145.Bl -tag -width Ds
146.It Ic server Ar name Brq ...
147Match the server name using shell globbing rules.
148This can be an explicit name,
149.Ar www.example.com ,
150or a name including wildcards,
151.Ar *.example.com .
152.It Ic server match Ar name Brq ...
153Match the server name using pattern matching,
154see
155.Xr patterns 7 .
156.El
157.Pp
158Followed by a block of options that is enclosed in curly brackets:
159.Bl -tag -width Ds
160.It Ic alias Ar name
161Specify an additional alias
162.Ar name
163for this server.
164.It Ic alias match Ar name
165Like the
166.Ic alias
167option,
168but
169.Ic match
170the
171.Ar name
172using pattern matching instead of shell globbing rules,
173see
174.Xr patterns 7 .
175.It Oo Ic no Oc Ic authenticate Oo Ar realm Oc Ic with Pa htpasswd
176Authenticate a remote user for
177.Ar realm
178by checking the credentials against the user authentication file
179.Pa htpasswd .
180The file name is relative to the
181.Ic chroot
182and must be readable by the www user.
183Use the
184.Ic no authenticate
185directive to disable authentication in a location.
186.It Ic block drop
187Drop the connection without sending an error page.
188.It Ic block Op Ic return Ar code Op Ar uri
189Close the connection and send an error page.
190If the optional return code is not specified,
191.Xr httpd 8
192denies access with a
193.Sq 403 Forbidden
194response.
195The optional
196.Ar uri
197argument can be used with return codes in the 3xx range to send a
198.Sq Location:
199header for redirection to a specified URI.
200.Pp
201The
202.Ar uri
203may contain predefined macros that will be expanded at runtime:
204.Pp
205.Bl -tag -width $DOCUMENT_URI -offset indent -compact
206.It Ic $DOCUMENT_URI
207The request path.
208.It Ic $QUERY_STRING
209The optional query string of the request.
210.It Ic $REMOTE_ADDR
211The IP address of the connected client.
212.It Ic $REMOTE_PORT
213The TCP source port of the connected client.
214.It Ic $REMOTE_USER
215The remote user for HTTP authentication.
216.It Ic $REQUEST_URI
217The request path and optional query string.
218.It Ic $SERVER_ADDR
219The configured IP address of the server.
220.It Ic $SERVER_PORT
221The configured TCP server port of the server.
222.It Ic $SERVER_NAME
223The name of the server.
224.It Pf % Ar n
225The capture index
226.Ar n
227of a string that was captured by the enclosing
228.Ic location match
229option.
230.El
231.It Ic connection Ar option
232Set the specified options and limits for HTTP connections.
233Valid options are:
234.Bl -tag -width Ds
235.It Ic max request body Ar number
236Set the maximum body size in bytes that the client can send to the server.
237The default value is 1048576 bytes (1M).
238.It Ic max requests Ar number
239Set the maximum number of requests per persistent HTTP connection.
240Persistent connections are negotiated using the Keep-Alive header in
241HTTP/1.0 and enabled by default in HTTP/1.1.
242The default maximum number of requests per connection is 100.
243.It Ic timeout Ar seconds
244Specify the inactivity timeout in seconds for accepted sessions.
245The default timeout is 600 seconds (10 minutes).
246The maximum is 2147483647 seconds (68 years).
247.El
248.It Ic default type Ar type/subtype
249Set the default media type for the specified location,
250overwriting the global setting.
251.It Ic directory Ar option
252Set the specified options when serving or accessing directories.
253Valid options are:
254.Bl -tag -width Ds
255.It Oo Ic no Oc Ic auto index
256If no index file is found, automatically generate a directory listing.
257This is disabled by default.
258.It Ic index Ar string
259Set the directory index file.
260If not specified, it defaults to
261.Pa index.html .
262.It Ic no index
263Disable the directory index.
264.Xr httpd 8
265will neither display nor generate a directory index.
266.El
267.It Oo Ic no Oc Ic fastcgi Op Ic socket Ar socket
268Enable FastCGI instead of serving files.
269The
270.Ar socket
271is a local path name within the
272.Xr chroot 2
273root directory of
274.Xr httpd 8
275and defaults to
276.Pa /run/slowcgi.sock .
277.Pp
278The FastCGI handler will be given the following variables:
279.Pp
280.Bl -tag -width GATEWAY_INTERFACE -offset indent -compact
281.It Ic DOCUMENT_ROOT
282The document root in which the script is located as configured by the
283.Ic root
284option for the server or location that matches the request.
285.It Ic GATEWAY_INTERFACE
286The revision of the CGI specification used.
287.It Ic HTTP_*
288Additional HTTP headers the connected client sent in the request, if
289any.
290.It Ic HTTPS
291A variable that is set to
292.Qq on
293when the server has been configured to use TLS.
294This variable is omitted otherwise.
295.It Ic REQUEST_URI
296The path and optional query string as requested by the connected client.
297.It Ic DOCUMENT_URI
298The canonicalized request path, possibly with a slash or
299directory index file name appended.
300This is the same as
301.Ic PATH_INFO
302appended to
303.Ic SCRIPT_NAME .
304.It Ic SCRIPT_NAME
305The virtual URI path to the script.
306.It Ic PATH_INFO
307The optional path appended after the script name in the request path.
308This variable is an empty string if no path is appended after the
309script name.
310.It Ic SCRIPT_FILENAME
311The absolute, physical path to the script within the
312.Xr chroot 2
313directory.
314.It Ic QUERY_STRING
315The optional query string of the request.
316This variable is an empty
317string if there is no query string in the request.
318.It Ic REMOTE_ADDR
319The IP address of the connected client.
320.It Ic REMOTE_PORT
321The TCP source port of the connected client.
322.It Ic REMOTE_USER
323The remote user when using HTTP authentication.
324.It Ic REQUEST_METHOD
325The HTTP method the connected client used when making the request.
326.It Ic SERVER_ADDR
327The configured IP address of the server.
328.It Ic SERVER_NAME
329The name of the server.
330.It Ic SERVER_PORT
331The configured TCP server port of the server.
332.It Ic SERVER_PROTOCOL
333The revision of the HTTP specification used.
334.It Ic SERVER_SOFTWARE
335The server software name of
336.Xr httpd 8 .
337.El
338.It Ic hsts Oo Ar option Oc
339Enable HTTP Strict Transport Security.
340Valid options are:
341.Bl -tag -width Ds
342.It Ic max-age Ar seconds
343Set the maximum time in seconds a receiving user agent should regard
344this host as an HSTS host.
345The default is one year.
346.It Ic preload
347Confirm and authenticate that the site is permitted to be included in
348a browser's preload list.
349.It Ic subdomains
350Signal to the receiving user agent that this host and all sub domains
351of the host's domain should be considered HSTS hosts.
352.El
353.It Ic listen on Ar address Oo Ic tls Oc Ic port Ar number
354Set the listen address and port.
355This statement can be specified multiple times.
356.It Ic location Ar path Brq ...
357Specify server configuration rules for a specific location.
358The
359.Ar path
360argument will be matched against the request path with shell globbing rules.
361A location section may include most of the server configuration rules
362except
363.Ic alias ,
364.Ic connection ,
365.Ic hsts ,
366.Ic listen on ,
367.Ic location ,
368.Ic tcp
369and
370.Ic tls .
371.It Ic location match Ar path Brq ...
372Like the
373.Ic location
374option,
375but
376.Ic match
377the
378.Ar path
379using pattern matching instead of shell globbing rules,
380see
381.Xr patterns 7 .
382The pattern may contain captures that can be used in the
383.Ar uri
384of an enclosed
385.Ic block return
386option.
387.It Oo Ic no Oc Ic log Op Ar option
388Set the specified logging options.
389Logging is enabled by default using the standard
390.Ic access
391and
392.Ic error
393log files,
394but can be changed per server or location.
395Use the
396.Ic no log
397directive to disable logging of any requests.
398Valid options are:
399.Bl -tag -width Ds
400.It Ic access Ar name
401Set the
402.Ar name
403of the access log file relative to the log directory.
404If not specified, it defaults to
405.Pa access.log .
406.It Ic error Ar name
407Set the
408.Ar name
409of the error log file relative to the log directory.
410If not specified, it defaults to
411.Pa error.log .
412.It Ic style Ar style
413Set the logging style.
414The
415.Ar style
416can be
417.Cm common ,
418.Cm combined
419or
420.Cm connection .
421The styles
422.Cm common
423and
424.Cm combined
425write a log entry after each request similar to the standard Apache
426and nginx access log formats.
427The style
428.Cm connection
429writes a summarized log entry after each connection,
430that can have multiple requests,
431similar to the format that is used by
432.Xr relayd 8 .
433If not specified, the default is
434.Cm common .
435.It Oo Ic no Oc Ic syslog
436Enable or disable logging to
437.Xr syslog 3
438instead of the log files.
439.El
440.It Ic pass
441Disable any previous
442.Ic block
443in a location.
444.It Ic root Ar option
445Configure the document root and options for the request path.
446Valid options are:
447.Bl -tag -width Ds
448.It Ar directory
449Set the document root of the server.
450The
451.Ar directory
452is a pathname within the
453.Xr chroot 2
454root directory of
455.Nm httpd .
456If not specified, it defaults to
457.Pa /htdocs .
458.It Ic strip Ar number
459Strip
460.Ar number
461path components from the beginning of the request path before looking
462up the stripped-down path at the document root.
463.El
464.It Ic tcp Ar option
465Enable or disable the specified TCP/IP options; see
466.Xr tcp 4
467and
468.Xr ip 4
469for more information about the options.
470Valid options are:
471.Bl -tag -width Ds
472.It Ic backlog Ar number
473Set the maximum length the queue of pending connections may grow to.
474The backlog option is 10 by default and is limited by the
475.Va kern.somaxconn
476.Xr sysctl 8
477variable.
478.It Ic ip minttl Ar number
479This option for the underlying IP connection may be used to discard packets
480with a TTL lower than the specified value.
481This can be used to implement the
482Generalized TTL Security Mechanism (GTSM)
483according to RFC 5082.
484.It Ic ip ttl Ar number
485Change the default time-to-live value in the IP headers.
486.It Oo Ic no Oc Ic nodelay
487Enable the TCP NODELAY option for this connection.
488This is recommended to avoid delays in the data stream.
489.It Oo Ic no Oc Ic sack
490Use selective acknowledgements for this connection.
491.It Ic socket buffer Ar number
492Set the socket-level buffer size for input and output for this
493connection.
494This will affect the TCP window size.
495.El
496.It Ic tls Ar option
497Set the TLS configuration for the server.
498These options are only used if TLS has been enabled via the listen directive.
499Valid options are:
500.Bl -tag -width Ds
501.It Ic certificate Ar file
502Specify the certificate to use for this server.
503The
504.Ar file
505should contain a PEM encoded certificate.
506The default is
507.Pa /etc/ssl/server.crt .
508.It Ic ciphers Ar string
509Specify the TLS cipher string.
510If not specified, the default value
511.Qq HIGH:!aNULL
512will be used (strong crypto cipher suites without anonymous DH).
513See the CIPHERS section of
514.Xr openssl 1
515for information about SSL/TLS cipher suites and preference lists.
516.It Ic dhe Ar params
517Specify the DHE parameters to use for DHE cipher suites.
518Valid parameter values are none, legacy and auto.
519For legacy a fixed key length of 1024 bits is used, whereas for auto the key
520length is determined automatically.
521The default is none, which disables DHE cipher suites.
522.It Ic ecdhe Ar curve
523Specify the ECDHE curve to use for ECDHE cipher suites.
524Valid parameter values are none, auto and the short name of any known curve.
525The default is auto.
526.It Ic key Ar file
527Specify the private key to use for this server.
528The
529.Ar file
530should contain a PEM encoded private key and reside outside of the
531.Xr chroot 2
532root directory of
533.Nm httpd .
534The default is
535.Pa /etc/ssl/private/server.key .
536.It Ic protocols Ar string
537Specify the TLS protocols to enable for this server.
538If not specified, the value
539.Qq default
540will be used (secure protocols; TLSv1.2-only).
541Refer to the
542.Xr tls_config_parse_protocols 3
543function for other valid protocol string values.
544.El
545.El
546.Sh TYPES
547Configure the supported media types.
548.Xr httpd 8
549will set the
550.Ar Content-Type
551of the response header based on the file extension listed in the
552.Ic types
553section.
554If not specified,
555.Xr httpd 8
556will use built-in media types for
557.Ar text/css ,
558.Ar text/html ,
559.Ar text/plain ,
560.Ar image/gif ,
561.Ar image/png ,
562.Ar image/jpeg ,
563and
564.Ar application/javascript .
565.Pp
566The
567.Ic types
568section must include one or more lines of the following syntax:
569.Bl -tag -width Ds
570.It Ar type/subtype Ar name Op Ar name ...
571Set the media
572.Ar type
573and
574.Ar subtype
575to the specified extension
576.Ar name .
577One or more names can be specified per line.
578Each line may end with an optional semicolon.
579.It Ic include Ar file
580Include types definitions from an external file, for example
581.Pa /usr/share/misc/mime.types .
582.El
583.Sh EXAMPLES
584The following example will start one server that is pre-forked two
585times and is listening on all local IP addresses.
586It additionally defines some media types overriding the defaults.
587.Bd -literal -offset indent
588prefork 2
589
590server "default" {
591	listen on * port 80
592}
593
594types {
595	text/css		css
596	text/html		html htm
597	text/plain		txt
598	image/gif		gif
599	image/jpeg		jpeg jpg
600	image/png		png
601	application/javascript	js
602	application/xml		xml
603}
604.Ed
605.Pp
606The server can also be configured to only listen on the primary IP
607address of the network interface that is a member of the
608.Qq egress
609group.
610.Bd -literal -offset indent
611server "default" {
612	listen on egress port 80
613}
614.Ed
615.Pp
616Multiple servers can be configured to support hosting of different domains.
617If the same address is repeated multiple times in the
618.Ic listen on
619statement,
620the server will be matched based on the requested host name.
621.Bd -literal -offset indent
622server "www.example.com" {
623	alias "example.com"
624	listen on * port 80
625	listen on * tls port 443
626	root "/htdocs/www.example.com"
627}
628
629server "www.a.example.com" {
630	listen on 203.0.113.1 port 80
631	root "/htdocs/www.a.example.com"
632}
633
634server "www.b.example.com" {
635	listen on 203.0.113.1 port 80
636	root "/htdocs/www.b.example.com"
637}
638
639server "intranet.example.com" {
640	listen on 10.0.0.1 port 80
641	root "/htdocs/intranet.example.com"
642}
643.Ed
644.Pp
645Simple redirections can be configured with the
646.Ic block
647directive:
648.Bd -literal -offset indent
649server "example.com" {
650	listen on 10.0.0.1 port 80
651	block return 301 "http://www.example.com$REQUEST_URI"
652}
653
654server "www.example.com" {
655	listen on 10.0.0.1 port 80
656}
657.Ed
658.Sh SEE ALSO
659.Xr htpasswd 1 ,
660.Xr patterns 7 ,
661.Xr httpd 8 ,
662.Xr slowcgi 8
663.Sh AUTHORS
664.An -nosplit
665The
666.Xr httpd 8
667program was written by
668.An Reyk Floeter Aq Mt reyk@openbsd.org .
669