]> git.proxmox.com Git - ceph.git/blob - ceph/src/civetweb/docs/UserManual.md
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / civetweb / docs / UserManual.md
1
2 Overview
3 =====
4
5 Civetweb is small and easy to use web server.
6 It may be embedded into C/C++ host applications or used as a stand-alone
7 server. See `Embedding.md` for information on embedding civetweb into
8 host applications.
9
10 The stand-alone server is self-contained, and does not require any external
11 software to run. Some Windows users may need to install the
12 [Visual C++ Redistributable](http://www.microsoft.com/en-us/download/details.aspx?id=30679).
13
14 Installation
15 ----
16
17 On Windows, UNIX and Mac, the civetweb stand-alone executable may be started
18 from the command line.
19 Running `civetweb` in a terminal, optionally followed by configuration parameters
20 (`civetweb [OPTIONS]`) or a configuration file name (`civetweb [config_file_name]`),
21 starts the web server.
22
23 For UNIX and Mac, civetweb does not detach from the terminal.
24 Pressing `Ctrl-C` keys will stop the server.
25
26 On Windows, civetweb iconifies itself to the system tray icon when started.
27 Right-click on the icon pops up a menu, where it is possible to stop
28 civetweb, or configure it, or install it as Windows service.
29
30 When started without options, the server exposes the local directory at
31 [http](http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) port 8080.
32 Thus, the easiest way to share a folder on Windows is to copy `civetweb.exe`
33 to this folder, double-click the exe, and launch a browser at
34 [http://localhost:8080](http://localhost:8080). Note that 'localhost' should
35 be changed to a machine's name if a folder is accessed from other computer.
36
37 When started, civetweb first searches for the configuration file.
38 If configuration file is specified explicitly in the command line, i.e.
39 `civetweb path_to_config_file`, then specified configuration file is used.
40 Otherwise, civetweb would search for file `civetweb.conf` in the same directory
41 the executable is located, and use it. This configuration file is optional.
42
43 The configuration file is a sequence of lines, each line containing one
44 command line argument name and the corresponding value.
45 Empty lines, and lines beginning with `#`, are ignored.
46 Here is the example of `civetweb.conf` file:
47
48 document_root c:\www
49 listening_ports 80,443s
50 ssl_certificate c:\civetweb\ssl_cert.pem
51
52 When a configuration file is used, additional command line arguments may
53 override the configuration file settings.
54 All command line arguments must start with `-`.
55
56 For example: The above `civetweb.conf` file is used, and civetweb started as
57 `civetweb -document_root D:\web`. Then the `D:\web` directory will be served
58 as document root, because command line options take priority over the
59 configuration file. The configuration options section below provides a good
60 overview of the Civetweb features.
61
62 Note that configuration options on the command line must start with `-`,
63 but their names are the same as in the config file. All option names are
64 listed in the next section. Thus, the following two setups are equivalent:
65
66 # Using command line arguments
67 $ civetweb -listening_ports 1234 -document_root /var/www
68
69 # Using config file
70 $ cat civetweb.conf
71 listening_ports 1234
72 document_root /var/www
73 $ civetweb
74
75 Civetweb can also be used to modify `.htpasswd` passwords files:
76
77 civetweb -A <htpasswd_file> <realm> <user> <passwd>
78
79 Unlike other web servers, civetweb does not require CGI scripts to be located
80 in a special directory. CGI scripts can be anywhere. CGI (and SSI) files are
81 recognized by the file name pattern. Civetweb uses shell-like glob
82 patterns. Pattern match starts at the beginning of the string, so essentially
83 patterns are prefix patterns. Syntax is as follows:
84
85 ** Matches everything
86 * Matches everything but slash character, '/'
87 ? Matches any character
88 $ Matches the end of the string
89 | Matches if pattern on the left side or the right side matches.
90
91 All other characters in the pattern match themselves. Examples:
92
93 **.cgi$ Any string that ends with .cgi
94 /foo Any string that begins with /foo
95 **a$|**b$ Any string that ends with a or b
96
97 # Configuration Options
98
99 Below is a list of configuration options understood by Civetweb.
100 Every option is followed by it's default value. If a default value is not
101 present, then the default is empty.
102
103 ### cgi\_pattern `**.cgi$|**.pl$|**.php$`
104 All files that match `cgi_pattern` are treated as CGI files. Default pattern
105 allows CGI files be anywhere. To restrict CGIs to a certain directory,
106 use `/path/to/cgi-bin/**.cgi` as pattern. Note that the full file path is
107 matched against the pattern, not the URI.
108
109 ### cgi\_environment
110 Extra environment variables to be passed to the CGI script in
111 addition to standard ones. The list must be comma-separated list
112 of name=value pairs, like this: `VARIABLE1=VALUE1,VARIABLE2=VALUE2`.
113
114 ### put\_delete\_auth\_file
115 Passwords file for PUT and DELETE requests. Without password file, it will not
116 be possible to, PUT new files to the server or DELETE existing ones. PUT and
117 DELETE requests might still be handled by Lua scripts and CGI paged.
118
119 ### cgi\_interpreter
120 Path to an executable to use as CGI interpreter for __all__ CGI scripts
121 regardless of the script file extension. If this option is not set (which is
122 the default), Civetweb looks at first line of a CGI script,
123 [shebang line](http://en.wikipedia.org/wiki/Shebang_(Unix\)), for an
124 interpreter (not only on Linux and Mac but also for Windows).
125
126 For example, if both PHP and Perl CGIs are used, then
127 `#!/path/to/php-cgi.exe` and `#!/path/to/perl.exe` must be first lines of the
128 respective CGI scripts. Note that paths should be either full file paths,
129 or file paths relative to the current working directory of the civetweb
130 server. If civetweb is started by mouse double-click on Windows, the current
131 working directory is the directory where the civetweb executable is located.
132
133 If all CGIs use the same interpreter, for example they are all PHP, it is
134 more efficient to set `cgi_interpreter` to the path to `php-cgi.exe`.
135 The shebang line in the CGI scripts can be omitted in this case.
136 Note that PHP scripts must use `php-cgi.exe` as executable, not `php.exe`.
137
138 ### protect\_uri
139 Comma separated list of URI=PATH pairs, specifying that given
140 URIs must be protected with password files specified by PATH.
141 All Paths must be full file paths.
142
143 ### authentication\_domain `mydomain.com`
144 Authorization realm used for HTTP digest authentication. This domain is
145 used in the encoding of the `.htpasswd` authorization files as well.
146 Changing the domain retroactively will render the existing passwords useless.
147
148 ### enable\_auth\_domain\_check `yes`
149 When using absolute URLs, verify the host is identical to the authentication\_domain. If enabled, requests to absolute URLs will only be processed
150 if they are directed to the domain. If disabled, absolute URLs to any host
151 will be accepted.
152
153 ### ssi\_pattern `**.shtml$|**.shtm$`
154 All files that match `ssi_pattern` are treated as Server Side Includes (SSI).
155
156 SSI is a simple interpreted server-side scripting language which is most
157 commonly used to include the contents of another file into a web page.
158 It can be useful when it is desirable to include a common piece
159 of code throughout a website, for example, headers and footers.
160
161 In order for a webpage to recognize an SSI-enabled HTML file, the filename
162 should end with a special extension, by default the extension should be
163 either `.shtml` or `.shtm`. These extentions may be changed using the
164 `ssi_pattern` option.
165
166 Unknown SSI directives are silently ignored by civetweb. Currently, two SSI
167 directives are supported, `<!--#include ...>` and
168 `<!--#exec "command">`. Note that the `<!--#include ...>` directive supports
169 three path specifications:
170
171 <!--#include virtual="path"> Path is relative to web server root
172 <!--#include abspath="path"> Path is absolute or relative to
173 web server working dir
174 <!--#include file="path">, Path is relative to current document
175 <!--#include "path">
176
177 The `include` directive may be used to include the contents of a file or the
178 result of running a CGI script. The `exec` directive is used to execute a
179 command on a server, and show the output that would have been printed to
180 stdout (the terminal window) otherwise. Example:
181
182 <!--#exec "ls -l" -->
183
184 For more information on Server Side Includes, take a look at the Wikipedia:
185 [Server Side Includes](http://en.wikipedia.org/wiki/Server_Side_Includes)
186
187 ### throttle
188 Limit download speed for clients. `throttle` is a comma-separated
189 list of key=value pairs, where key could be:
190
191 * limit speed for all connections
192 x.x.x.x/mask limit speed for specified subnet
193 uri_prefix_pattern limit speed for given URIs
194
195 The value is a floating-point number of bytes per second, optionally
196 followed by a `k` or `m` character, meaning kilobytes and
197 megabytes respectively. A limit of 0 means unlimited rate. The
198 last matching rule wins. Examples:
199
200 *=1k,10.0.0.0/8=0 limit all accesses to 1 kilobyte per second,
201 but give connections the from 10.0.0.0/8 subnet
202 unlimited speed
203
204 /downloads/=5k limit accesses to all URIs in `/downloads/` to
205 5 kilobytes per second. All other accesses are unlimited
206
207 ### access\_log\_file
208 Path to a file for access logs. Either full path, or relative to the current
209 working directory. If absent (default), then accesses are not logged.
210
211 ### enable\_directory\_listing `yes`
212 Enable directory listing, either `yes` or `no`.
213
214 ### error\_log\_file
215 Path to a file for error logs. Either full path, or relative to the current
216 working directory. If absent (default), then errors are not logged.
217
218 ### global\_auth\_file
219 Path to a global passwords file, either full path or relative to the current
220 working directory. If set, per-directory `.htpasswd` files are ignored,
221 and all requests are authorized against that file.
222
223 The file has to include the realm set through `authentication_domain` and the
224 password in digest format:
225
226 user:realm:digest
227 test:test.com:ce0220efc2dd2fad6185e1f1af5a4327
228
229 Password files may be generated using `civetweb -A` as explained above, or
230 online tools e.g. [this generator](http://www.askapache.com/online-tools/htpasswd-generator).
231
232 ### index\_files `index.xhtml,index.html,index.htm,index.cgi,index.shtml,index.php`
233 Comma-separated list of files to be treated as directory index files.
234 If more than one matching file is present in a directory, the one listed to the left
235 is used as a directory index.
236
237 In case built-in Lua support has been enabled, `index.lp,index.lsp,index.lua`
238 are additional default index files, ordered before `index.cgi`.
239
240 ### enable\_keep\_alive `no`
241 Enable connection keep alive, either `yes` or `no`.
242
243 Allows clients to reuse TCP connection for subsequent HTTP requests,
244 which improves performance.
245 For this to work when using request handlers it is important to add the
246 correct Content-Length HTTP header for each request. If this is forgotten the
247 client will time out.
248
249 Note: If you set keep\_alive to `yes`, you should set keep\_alive\_timeout\_ms
250 to some value > 0 (e.g. 500). If you set keep\_alive to `no`, you should set
251 keep\_alive\_timeout\_ms to 0. Currently, this is done as a default value,
252 but this configuration is redundant. In a future version, the keep\_alive
253 configuration option might be removed and automatically set to `yes` if
254 a timeout > 0 is set.
255
256 ### access\_control\_list
257 An Access Control List (ACL) allows restrictions to be put on the list of IP
258 addresses which have access to the web server. In the case of the Civetweb
259 web server, the ACL is a comma separated list of IP subnets, where each
260 subnet is pre-pended by either a `-` or a `+` sign. A plus sign means allow,
261 where a minus sign means deny. If a subnet mask is omitted, such as `-1.2.3.4`,
262 this means to deny only that single IP address.
263
264 Subnet masks may vary from 0 to 32, inclusive. The default setting is to allow
265 all accesses. On each request the full list is traversed, and
266 the last match wins. Examples:
267
268 -0.0.0.0/0,+192.168/16 deny all accesses, only allow 192.168/16 subnet
269
270 To learn more about subnet masks, see the
271 [Wikipedia page on Subnetwork](http://en.wikipedia.org/wiki/Subnetwork).
272
273 ### extra\_mime\_types
274 Extra mime types, in tha form `extension1=type1,exten-sion2=type2,...`.
275 See the [Wikipedia page on Internet media types](http://en.wikipedia.org/wiki/Internet_media_type).
276 Extension must include a leading dot. Example:
277 `.cpp=plain/text,.java=plain/text`
278
279 ### listening\_ports `8080`
280 Comma-separated list of ports to listen on. If the port is SSL, a
281 letter `s` must be appended, for example, `80,443s` will open
282 port 80 and port 443, and connections on port 443 will be SSL-ed.
283 For non-SSL ports, it is allowed to append letter `r`, meaning 'redirect'.
284 Redirect ports will redirect all their traffic to the first configured
285 SSL port. For example, if `listening_ports` is `80r,443s`, then all
286 HTTP traffic coming at port 80 will be redirected to HTTPS port 443.
287
288 It is possible to specify an IP address to bind to. In this case,
289 an IP address and a colon must be pre-pended to the port number.
290 For example, to bind to a loopback interface on port 80 and to
291 all interfaces on HTTPS port 443, use `127.0.0.1:80,443s`.
292
293 If the server is built with IPv6 support, `[::]:8080` can be used to
294 listen to IPv6 connections to port 8080. IPv6 addresses of network
295 interfaces can be specified as well,
296 e.g. `[::1]:8080` for the IPv6 loopback interface.
297
298 [::]:80 will bind to port 80 IPv6 only. In order to use port 80 for
299 all interfaces, both IPv4 and IPv6, use either the configuration
300 `80,[::]:80` (create one socket for IPv4 and one for IPv6 only),
301 or `+80` (create one socket for both, IPv4 and IPv6).
302 The `+`-notation to use IPv4 and IPv6 will only work in no network
303 interface is specified. Depending on your operating system version
304 and IPv6 network environment, some configurations might not work
305 as expected, so you have to test to find the configuration most
306 suitable for your needs. In case `+80` does not work for your
307 environment, you need to use `80,[::]:80`.
308
309 It is possible to use network interface addresses (e.g., `192.0.2.3:80`,
310 `[2001:0db8::1234]:80`). To get a list of available network interface
311 addresses, use `ipconfig` (in a `cmd` window in Windows) or `ifconfig`
312 (in a Linux shell).
313 Alternatively, you could use the hostname for an interface. Check the
314 hosts file of your operating system for a proper hostname
315 (for Windows, usually found in C:\Windows\System32\drivers\etc\,
316 for most Linux distributions: /etc/hosts). E.g., to bind the IPv6
317 local host, you could use `ip6-localhost:80`. This translates to
318 `[::1]:80`. Beside the hosts file, there are several other name
319 resolution services. Using your hostname might bind you to the
320 localhost or an external interface. You could also try `hostname.local`,
321 if the proper network services are installed (Zeroconf, mDNS, Bonjour,
322 Avahi). When using a hostname, you need to test in your particular network
323 environment - in some cases, you might need to resort to a fixed IP address.
324
325 ### document\_root `.`
326 A directory to serve. By default, the current working directory is served.
327 The current directory is commonly referenced as dot (`.`).
328 It is recommended to use an absolute path for document\_root, in order to
329 avoid accidentally serving the wrong directory.
330
331 ### ssl\_certificate
332 Path to the SSL certificate file. This option is only required when at least
333 one of the `listening\_ports` is SSL. The file must be in PEM format,
334 and it must have both, private key and certificate, see for example
335 [ssl_cert.pem](https://github.com/civetweb/civetweb/blob/master/resources/ssl_cert.pem)
336 A description how to create a certificate can be found in doc/OpenSSL.md
337
338 ### num\_threads `50`
339 Number of worker threads. Civetweb handles each incoming connection in a
340 separate thread. Therefore, the value of this option is effectively the number
341 of concurrent HTTP connections Civetweb can handle.
342
343 ### run\_as\_user
344 Switch to given user credentials after startup. Usually, this option is
345 required when civetweb needs to bind on privileged ports on UNIX. To do
346 that, civetweb needs to be started as root. From a security point of view,
347 running as root is not advisable, therefore this option can be used to drop
348 privileges. Example:
349
350 civetweb -listening_ports 80 -run_as_user webserver
351
352 ### url\_rewrite\_patterns
353 Comma-separated list of URL rewrites in the form of
354 `uri_pattern=file_or_directory_path`. When Civetweb receives any request,
355 it constructs the file name to show by combining `document_root` and the URI.
356 However, if the rewrite option is used and `uri_pattern` matches the
357 requested URI, then `document_root` is ignored. Instead,
358 `file_or_directory_path` is used, which should be a full path name or
359 a path relative to the web server's current working directory. Note that
360 `uri_pattern`, as all civetweb patterns, is a prefix pattern.
361
362 This makes it possible to serve many directories outside from `document_root`,
363 redirect all requests to scripts, and do other tricky things. For example,
364 to redirect all accesses to `.doc` files to a special script, do:
365
366 civetweb -url_rewrite_patterns **.doc$=/path/to/cgi-bin/handle_doc.cgi
367
368 Or, to imitate support for user home directories, do:
369
370 civetweb -url_rewrite_patterns /~joe/=/home/joe/,/~bill=/home/bill/
371
372 ### hide\_files\_patterns
373 A pattern for the files to hide. Files that match the pattern will not
374 show up in directory listing and return `404 Not Found` if requested. Pattern
375 must be for a file name only, not including directory names. Example:
376
377 civetweb -hide_files_patterns secret.txt|**.hide
378
379 Note: hide\_file\_patterns uses the pattern described above. If you want to
380 hide all files with a certain extension, make sure to use **.extension
381 (not just *.extension).
382
383 ### request\_timeout\_ms `30000`
384 Timeout for network read and network write operations, in milliseconds.
385 If a client intends to keep long-running connection, either increase this
386 value or (better) use keep-alive messages.
387
388 ### keep\_alive\_timeout\_ms `500` or `0`
389 Idle timeout between two requests in one keep-alive connection.
390 If keep alive is enabled, multiple requests using the same connection
391 are possible. This reduces the overhead for opening and closing connections
392 when loading several resources from one server, but it also blocks one port
393 and one thread at the server during the lifetime of this connection.
394 Unfortunately, browsers do not close the keep-alive connection after loading
395 all resources required to show a website.
396 The server closes a keep-alive connection, if there is no additional request
397 from the client during this timeout.
398
399 Note: if enable\_keep\_alive is set to `no` the value of
400 keep\_alive\_timeout\_ms should be set to `0`, if enable\_keep\_alive is set
401 to `yes`, the value of keep\_alive\_timeout\_ms must be >0.
402 Currently keep\_alive\_timeout\_ms is ignored if enable\_keep\_alive is no,
403 but future versions my drop the enable\_keep\_alive configuration value and
404 automatically use keep-alive if keep\_alive\_timeout\_ms is not 0.
405
406 ### linger\_timeout\_ms
407 Set TCP socket linger timeout before closing sockets (SO\_LINGER option).
408 The configured value is a timeout in milliseconds. Setting the value to 0
409 will yield in abortive close (if the socket is closed from the server side).
410 Setting the value to -1 will turn off linger.
411 If the value is not set (or set to -2), CivetWeb will not set the linger
412 option at all.
413
414 Note: For consistency with other timeouts, the value is configured in
415 milliseconds. However, the TCP socket layer usually only offers a timeout in
416 seconds, so the value should be an integer multiple of 1000.
417
418 ### lua\_preload\_file
419 This configuration option can be used to specify a Lua script file, which
420 is executed before the actual web page script (Lua script, Lua server page
421 or Lua websocket). It can be used to modify the Lua environment of all web
422 page scripts, e.g., by loading additional libraries or defining functions
423 required by all scripts.
424 It may be used to achieve backward compatibility by defining obsolete
425 functions as well.
426
427 ### lua\_script\_pattern `"**.lua$`
428 A pattern for files that are interpreted as Lua scripts by the server.
429 In contrast to Lua server pages, Lua scripts use plain Lua syntax.
430 An example can be found in the test directory.
431
432 ### lua\_server\_page\_pattern `**.lp$|**.lsp$`
433 Files matching this pattern are treated as Lua server pages.
434 In contrast to Lua scripts, the content of a Lua server pages is delivered
435 directly to the client. Lua script parts are delimited from the standard
436 content by including them between <? and ?> tags.
437 An example can be found in the test directory.
438
439 ### lua\_background\_script
440 Experimental feature, and subject to change.
441 Run a Lua script in the background, independent from any connection.
442 The script is started before network access to the server is available.
443 It can be used to prepare the document root (e.g., update files, compress
444 files, ...), check for external resources, remove old log files, etc.
445
446 The Lua state remains open until the server is stopped.
447 In the future, some callback functions will be available to notify the
448 script on changes of the server state. See example lua script :
449 [background.lua](https://github.com/civetweb/civetweb/blob/master/test/background.lua).
450
451 Additional functions available in background script :
452 sleep, root path, script name, isterminated
453
454 ### lua\_background\_script\_params `param1=1,param2=2`
455 Can add dynamic parameters to background script.
456 Parameters mapped to global 'mg' table 'params' field.
457
458 ### websocket\_root
459 In case civetweb is built with Lua and websocket support, Lua scripts may
460 be used for websockets as well. Since websockets use a different URL scheme
461 (ws, wss) than other http pages (http, https), the Lua scripts used for
462 websockets may also be served from a different directory. By default,
463 the document_root is used as websocket_root as well.
464
465
466 ### access\_control\_allow\_origin `*`
467 Access-Control-Allow-Origin header field, used for cross-origin resource
468 sharing (CORS).
469 See the [Wikipedia page on CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing).
470
471
472 ### access\_control\_allow\_methods `*`
473 Access-Control-Allow-Methods header field, used for cross-origin resource
474 sharing (CORS) pre-flight requests.
475 See the [Wikipedia page on CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing).
476
477 If set to an empty string, pre-flights will not be supported directly by the server,
478 but scripts may still support pre-flights by handling the OPTIONS method properly.
479 If set to "*", the pre-flight will allow whatever method has been requested.
480 If set to a comma separated list of valid HTTP methods, the pre-flight will return
481 exactly this list as allowed method.
482 If set in any other way, the result is unspecified.
483
484
485 ### access\_control\_allow\_headers `*`
486 Access-Control-Allow-Headers header field, used for cross-origin resource
487 sharing (CORS) pre-flight requests.
488 See the [Wikipedia page on CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing).
489
490 If set to an empty string, pre-flights will not allow additional headers.
491 If set to "*", the pre-flight will allow whatever headers have been requested.
492 If set to a comma separated list of valid HTTP headers, the pre-flight will return
493 exactly this list as allowed headers.
494 If set in any other way, the result is unspecified.
495
496
497 ### error\_pages
498 This option may be used to specify a directory for user defined error pages.
499 The error pages may be specified for an individual http status code (e.g.,
500 404 - page requested by the client not found), a group of http status codes
501 (e.g., 4xx - all client errors) or all errors. The corresponding error pages
502 must be called error404.ext, error4xx.ext or error.ext, whereas the file
503 extention may be one of the extentions specified for the index_files option.
504 See the [Wikipedia page on HTTP status codes](http://en.wikipedia.org/wiki/HTTP_status_code).
505
506 ### tcp\_nodelay `0`
507 Enable TCP_NODELAY socket option on client connections.
508
509 If set the socket option will disable Nagle's algorithm on the connection
510 which means that packets will be sent as soon as possible instead of waiting
511 for a full buffer or timeout to occur.
512
513 0 Keep the default: Nagel's algorithm enabled
514 1 Disable Nagel's algorithm for all sockets
515
516 ### static\_file\_max\_age `3600`
517 Set the maximum time (in seconds) a cache may store a static files.
518
519 This option will set the `Cache-Control: max-age` value for static files.
520 Dynamically generated content, i.e., content created by a script or callback,
521 must send cache control headers by themselfes.
522
523 A value >0 corresponds to a maximum allowed caching time in seconds.
524 This value should not exceed one year (RFC 2616, Section 14.21).
525 A value of 0 will send "do not cache" headers for all static files.
526 For values <0 and values >31622400, the behavior is undefined.
527
528 ### strict\_transport\_security\_max\_age
529
530 Set the `Strict-Transport-Security` header, and set the `max-age` value.
531 This instructs web browsers to interact with the server only using HTTPS,
532 never by HTTP. If set, it will be sent for every request handled directly
533 by the server, except scripts (CGI, Lua, ..) and callbacks. They must
534 send HTTP headers on their own.
535
536 The time is specified in seconds. If this configuration is not set,
537 or set to -1, no `Strict-Transport-Security` header will be sent.
538 For values <-1 and values >31622400, the behavior is undefined.
539
540 ### decode\_url `yes`
541 URL encoded request strings are decoded in the server, unless it is disabled
542 by setting this option to `no`.
543
544 ### ssl\_verify\_peer `no`
545 Enable client's certificate verification by the server.
546
547 ### ssl\_ca\_path
548 Name of a directory containing trusted CA certificates. Each file in the
549 directory must contain only a single CA certificate. The files must be named
550 by the subject name’s hash and an extension of “.0”. If there is more than one
551 certificate with the same subject name they should have extensions ".0", ".1",
552 ".2" and so on respectively.
553
554 ### ssl\_ca\_file
555 Path to a .pem file containing trusted certificates. The file may contain
556 more than one certificate.
557
558 ### ssl\_verify\_depth `9`
559 Sets maximum depth of certificate chain. If client's certificate chain is longer
560 than the depth set here connection is refused.
561
562 ### ssl\_default\_verify\_paths `yes`
563 Loads default trusted certificates locations set at openssl compile time.
564
565 ### ssl\_cipher\_list
566 List of ciphers to present to the client. Entries should be separated by
567 colons, commas or spaces.
568
569 ALL All available ciphers
570 ALL:!eNULL All ciphers excluding NULL ciphers
571 AES128:!MD5 AES 128 with digests other than MD5
572
573 See [this entry](https://www.openssl.org/docs/manmaster/apps/ciphers.html) in
574 OpenSSL documentation for full list of options and additional examples.
575
576 ### ssl\_protocol\_version `0`
577 Sets the minimal accepted version of SSL/TLS protocol according to the table:
578
579 Protocols | Value
580 ------------ | -------------
581 SSL2+SSL3+TLS1.0+TLS1.1+TLS1.2 | 0
582 SSL3+TLS1.0+TLS1.1+TLS1.2 | 1
583 TLS1.0+TLS1.1+TLS1.2 | 2
584 TLS1.1+TLS1.2 | 3
585 TLS1.2 | 4
586
587 ### ssl\_short\_trust `no`
588 Enables the use of short lived certificates. This will allow for the certificates
589 and keys specified in `ssl_certificate`, `ssl_ca_file` and `ssl_ca_path` to be
590 exchanged and reloaded while the server is running.
591
592 In an automated environment it is advised to first write the new pem file to
593 a different filename and then to rename it to the configured pem file name to
594 increase performance while swapping the certificate.
595
596 Disk IO performance can be improved when keeping the certificates and keys stored
597 on a tmpfs (linux) on a system with very high throughput.
598
599 ### allow\_sendfile\_call `yes`
600 This option can be used to enable or disable the use of the Linux `sendfile` system call. It is only available for Linux systems and only affecting HTTP (not HTTPS) connections if `throttle` is not enabled. While using the `sendfile` call will lead to a performance boost for HTTP connections, this call may be broken for some file systems and some operating system versions.
601
602 ### case\_sensitive `no`
603 This option can be uset to enable case URLs for Windows servers. It is only available for Windows systems. Windows file systems are not case sensitive, but they still store the file name including case. If this option is set to `yes`, the comparison for URIs and Windows file names will be case sensitive.
604
605 ### allow\_index\_script\_resource `no`
606 Index scripts (like `index.cgi` or `index.lua`) may have script handled resources.
607
608 It this feature is activated, that /some/path/file.ext might be handled by:
609 1. /some/path/file.ext (with PATH\_INFO='/', if ext = cgi)
610 2. /some/path/index.lua with mg.request\_info.path\_info='/file.ext'
611 3. /some/path/index.cgi with PATH\_INFO='/file.ext'
612 4. /some/path/index.php with PATH\_INFO='/file.ext'
613 5. /some/index.lua with mg.request\_info.path\_info=='/path/file.ext'
614 6. /some/index.cgi with PATH\_INFO='/path/file.ext'
615 7. /some/index.php with PATH\_INFO='/path/file.ext'
616 8. /index.lua with mg.request\_info.path\_info=='/some/path/file.ext'
617 9. /index.cgi with PATH\_INFO='/some/path/file.ext'
618 10. /index.php with PATH\_INFO='/some/path/file.ext'
619
620 Note: This example is valid, if the default configuration values for `index_files`, `cgi_pattern` and `lua_script_pattern` are used, and the server is built with CGI and Lua support enabled.
621
622 If this feature is not activated, only the first file (/some/path/file.cgi) will be accepted.
623
624 Note: This parameter affects only index scripts. A path like /here/script.cgi/handle/this.ext will call /here/script.cgi with PATH\_INFO='/handle/this.ext', no matter if this option is set to `yes` or `no`.
625
626 This feature can be used to completely hide the script extension from the URL.
627
628 ### additional\_header
629 Send additional HTTP response header line for every request.
630 The full header line including key and value must be specified, excluding the carriage return line feed.
631
632 Example (used as command line option):
633 `-additional_header "X-Frame-Options: SAMEORIGIN"`
634
635 This option can be specified multiple times. All specified header lines will be sent.
636
637 # Lua Scripts and Lua Server Pages
638 Pre-built Windows and Mac civetweb binaries have built-in Lua scripting
639 support as well as support for Lua Server Pages.
640
641 Lua scripts (default extension: *.lua) use plain Lua syntax.
642 The body of the script file is not sent directly to the client,
643 the Lua script must send header and content of the web page by calling
644 the function mg.write(text).
645
646 Lua Server Pages (default extensions: *.lsp, *.lp) are html pages containing
647 script elements similar to PHP, using the Lua programming language instead of
648 PHP. Lua script elements must be enclosed in `<? ?>` blocks, and can appear
649 anywhere on the page. Furthermore, Lua Server Pages offer the opportunity to
650 insert the content of a variable by enclosing the Lua variable name in
651 `<?= ?>` blocks, similar to PHP.
652 For example, to print the current weekday name and the URI of the current
653 page, one can write:
654
655 <p>
656 <span>Today is:</span>
657 <? mg.write(os.date("%A")) ?>
658 </p>
659 <p>
660 URI is <?=mg.request_info.uri?>
661 </p>
662
663 Lua is known for it's speed and small size. Civetweb currently uses Lua
664 version 5.2.4. The documentation for it can be found in the
665 [Lua 5.2 reference manual](http://www.lua.org/manual/5.2/).
666
667
668 Note that this example uses function `mg.write()`, which sends data to the
669 web client. Using `mg.write()` is the way to generate web content from inside
670 Lua code. In addition to `mg.write()`, all standard Lua library functions
671 are accessible from the Lua code (please check the reference manual for
672 details). Lua functions working on files (e.g., `io.open`) use a path
673 relative to the working path of the civetweb process. The web server content
674 is located in the path `mg.document_root`.
675 Information on the request is available in the `mg.request_info`
676 object, like the request method, all HTTP headers, etcetera.
677
678 [page2.lua](https://github.com/civetweb/civetweb/blob/master/test/page2.lua)
679 is an example for a plain Lua script.
680
681 [page2.lp](https://github.com/civetweb/civetweb/blob/master/test/page2.lp)
682 is an example for a Lua Server Page.
683
684 Both examples show the content of the `mg.request_info` object as the page
685 content. Please refer to `struct mg_request_info` definition in
686 [civetweb.h](https://github.com/civetweb/civetweb/blob/master/include/civetweb.h)
687 to see additional information on the elements of the `mg.request_info` object.
688
689 Civetweb also provides access to the [SQlite3 database](http://www.sqlite.org/)
690 through the [LuaSQLite3 interface](http://lua.sqlite.org/index.cgi/doc/tip/doc/lsqlite3.wiki)
691 in Lua. Examples are given in
692 [page.lua](https://github.com/civetweb/civetweb/blob/master/test/page.lua) and
693 [page.lp](https://github.com/civetweb/civetweb/blob/master/test/page.lp).
694
695
696 Civetweb exports the following functions to Lua:
697
698 mg (table):
699
700 mg.read() -- reads a chunk from POST data, returns it as a string
701 mg.write(str) -- writes string to the client
702 mg.include(filename, [pathtype]) -- include another Lua Page file (Lua Pages only)
703 -- pathtype can be "abs", "rel"/"file" or "virt[ual]"
704 -- like defined for SSI #include
705 mg.redirect(uri) -- internal redirect to a given URI
706 mg.onerror(msg) -- error handler, can be overridden
707 mg.version -- a string that holds Civetweb version
708 mg.document_root -- a string that holds the document root directory
709 mg.auth_domain -- a string that holds the HTTP authentication domain
710 mg.get_var(str, varname) -- extract variable from (query) string
711 mg.get_cookie(str, cookie) -- extract cookie from a string
712 mg.get_mime_type(filename) -- get MIME type of a file
713 mg.get_info(infotype) -- get server status information
714 mg.send_file(filename) -- send a file, including MIME type
715 mg.url_encode(str) -- URL encode a string
716 mg.url_decode(str, [form]) -- URL decode a string. If form=true, replace + by space.
717 mg.base64_encode(str) -- BASE64 encode a string
718 mg.base64_decode(str) -- BASE64 decode a string
719 mg.md5(str) -- return the MD5 hash of a string
720 mg.keep_alive(bool) -- allow/forbid to use http keep-alive for this request
721 mg.request_info -- a table with the following request information
722 .remote_addr -- IP address of the client as string
723 .remote_port -- remote port number
724 .server_port -- server port number
725 .request_method -- HTTP method (e.g.: GET, POST)
726 .http_version -- HTTP protocol version (e.g.: 1.1)
727 .uri -- resource name
728 .query_string -- query string if present, nil otherwise
729 .script_name -- name of the Lua script
730 .https -- true if accessed by https://, false otherwise
731 .remote_user -- user name if authenticated, nil otherwise
732
733 connect (function):
734
735 -- Connect to the remote TCP server. This function is an implementation
736 -- of simple socket interface. It returns a socket object with three
737 -- methods: send, recv, close, which are synchronous (blocking).
738 -- connect() throws an exception on connection error.
739 connect(host, port, use_ssl)
740
741 -- Example of using connect() interface:
742 local host = 'code.google.com' -- IP address or domain name
743 local ok, sock = pcall(connect, host, 80, 1)
744 if ok then
745 sock:send('GET /p/civetweb/ HTTP/1.0\r\n' ..
746 'Host: ' .. host .. '\r\n\r\n')
747 local reply = sock:recv()
748 sock:close()
749 -- reply now contains the web page https://code.google.com/p/civetweb
750 end
751
752
753 All filename arguments are either absolute or relative to the civetweb working
754 directory (not the document root or the Lua script/page file).
755
756 **IMPORTANT: Civetweb does not send HTTP headers for Lua pages. Therefore,
757 every Lua Page must begin with a HTTP reply line and headers**, like this:
758
759 <? mg.write('HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n') ?>
760 <html><body>
761 ... the rest of the web page ...
762
763 To serve a Lua Page, civetweb creates a Lua context. That context is used for
764 all Lua blocks within the page. That means, all Lua blocks on the same page
765 share the same context. If one block defines a variable, for example, that
766 variable is visible in all block that follow.
767
768 ## Websockets for Lua
769 Civetweb offers support for websockets in Lua as well. In contrast to plain
770 Lua scripts and Lua server pages, Lua websocket scripts are shared by all clients.
771
772 Lua websocket scripts must define a few functions:
773 open(arg) -- callback to accept or reject a connection
774 ready(arg) -- called after a connection has been established
775 data(arg) -- called when the server receives data from the client
776 close(arg) -- called when a websocket connection is closed
777 All function are called with one argument of type table with at least one field
778 "client" to identify the client. When "open" is called, the argument table additionally
779 contains the "request_info" table as defined above. For the "data" handler, an
780 additional field "data" is available. The functions "open", "ready" and "data"
781 must return true in order to keep the connetion open.
782
783 Lua websocket pages do support single shot (timeout) and interval timers.
784
785 An example is shown in
786 [websocket.lua](https://github.com/civetweb/civetweb/blob/master/test/websocket.lua).
787
788
789 # Common Problems
790 - PHP doesn't work - getting empty page, or 'File not found' error. The
791 reason for that is wrong paths to the interpreter. Remember that with PHP,
792 the correct interpreter is `php-cgi.exe` (`php-cgi` on UNIX).
793 Solution: specify the full path to the PHP interpreter, e.g.:
794 `civetweb -cgi_interpreter /full/path/to/php-cgi`
795
796 - `php-cgi` is unavailable, for example on Mac OS X. As long as the `php` binary is installed, you can run CGI programs in command line mode (see the example below). Note that in this mode, `$_GET` and friends will be unavailable, and you'll have to parse the query string manually using [parse_str](http://php.net/manual/en/function.parse-str.php) and the `QUERY_STRING` environmental variable.
797
798 #!/usr/bin/php
799 <?php
800 echo "Content-Type: text/html\r\n\r\n";
801 echo "Hello World!\n";
802 ?>
803
804 - Civetweb fails to start. If Civetweb exits immediately when started, this
805 usually indicates a syntax error in the configuration file
806 (named `civetweb.conf` by default) or the command-line arguments.
807 Syntax checking is omitted from Civetweb to keep its size low. However,
808 the Manual should be of help. Note: the syntax changes from time to time,
809 so updating the config file might be necessary after executable update.
810
811 - Embedding with OpenSSL on Windows might fail because of calling convention.
812 To force Civetweb to use `__stdcall` convention, add `/Gz` compilation
813 flag in Visual Studio compiler.
814