1 2.. GENERATED by help2rst.py. DO NOT EDIT DIRECTLY. 3 4.. program:: nghttpx 5 6nghttpx(1) 7========== 8 9SYNOPSIS 10-------- 11 12**nghttpx** [OPTIONS]... [<PRIVATE_KEY> <CERT>] 13 14DESCRIPTION 15----------- 16 17A reverse proxy for HTTP/3, HTTP/2, and HTTP/1. 18 19.. describe:: <PRIVATE_KEY> 20 21 22 Set path to server's private key. Required unless 23 "no-tls" parameter is used in :option:`--frontend` option. 24 25.. describe:: <CERT> 26 27 Set path to server's certificate. Required unless 28 "no-tls" parameter is used in :option:`--frontend` option. To 29 make OCSP stapling work, this must be an absolute path. 30 31 32OPTIONS 33------- 34 35The options are categorized into several groups. 36 37Connections 38~~~~~~~~~~~ 39 40.. option:: -b, --backend=(<HOST>,<PORT>|unix:<PATH>)[;[<PATTERN>[:...]][[;<PARAM>]...] 41 42 43 Set backend host and port. The multiple backend 44 addresses are accepted by repeating this option. UNIX 45 domain socket can be specified by prefixing path name 46 with "unix:" (e.g., unix:/var/run/backend.sock). 47 48 Optionally, if <PATTERN>s are given, the backend address 49 is only used if request matches the pattern. The 50 pattern matching is closely designed to ServeMux in 51 net/http package of Go programming language. <PATTERN> 52 consists of path, host + path or just host. The path 53 must start with "*/*". If it ends with "*/*", it matches 54 all request path in its subtree. To deal with the 55 request to the directory without trailing slash, the 56 path which ends with "*/*" also matches the request path 57 which only lacks trailing '*/*' (e.g., path "*/foo/*" 58 matches request path "*/foo*"). If it does not end with 59 "*/*", it performs exact match against the request path. 60 If host is given, it performs a match against the 61 request host. For a request received on the frontend 62 listener with "sni-fwd" parameter enabled, SNI host is 63 used instead of a request host. If host alone is given, 64 "*/*" is appended to it, so that it matches all request 65 paths under the host (e.g., specifying "nghttp2.org" 66 equals to "nghttp2.org/"). CONNECT method is treated 67 specially. It does not have path, and we don't allow 68 empty path. To workaround this, we assume that CONNECT 69 method has "*/*" as path. 70 71 Patterns with host take precedence over patterns with 72 just path. Then, longer patterns take precedence over 73 shorter ones. 74 75 Host can include "\*" in the left most position to 76 indicate wildcard match (only suffix match is done). 77 The "\*" must match at least one character. For example, 78 host pattern "\*.nghttp2.org" matches against 79 "www.nghttp2.org" and "git.ngttp2.org", but does not 80 match against "nghttp2.org". The exact hosts match 81 takes precedence over the wildcard hosts match. 82 83 If path part ends with "\*", it is treated as wildcard 84 path. The wildcard path behaves differently from the 85 normal path. For normal path, match is made around the 86 boundary of path component separator,"*/*". On the other 87 hand, the wildcard path does not take into account the 88 path component separator. All paths which include the 89 wildcard path without last "\*" as prefix, and are 90 strictly longer than wildcard path without last "\*" are 91 matched. "\*" must match at least one character. For 92 example, the pattern "*/foo\**" matches "*/foo/*" and 93 "*/foobar*". But it does not match "*/foo*", or "*/fo*". 94 95 If <PATTERN> is omitted or empty string, "*/*" is used as 96 pattern, which matches all request paths (catch-all 97 pattern). The catch-all backend must be given. 98 99 When doing a match, nghttpx made some normalization to 100 pattern, request host and path. For host part, they are 101 converted to lower case. For path part, percent-encoded 102 unreserved characters defined in RFC 3986 are decoded, 103 and any dot-segments (".." and ".") are resolved and 104 removed. 105 106 For example, :option:`-b`\'127.0.0.1,8080;nghttp2.org/httpbin/' 107 matches the request host "nghttp2.org" and the request 108 path "*/httpbin/get*", but does not match the request host 109 "nghttp2.org" and the request path "*/index.html*". 110 111 The multiple <PATTERN>s can be specified, delimiting 112 them by ":". Specifying 113 :option:`-b`\'127.0.0.1,8080;nghttp2.org:www.nghttp2.org' has the 114 same effect to specify :option:`-b`\'127.0.0.1,8080;nghttp2.org' 115 and :option:`-b`\'127.0.0.1,8080;www.nghttp2.org'. 116 117 The backend addresses sharing same <PATTERN> are grouped 118 together forming load balancing group. 119 120 Several parameters <PARAM> are accepted after <PATTERN>. 121 The parameters are delimited by ";". The available 122 parameters are: "proto=<PROTO>", "tls", 123 "sni=<SNI_HOST>", "fall=<N>", "rise=<N>", 124 "affinity=<METHOD>", "dns", "redirect-if-not-tls", 125 "upgrade-scheme", "mruby=<PATH>", 126 "read-timeout=<DURATION>", "write-timeout=<DURATION>", 127 "group=<GROUP>", "group-weight=<N>", "weight=<N>", and 128 "dnf". The parameter consists of keyword, and 129 optionally followed by "=" and value. For example, the 130 parameter "proto=h2" consists of the keyword "proto" and 131 value "h2". The parameter "tls" consists of the keyword 132 "tls" without value. Each parameter is described as 133 follows. 134 135 The backend application protocol can be specified using 136 optional "proto" parameter, and in the form of 137 "proto=<PROTO>". <PROTO> should be one of the following 138 list without quotes: "h2", "http/1.1". The default 139 value of <PROTO> is "http/1.1". Note that usually "h2" 140 refers to HTTP/2 over TLS. But in this option, it may 141 mean HTTP/2 over cleartext TCP unless "tls" keyword is 142 used (see below). 143 144 TLS can be enabled by specifying optional "tls" 145 parameter. TLS is not enabled by default. 146 147 With "sni=<SNI_HOST>" parameter, it can override the TLS 148 SNI field value with given <SNI_HOST>. This will 149 default to the backend <HOST> name 150 151 The feature to detect whether backend is online or 152 offline can be enabled using optional "fall" and "rise" 153 parameters. Using "fall=<N>" parameter, if nghttpx 154 cannot connect to a this backend <N> times in a row, 155 this backend is assumed to be offline, and it is 156 excluded from load balancing. If <N> is 0, this backend 157 never be excluded from load balancing whatever times 158 nghttpx cannot connect to it, and this is the default. 159 There is also "rise=<N>" parameter. After backend was 160 excluded from load balancing group, nghttpx periodically 161 attempts to make a connection to the failed backend, and 162 if the connection is made successfully <N> times in a 163 row, the backend is assumed to be online, and it is now 164 eligible for load balancing target. If <N> is 0, a 165 backend is permanently offline, once it goes in that 166 state, and this is the default behaviour. 167 168 The session affinity is enabled using 169 "affinity=<METHOD>" parameter. If "ip" is given in 170 <METHOD>, client IP based session affinity is enabled. 171 If "cookie" is given in <METHOD>, cookie based session 172 affinity is enabled. If "none" is given in <METHOD>, 173 session affinity is disabled, and this is the default. 174 The session affinity is enabled per <PATTERN>. If at 175 least one backend has "affinity" parameter, and its 176 <METHOD> is not "none", session affinity is enabled for 177 all backend servers sharing the same <PATTERN>. It is 178 advised to set "affinity" parameter to all backend 179 explicitly if session affinity is desired. The session 180 affinity may break if one of the backend gets 181 unreachable, or backend settings are reloaded or 182 replaced by API. 183 184 If "affinity=cookie" is used, the additional 185 configuration is required. 186 "affinity-cookie-name=<NAME>" must be used to specify a 187 name of cookie to use. Optionally, 188 "affinity-cookie-path=<PATH>" can be used to specify a 189 path which cookie is applied. The optional 190 "affinity-cookie-secure=<SECURE>" controls the Secure 191 attribute of a cookie. The default value is "auto", and 192 the Secure attribute is determined by a request scheme. 193 If a request scheme is "https", then Secure attribute is 194 set. Otherwise, it is not set. If <SECURE> is "yes", 195 the Secure attribute is always set. If <SECURE> is 196 "no", the Secure attribute is always omitted. 197 "affinity-cookie-stickiness=<STICKINESS>" controls 198 stickiness of this affinity. If <STICKINESS> is 199 "loose", removing or adding a backend server might break 200 the affinity and the request might be forwarded to a 201 different backend server. If <STICKINESS> is "strict", 202 removing the designated backend server breaks affinity, 203 but adding new backend server does not cause breakage. 204 If the designated backend server becomes unavailable, 205 new backend server is chosen as if the request does not 206 have an affinity cookie. <STICKINESS> defaults to 207 "loose". 208 209 By default, name resolution of backend host name is done 210 at start up, or reloading configuration. If "dns" 211 parameter is given, name resolution takes place 212 dynamically. This is useful if backend address changes 213 frequently. If "dns" is given, name resolution of 214 backend host name at start up, or reloading 215 configuration is skipped. 216 217 If "redirect-if-not-tls" parameter is used, the matched 218 backend requires that frontend connection is TLS 219 encrypted. If it isn't, nghttpx responds to the request 220 with 308 status code, and https URI the client should 221 use instead is included in Location header field. The 222 port number in redirect URI is 443 by default, and can 223 be changed using :option:`--redirect-https-port` option. If at 224 least one backend has "redirect-if-not-tls" parameter, 225 this feature is enabled for all backend servers sharing 226 the same <PATTERN>. It is advised to set 227 "redirect-if-no-tls" parameter to all backends 228 explicitly if this feature is desired. 229 230 If "upgrade-scheme" parameter is used along with "tls" 231 parameter, HTTP/2 :scheme pseudo header field is changed 232 to "https" from "http" when forwarding a request to this 233 particular backend. This is a workaround for a backend 234 server which requires "https" :scheme pseudo header 235 field on TLS encrypted connection. 236 237 "mruby=<PATH>" parameter specifies a path to mruby 238 script file which is invoked when this pattern is 239 matched. All backends which share the same pattern must 240 have the same mruby path. 241 242 "read-timeout=<DURATION>" and "write-timeout=<DURATION>" 243 parameters specify the read and write timeout of the 244 backend connection when this pattern is matched. All 245 backends which share the same pattern must have the same 246 timeouts. If these timeouts are entirely omitted for a 247 pattern, :option:`--backend-read-timeout` and 248 :option:`--backend-write-timeout` are used. 249 250 "group=<GROUP>" parameter specifies the name of group 251 this backend address belongs to. By default, it belongs 252 to the unnamed default group. The name of group is 253 unique per pattern. "group-weight=<N>" parameter 254 specifies the weight of the group. The higher weight 255 gets more frequently selected by the load balancing 256 algorithm. <N> must be [1, 256] inclusive. The weight 257 8 has 4 times more weight than 2. <N> must be the same 258 for all addresses which share the same <GROUP>. If 259 "group-weight" is omitted in an address, but the other 260 address which belongs to the same group specifies 261 "group-weight", its weight is used. If no 262 "group-weight" is specified for all addresses, the 263 weight of a group becomes 1. "group" and "group-weight" 264 are ignored if session affinity is enabled. 265 266 "weight=<N>" parameter specifies the weight of the 267 backend address inside a group which this address 268 belongs to. The higher weight gets more frequently 269 selected by the load balancing algorithm. <N> must be 270 [1, 256] inclusive. The weight 8 has 4 times more 271 weight than weight 2. If this parameter is omitted, 272 weight becomes 1. "weight" is ignored if session 273 affinity is enabled. 274 275 If "dnf" parameter is specified, an incoming request is 276 not forwarded to a backend and just consumed along with 277 the request body (actually a backend server never be 278 contacted). It is expected that the HTTP response is 279 generated by mruby script (see "mruby=<PATH>" parameter 280 above). "dnf" is an abbreviation of "do not forward". 281 282 Since ";" and ":" are used as delimiter, <PATTERN> must 283 not contain these characters. In order to include ":" 284 in <PATTERN>, one has to specify "%3A" (which is 285 percent-encoded from of ":") instead. Since ";" has 286 special meaning in shell, the option value must be 287 quoted. 288 289 290 Default: ``127.0.0.1,80`` 291 292.. option:: -f, --frontend=(<HOST>,<PORT>|unix:<PATH>)[[;<PARAM>]...] 293 294 Set frontend host and port. If <HOST> is '\*', it 295 assumes all addresses including both IPv4 and IPv6. 296 UNIX domain socket can be specified by prefixing path 297 name with "unix:" (e.g., unix:/var/run/nghttpx.sock). 298 This option can be used multiple times to listen to 299 multiple addresses. 300 301 This option can take 0 or more parameters, which are 302 described below. Note that "api" and "healthmon" 303 parameters are mutually exclusive. 304 305 Optionally, TLS can be disabled by specifying "no-tls" 306 parameter. TLS is enabled by default. 307 308 If "sni-fwd" parameter is used, when performing a match 309 to select a backend server, SNI host name received from 310 the client is used instead of the request host. See 311 :option:`--backend` option about the pattern match. 312 313 To make this frontend as API endpoint, specify "api" 314 parameter. This is disabled by default. It is 315 important to limit the access to the API frontend. 316 Otherwise, someone may change the backend server, and 317 break your services, or expose confidential information 318 to the outside the world. 319 320 To make this frontend as health monitor endpoint, 321 specify "healthmon" parameter. This is disabled by 322 default. Any requests which come through this address 323 are replied with 200 HTTP status, without no body. 324 325 To accept PROXY protocol version 1 and 2 on frontend 326 connection, specify "proxyproto" parameter. This is 327 disabled by default. 328 329 To receive HTTP/3 (QUIC) traffic, specify "quic" 330 parameter. It makes nghttpx listen on UDP port rather 331 than TCP port. UNIX domain socket, "api", and 332 "healthmon" parameters cannot be used with "quic" 333 parameter. 334 335 336 Default: ``*,3000`` 337 338.. option:: --backlog=<N> 339 340 Set listen backlog size. 341 342 Default: ``65536`` 343 344.. option:: --backend-address-family=(auto|IPv4|IPv6) 345 346 Specify address family of backend connections. If 347 "auto" is given, both IPv4 and IPv6 are considered. If 348 "IPv4" is given, only IPv4 address is considered. If 349 "IPv6" is given, only IPv6 address is considered. 350 351 Default: ``auto`` 352 353.. option:: --backend-http-proxy-uri=<URI> 354 355 Specify proxy URI in the form 356 http://[<USER>:<PASS>@]<PROXY>:<PORT>. If a proxy 357 requires authentication, specify <USER> and <PASS>. 358 Note that they must be properly percent-encoded. This 359 proxy is used when the backend connection is HTTP/2. 360 First, make a CONNECT request to the proxy and it 361 connects to the backend on behalf of nghttpx. This 362 forms tunnel. After that, nghttpx performs SSL/TLS 363 handshake with the downstream through the tunnel. The 364 timeouts when connecting and making CONNECT request can 365 be specified by :option:`--backend-read-timeout` and 366 :option:`--backend-write-timeout` options. 367 368 369Performance 370~~~~~~~~~~~ 371 372.. option:: -n, --workers=<N> 373 374 Set the number of worker threads. 375 376 Default: ``1`` 377 378.. option:: --single-thread 379 380 Run everything in one thread inside the worker process. 381 This feature is provided for better debugging 382 experience, or for the platforms which lack thread 383 support. If threading is disabled, this option is 384 always enabled. 385 386.. option:: --read-rate=<SIZE> 387 388 Set maximum average read rate on frontend connection. 389 Setting 0 to this option means read rate is unlimited. 390 391 Default: ``0`` 392 393.. option:: --read-burst=<SIZE> 394 395 Set maximum read burst size on frontend connection. 396 Setting 0 to this option means read burst size is 397 unlimited. 398 399 Default: ``0`` 400 401.. option:: --write-rate=<SIZE> 402 403 Set maximum average write rate on frontend connection. 404 Setting 0 to this option means write rate is unlimited. 405 406 Default: ``0`` 407 408.. option:: --write-burst=<SIZE> 409 410 Set maximum write burst size on frontend connection. 411 Setting 0 to this option means write burst size is 412 unlimited. 413 414 Default: ``0`` 415 416.. option:: --worker-read-rate=<SIZE> 417 418 Set maximum average read rate on frontend connection per 419 worker. Setting 0 to this option means read rate is 420 unlimited. Not implemented yet. 421 422 Default: ``0`` 423 424.. option:: --worker-read-burst=<SIZE> 425 426 Set maximum read burst size on frontend connection per 427 worker. Setting 0 to this option means read burst size 428 is unlimited. Not implemented yet. 429 430 Default: ``0`` 431 432.. option:: --worker-write-rate=<SIZE> 433 434 Set maximum average write rate on frontend connection 435 per worker. Setting 0 to this option means write rate 436 is unlimited. Not implemented yet. 437 438 Default: ``0`` 439 440.. option:: --worker-write-burst=<SIZE> 441 442 Set maximum write burst size on frontend connection per 443 worker. Setting 0 to this option means write burst size 444 is unlimited. Not implemented yet. 445 446 Default: ``0`` 447 448.. option:: --worker-frontend-connections=<N> 449 450 Set maximum number of simultaneous connections frontend 451 accepts. Setting 0 means unlimited. 452 453 Default: ``0`` 454 455.. option:: --backend-connections-per-host=<N> 456 457 Set maximum number of backend concurrent connections 458 (and/or streams in case of HTTP/2) per origin host. 459 This option is meaningful when :option:`--http2-proxy` option is 460 used. The origin host is determined by authority 461 portion of request URI (or :authority header field for 462 HTTP/2). To limit the number of connections per 463 frontend for default mode, use 464 :option:`--backend-connections-per-frontend`\. 465 466 Default: ``8`` 467 468.. option:: --backend-connections-per-frontend=<N> 469 470 Set maximum number of backend concurrent connections 471 (and/or streams in case of HTTP/2) per frontend. This 472 option is only used for default mode. 0 means 473 unlimited. To limit the number of connections per host 474 with :option:`--http2-proxy` option, use 475 :option:`--backend-connections-per-host`\. 476 477 Default: ``0`` 478 479.. option:: --rlimit-nofile=<N> 480 481 Set maximum number of open files (RLIMIT_NOFILE) to <N>. 482 If 0 is given, nghttpx does not set the limit. 483 484 Default: ``0`` 485 486.. option:: --rlimit-memlock=<N> 487 488 Set maximum number of bytes of memory that may be locked 489 into RAM. If 0 is given, nghttpx does not set the 490 limit. 491 492 Default: ``0`` 493 494.. option:: --backend-request-buffer=<SIZE> 495 496 Set buffer size used to store backend request. 497 498 Default: ``16K`` 499 500.. option:: --backend-response-buffer=<SIZE> 501 502 Set buffer size used to store backend response. 503 504 Default: ``128K`` 505 506.. option:: --fastopen=<N> 507 508 Enables "TCP Fast Open" for the listening socket and 509 limits the maximum length for the queue of connections 510 that have not yet completed the three-way handshake. If 511 value is 0 then fast open is disabled. 512 513 Default: ``0`` 514 515.. option:: --no-kqueue 516 517 Don't use kqueue. This option is only applicable for 518 the platforms which have kqueue. For other platforms, 519 this option will be simply ignored. 520 521 522Timeout 523~~~~~~~ 524 525.. option:: --frontend-http2-idle-timeout=<DURATION> 526 527 Specify idle timeout for HTTP/2 frontend connection. If 528 no active streams exist for this duration, connection is 529 closed. 530 531 Default: ``3m`` 532 533.. option:: --frontend-http3-idle-timeout=<DURATION> 534 535 Specify idle timeout for HTTP/3 frontend connection. If 536 no active streams exist for this duration, connection is 537 closed. 538 539 Default: ``3m`` 540 541.. option:: --frontend-write-timeout=<DURATION> 542 543 Specify write timeout for all frontend connections. 544 545 Default: ``30s`` 546 547.. option:: --frontend-keep-alive-timeout=<DURATION> 548 549 Specify keep-alive timeout for frontend HTTP/1 550 connection. 551 552 Default: ``1m`` 553 554.. option:: --frontend-header-timeout=<DURATION> 555 556 Specify duration that the server waits for an HTTP 557 request header fields to be received completely. On 558 timeout, HTTP/1 and HTTP/2 connections are closed. For 559 HTTP/3, the stream is shutdown, and the connection 560 itself is left intact. 561 562 Default: ``1m`` 563 564.. option:: --stream-read-timeout=<DURATION> 565 566 Specify read timeout for HTTP/2 streams. 0 means no 567 timeout. 568 569 Default: ``0`` 570 571.. option:: --stream-write-timeout=<DURATION> 572 573 Specify write timeout for HTTP/2 streams. 0 means no 574 timeout. 575 576 Default: ``1m`` 577 578.. option:: --backend-read-timeout=<DURATION> 579 580 Specify read timeout for backend connection. 581 582 Default: ``1m`` 583 584.. option:: --backend-write-timeout=<DURATION> 585 586 Specify write timeout for backend connection. 587 588 Default: ``30s`` 589 590.. option:: --backend-connect-timeout=<DURATION> 591 592 Specify timeout before establishing TCP connection to 593 backend. 594 595 Default: ``30s`` 596 597.. option:: --backend-keep-alive-timeout=<DURATION> 598 599 Specify keep-alive timeout for backend HTTP/1 600 connection. 601 602 Default: ``2s`` 603 604.. option:: --listener-disable-timeout=<DURATION> 605 606 After accepting connection failed, connection listener 607 is disabled for a given amount of time. Specifying 0 608 disables this feature. 609 610 Default: ``30s`` 611 612.. option:: --frontend-http2-setting-timeout=<DURATION> 613 614 Specify timeout before SETTINGS ACK is received from 615 client. 616 617 Default: ``10s`` 618 619.. option:: --backend-http2-settings-timeout=<DURATION> 620 621 Specify timeout before SETTINGS ACK is received from 622 backend server. 623 624 Default: ``10s`` 625 626.. option:: --backend-max-backoff=<DURATION> 627 628 Specify maximum backoff interval. This is used when 629 doing health check against offline backend (see "fail" 630 parameter in :option:`--backend` option). It is also used to 631 limit the maximum interval to temporarily disable 632 backend when nghttpx failed to connect to it. These 633 intervals are calculated using exponential backoff, and 634 consecutive failed attempts increase the interval. This 635 option caps its maximum value. 636 637 Default: ``2m`` 638 639 640SSL/TLS 641~~~~~~~ 642 643.. option:: --ciphers=<SUITE> 644 645 Set allowed cipher list for frontend connection. The 646 format of the string is described in OpenSSL ciphers(1). 647 This option sets cipher suites for TLSv1.2 or earlier. 648 Use :option:`--tls13-ciphers` for TLSv1.3. 649 650 Default: ``ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384`` 651 652.. option:: --tls13-ciphers=<SUITE> 653 654 Set allowed cipher list for frontend connection. The 655 format of the string is described in OpenSSL ciphers(1). 656 This option sets cipher suites for TLSv1.3. Use 657 :option:`--ciphers` for TLSv1.2 or earlier. 658 659 Default: ``TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256`` 660 661.. option:: --client-ciphers=<SUITE> 662 663 Set allowed cipher list for backend connection. The 664 format of the string is described in OpenSSL ciphers(1). 665 This option sets cipher suites for TLSv1.2 or earlier. 666 Use :option:`--tls13-client-ciphers` for TLSv1.3. 667 668 Default: ``ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384`` 669 670.. option:: --tls13-client-ciphers=<SUITE> 671 672 Set allowed cipher list for backend connection. The 673 format of the string is described in OpenSSL ciphers(1). 674 This option sets cipher suites for TLSv1.3. Use 675 :option:`--tls13-client-ciphers` for TLSv1.2 or earlier. 676 677 Default: ``TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256`` 678 679.. option:: --ecdh-curves=<LIST> 680 681 Set supported curve list for frontend connections. 682 <LIST> is a colon separated list of curve NID or names 683 in the preference order. The supported curves depend on 684 the linked OpenSSL library. This function requires 685 OpenSSL >= 1.0.2. 686 687 Default: ``X25519:P-256:P-384:P-521`` 688 689.. option:: -k, --insecure 690 691 Don't verify backend server's certificate if TLS is 692 enabled for backend connections. 693 694.. option:: --cacert=<PATH> 695 696 Set path to trusted CA certificate file. It is used in 697 backend TLS connections to verify peer's certificate. 698 It is also used to verify OCSP response from the script 699 set by :option:`--fetch-ocsp-response-file`\. The file must be in 700 PEM format. It can contain multiple certificates. If 701 the linked OpenSSL is configured to load system wide 702 certificates, they are loaded at startup regardless of 703 this option. 704 705.. option:: --private-key-passwd-file=<PATH> 706 707 Path to file that contains password for the server's 708 private key. If none is given and the private key is 709 password protected it'll be requested interactively. 710 711.. option:: --subcert=<KEYPATH>:<CERTPATH>[[;<PARAM>]...] 712 713 Specify additional certificate and private key file. 714 nghttpx will choose certificates based on the hostname 715 indicated by client using TLS SNI extension. If nghttpx 716 is built with OpenSSL >= 1.0.2, the shared elliptic 717 curves (e.g., P-256) between client and server are also 718 taken into consideration. This allows nghttpx to send 719 ECDSA certificate to modern clients, while sending RSA 720 based certificate to older clients. This option can be 721 used multiple times. To make OCSP stapling work, 722 <CERTPATH> must be absolute path. 723 724 Additional parameter can be specified in <PARAM>. The 725 available <PARAM> is "sct-dir=<DIR>". 726 727 "sct-dir=<DIR>" specifies the path to directory which 728 contains \*.sct files for TLS 729 signed_certificate_timestamp extension (RFC 6962). This 730 feature requires OpenSSL >= 1.0.2. See also 731 :option:`--tls-sct-dir` option. 732 733.. option:: --dh-param-file=<PATH> 734 735 Path to file that contains DH parameters in PEM format. 736 Without this option, DHE cipher suites are not 737 available. 738 739.. option:: --alpn-list=<LIST> 740 741 Comma delimited list of ALPN protocol identifier sorted 742 in the order of preference. That means most desirable 743 protocol comes first. The parameter must be delimited 744 by a single comma only and any white spaces are treated 745 as a part of protocol string. 746 747 Default: ``h2,h2-16,h2-14,http/1.1`` 748 749.. option:: --verify-client 750 751 Require and verify client certificate. 752 753.. option:: --verify-client-cacert=<PATH> 754 755 Path to file that contains CA certificates to verify 756 client certificate. The file must be in PEM format. It 757 can contain multiple certificates. 758 759.. option:: --verify-client-tolerate-expired 760 761 Accept expired client certificate. Operator should 762 handle the expired client certificate by some means 763 (e.g., mruby script). Otherwise, this option might 764 cause a security risk. 765 766.. option:: --client-private-key-file=<PATH> 767 768 Path to file that contains client private key used in 769 backend client authentication. 770 771.. option:: --client-cert-file=<PATH> 772 773 Path to file that contains client certificate used in 774 backend client authentication. 775 776.. option:: --tls-min-proto-version=<VER> 777 778 Specify minimum SSL/TLS protocol. The name matching is 779 done in case-insensitive manner. The versions between 780 :option:`--tls-min-proto-version` and :option:`\--tls-max-proto-version` are 781 enabled. If the protocol list advertised by client does 782 not overlap this range, you will receive the error 783 message "unknown protocol". If a protocol version lower 784 than TLSv1.2 is specified, make sure that the compatible 785 ciphers are included in :option:`--ciphers` option. The default 786 cipher list only includes ciphers compatible with 787 TLSv1.2 or above. The available versions are: 788 TLSv1.3, TLSv1.2, TLSv1.1, and TLSv1.0 789 790 Default: ``TLSv1.2`` 791 792.. option:: --tls-max-proto-version=<VER> 793 794 Specify maximum SSL/TLS protocol. The name matching is 795 done in case-insensitive manner. The versions between 796 :option:`--tls-min-proto-version` and :option:`\--tls-max-proto-version` are 797 enabled. If the protocol list advertised by client does 798 not overlap this range, you will receive the error 799 message "unknown protocol". The available versions are: 800 TLSv1.3, TLSv1.2, TLSv1.1, and TLSv1.0 801 802 Default: ``TLSv1.3`` 803 804.. option:: --tls-ticket-key-file=<PATH> 805 806 Path to file that contains random data to construct TLS 807 session ticket parameters. If aes-128-cbc is given in 808 :option:`--tls-ticket-key-cipher`\, the file must contain exactly 809 48 bytes. If aes-256-cbc is given in 810 :option:`--tls-ticket-key-cipher`\, the file must contain exactly 811 80 bytes. This options can be used repeatedly to 812 specify multiple ticket parameters. If several files 813 are given, only the first key is used to encrypt TLS 814 session tickets. Other keys are accepted but server 815 will issue new session ticket with first key. This 816 allows session key rotation. Please note that key 817 rotation does not occur automatically. User should 818 rearrange files or change options values and restart 819 nghttpx gracefully. If opening or reading given file 820 fails, all loaded keys are discarded and it is treated 821 as if none of this option is given. If this option is 822 not given or an error occurred while opening or reading 823 a file, key is generated every 1 hour internally and 824 they are valid for 12 hours. This is recommended if 825 ticket key sharing between nghttpx instances is not 826 required. 827 828.. option:: --tls-ticket-key-memcached=<HOST>,<PORT>[;tls] 829 830 Specify address of memcached server to get TLS ticket 831 keys for session resumption. This enables shared TLS 832 ticket key between multiple nghttpx instances. nghttpx 833 does not set TLS ticket key to memcached. The external 834 ticket key generator is required. nghttpx just gets TLS 835 ticket keys from memcached, and use them, possibly 836 replacing current set of keys. It is up to extern TLS 837 ticket key generator to rotate keys frequently. See 838 "TLS SESSION TICKET RESUMPTION" section in manual page 839 to know the data format in memcached entry. Optionally, 840 memcached connection can be encrypted with TLS by 841 specifying "tls" parameter. 842 843.. option:: --tls-ticket-key-memcached-address-family=(auto|IPv4|IPv6) 844 845 Specify address family of memcached connections to get 846 TLS ticket keys. If "auto" is given, both IPv4 and IPv6 847 are considered. If "IPv4" is given, only IPv4 address 848 is considered. If "IPv6" is given, only IPv6 address is 849 considered. 850 851 Default: ``auto`` 852 853.. option:: --tls-ticket-key-memcached-interval=<DURATION> 854 855 Set interval to get TLS ticket keys from memcached. 856 857 Default: ``10m`` 858 859.. option:: --tls-ticket-key-memcached-max-retry=<N> 860 861 Set maximum number of consecutive retries before 862 abandoning TLS ticket key retrieval. If this number is 863 reached, the attempt is considered as failure, and 864 "failure" count is incremented by 1, which contributed 865 to the value controlled 866 :option:`--tls-ticket-key-memcached-max-fail` option. 867 868 Default: ``3`` 869 870.. option:: --tls-ticket-key-memcached-max-fail=<N> 871 872 Set maximum number of consecutive failure before 873 disabling TLS ticket until next scheduled key retrieval. 874 875 Default: ``2`` 876 877.. option:: --tls-ticket-key-cipher=<CIPHER> 878 879 Specify cipher to encrypt TLS session ticket. Specify 880 either aes-128-cbc or aes-256-cbc. By default, 881 aes-128-cbc is used. 882 883.. option:: --tls-ticket-key-memcached-cert-file=<PATH> 884 885 Path to client certificate for memcached connections to 886 get TLS ticket keys. 887 888.. option:: --tls-ticket-key-memcached-private-key-file=<PATH> 889 890 Path to client private key for memcached connections to 891 get TLS ticket keys. 892 893.. option:: --fetch-ocsp-response-file=<PATH> 894 895 Path to fetch-ocsp-response script file. It should be 896 absolute path. 897 898 Default: ``/usr/local/share/nghttp2/fetch-ocsp-response`` 899 900.. option:: --ocsp-update-interval=<DURATION> 901 902 Set interval to update OCSP response cache. 903 904 Default: ``4h`` 905 906.. option:: --ocsp-startup 907 908 Start accepting connections after initial attempts to 909 get OCSP responses finish. It does not matter some of 910 the attempts fail. This feature is useful if OCSP 911 responses must be available before accepting 912 connections. 913 914.. option:: --no-verify-ocsp 915 916 nghttpx does not verify OCSP response. 917 918.. option:: --no-ocsp 919 920 Disable OCSP stapling. 921 922.. option:: --tls-session-cache-memcached=<HOST>,<PORT>[;tls] 923 924 Specify address of memcached server to store session 925 cache. This enables shared session cache between 926 multiple nghttpx instances. Optionally, memcached 927 connection can be encrypted with TLS by specifying "tls" 928 parameter. 929 930.. option:: --tls-session-cache-memcached-address-family=(auto|IPv4|IPv6) 931 932 Specify address family of memcached connections to store 933 session cache. If "auto" is given, both IPv4 and IPv6 934 are considered. If "IPv4" is given, only IPv4 address 935 is considered. If "IPv6" is given, only IPv6 address is 936 considered. 937 938 Default: ``auto`` 939 940.. option:: --tls-session-cache-memcached-cert-file=<PATH> 941 942 Path to client certificate for memcached connections to 943 store session cache. 944 945.. option:: --tls-session-cache-memcached-private-key-file=<PATH> 946 947 Path to client private key for memcached connections to 948 store session cache. 949 950.. option:: --tls-dyn-rec-warmup-threshold=<SIZE> 951 952 Specify the threshold size for TLS dynamic record size 953 behaviour. During a TLS session, after the threshold 954 number of bytes have been written, the TLS record size 955 will be increased to the maximum allowed (16K). The max 956 record size will continue to be used on the active TLS 957 session. After :option:`--tls-dyn-rec-idle-timeout` has elapsed, 958 the record size is reduced to 1300 bytes. Specify 0 to 959 always use the maximum record size, regardless of idle 960 period. This behaviour applies to all TLS based 961 frontends, and TLS HTTP/2 backends. 962 963 Default: ``1M`` 964 965.. option:: --tls-dyn-rec-idle-timeout=<DURATION> 966 967 Specify TLS dynamic record size behaviour timeout. See 968 :option:`--tls-dyn-rec-warmup-threshold` for more information. 969 This behaviour applies to all TLS based frontends, and 970 TLS HTTP/2 backends. 971 972 Default: ``1s`` 973 974.. option:: --no-http2-cipher-block-list 975 976 Allow block listed cipher suite on frontend HTTP/2 977 connection. See 978 https://tools.ietf.org/html/rfc7540#appendix-A for the 979 complete HTTP/2 cipher suites block list. 980 981.. option:: --client-no-http2-cipher-block-list 982 983 Allow block listed cipher suite on backend HTTP/2 984 connection. See 985 https://tools.ietf.org/html/rfc7540#appendix-A for the 986 complete HTTP/2 cipher suites block list. 987 988.. option:: --tls-sct-dir=<DIR> 989 990 Specifies the directory where \*.sct files exist. All 991 \*.sct files in <DIR> are read, and sent as 992 extension_data of TLS signed_certificate_timestamp (RFC 993 6962) to client. These \*.sct files are for the 994 certificate specified in positional command-line 995 argument <CERT>, or certificate option in configuration 996 file. For additional certificates, use :option:`--subcert` 997 option. This option requires OpenSSL >= 1.0.2. 998 999.. option:: --psk-secrets=<PATH> 1000 1001 Read list of PSK identity and secrets from <PATH>. This 1002 is used for frontend connection. The each line of input 1003 file is formatted as <identity>:<hex-secret>, where 1004 <identity> is PSK identity, and <hex-secret> is secret 1005 in hex. An empty line, and line which starts with '#' 1006 are skipped. The default enabled cipher list might not 1007 contain any PSK cipher suite. In that case, desired PSK 1008 cipher suites must be enabled using :option:`--ciphers` option. 1009 The desired PSK cipher suite may be block listed by 1010 HTTP/2. To use those cipher suites with HTTP/2, 1011 consider to use :option:`--no-http2-cipher-block-list` option. 1012 But be aware its implications. 1013 1014.. option:: --client-psk-secrets=<PATH> 1015 1016 Read PSK identity and secrets from <PATH>. This is used 1017 for backend connection. The each line of input file is 1018 formatted as <identity>:<hex-secret>, where <identity> 1019 is PSK identity, and <hex-secret> is secret in hex. An 1020 empty line, and line which starts with '#' are skipped. 1021 The first identity and secret pair encountered is used. 1022 The default enabled cipher list might not contain any 1023 PSK cipher suite. In that case, desired PSK cipher 1024 suites must be enabled using :option:`--client-ciphers` option. 1025 The desired PSK cipher suite may be block listed by 1026 HTTP/2. To use those cipher suites with HTTP/2, 1027 consider to use :option:`--client-no-http2-cipher-block-list` 1028 option. But be aware its implications. 1029 1030.. option:: --tls-no-postpone-early-data 1031 1032 By default, except for QUIC connections, nghttpx 1033 postpones forwarding HTTP requests sent in early data, 1034 including those sent in partially in it, until TLS 1035 handshake finishes. If all backend server recognizes 1036 "Early-Data" header field, using this option makes 1037 nghttpx not postpone forwarding request and get full 1038 potential of 0-RTT data. 1039 1040.. option:: --tls-max-early-data=<SIZE> 1041 1042 Sets the maximum amount of 0-RTT data that server 1043 accepts. 1044 1045 Default: ``16K`` 1046 1047.. option:: --tls-ktls 1048 1049 Enable ktls. For server, ktls is enable if 1050 :option:`--tls-session-cache-memcached` is not configured. 1051 1052 1053HTTP/2 1054~~~~~~ 1055 1056.. option:: -c, --frontend-http2-max-concurrent-streams=<N> 1057 1058 Set the maximum number of the concurrent streams in one 1059 frontend HTTP/2 session. 1060 1061 Default: ``100`` 1062 1063.. option:: --backend-http2-max-concurrent-streams=<N> 1064 1065 Set the maximum number of the concurrent streams in one 1066 backend HTTP/2 session. This sets maximum number of 1067 concurrent opened pushed streams. The maximum number of 1068 concurrent requests are set by a remote server. 1069 1070 Default: ``100`` 1071 1072.. option:: --frontend-http2-window-size=<SIZE> 1073 1074 Sets the per-stream initial window size of HTTP/2 1075 frontend connection. 1076 1077 Default: ``65535`` 1078 1079.. option:: --frontend-http2-connection-window-size=<SIZE> 1080 1081 Sets the per-connection window size of HTTP/2 frontend 1082 connection. 1083 1084 Default: ``65535`` 1085 1086.. option:: --backend-http2-window-size=<SIZE> 1087 1088 Sets the initial window size of HTTP/2 backend 1089 connection. 1090 1091 Default: ``65535`` 1092 1093.. option:: --backend-http2-connection-window-size=<SIZE> 1094 1095 Sets the per-connection window size of HTTP/2 backend 1096 connection. 1097 1098 Default: ``2147483647`` 1099 1100.. option:: --http2-no-cookie-crumbling 1101 1102 Don't crumble cookie header field. 1103 1104.. option:: --padding=<N> 1105 1106 Add at most <N> bytes to a HTTP/2 frame payload as 1107 padding. Specify 0 to disable padding. This option is 1108 meant for debugging purpose and not intended to enhance 1109 protocol security. 1110 1111.. option:: --no-server-push 1112 1113 Disable HTTP/2 server push. Server push is supported by 1114 default mode and HTTP/2 frontend via Link header field. 1115 It is also supported if both frontend and backend are 1116 HTTP/2 in default mode. In this case, server push from 1117 backend session is relayed to frontend, and server push 1118 via Link header field is also supported. 1119 1120.. option:: --frontend-http2-optimize-write-buffer-size 1121 1122 (Experimental) Enable write buffer size optimization in 1123 frontend HTTP/2 TLS connection. This optimization aims 1124 to reduce write buffer size so that it only contains 1125 bytes which can send immediately. This makes server 1126 more responsive to prioritized HTTP/2 stream because the 1127 buffering of lower priority stream is reduced. This 1128 option is only effective on recent Linux platform. 1129 1130.. option:: --frontend-http2-optimize-window-size 1131 1132 (Experimental) Automatically tune connection level 1133 window size of frontend HTTP/2 TLS connection. If this 1134 feature is enabled, connection window size starts with 1135 the default window size, 65535 bytes. nghttpx 1136 automatically adjusts connection window size based on 1137 TCP receiving window size. The maximum window size is 1138 capped by the value specified by 1139 :option:`--frontend-http2-connection-window-size`\. Since the 1140 stream is subject to stream level window size, it should 1141 be adjusted using :option:`--frontend-http2-window-size` option as 1142 well. This option is only effective on recent Linux 1143 platform. 1144 1145.. option:: --frontend-http2-encoder-dynamic-table-size=<SIZE> 1146 1147 Specify the maximum dynamic table size of HPACK encoder 1148 in the frontend HTTP/2 connection. The decoder (client) 1149 specifies the maximum dynamic table size it accepts. 1150 Then the negotiated dynamic table size is the minimum of 1151 this option value and the value which client specified. 1152 1153 Default: ``4K`` 1154 1155.. option:: --frontend-http2-decoder-dynamic-table-size=<SIZE> 1156 1157 Specify the maximum dynamic table size of HPACK decoder 1158 in the frontend HTTP/2 connection. 1159 1160 Default: ``4K`` 1161 1162.. option:: --backend-http2-encoder-dynamic-table-size=<SIZE> 1163 1164 Specify the maximum dynamic table size of HPACK encoder 1165 in the backend HTTP/2 connection. The decoder (backend) 1166 specifies the maximum dynamic table size it accepts. 1167 Then the negotiated dynamic table size is the minimum of 1168 this option value and the value which backend specified. 1169 1170 Default: ``4K`` 1171 1172.. option:: --backend-http2-decoder-dynamic-table-size=<SIZE> 1173 1174 Specify the maximum dynamic table size of HPACK decoder 1175 in the backend HTTP/2 connection. 1176 1177 Default: ``4K`` 1178 1179 1180Mode 1181~~~~ 1182 1183.. describe:: (default mode) 1184 1185 1186 Accept HTTP/2, and HTTP/1.1 over SSL/TLS. "no-tls" 1187 parameter is used in :option:`--frontend` option, accept HTTP/2 1188 and HTTP/1.1 over cleartext TCP. The incoming HTTP/1.1 1189 connection can be upgraded to HTTP/2 through HTTP 1190 Upgrade. 1191 1192.. option:: -s, --http2-proxy 1193 1194 Like default mode, but enable forward proxy. This is so 1195 called HTTP/2 proxy mode. 1196 1197 1198Logging 1199~~~~~~~ 1200 1201.. option:: -L, --log-level=<LEVEL> 1202 1203 Set the severity level of log output. <LEVEL> must be 1204 one of INFO, NOTICE, WARN, ERROR and FATAL. 1205 1206 Default: ``NOTICE`` 1207 1208.. option:: --accesslog-file=<PATH> 1209 1210 Set path to write access log. To reopen file, send USR1 1211 signal to nghttpx. 1212 1213.. option:: --accesslog-syslog 1214 1215 Send access log to syslog. If this option is used, 1216 :option:`--accesslog-file` option is ignored. 1217 1218.. option:: --accesslog-format=<FORMAT> 1219 1220 Specify format string for access log. The default 1221 format is combined format. The following variables are 1222 available: 1223 1224 * $remote_addr: client IP address. 1225 * $time_local: local time in Common Log format. 1226 * $time_iso8601: local time in ISO 8601 format. 1227 * $request: HTTP request line. 1228 * $status: HTTP response status code. 1229 * $body_bytes_sent: the number of bytes sent to client 1230 as response body. 1231 * $http_<VAR>: value of HTTP request header <VAR> where 1232 '_' in <VAR> is replaced with '-'. 1233 * $remote_port: client port. 1234 * $server_port: server port. 1235 * $request_time: request processing time in seconds with 1236 milliseconds resolution. 1237 * $pid: PID of the running process. 1238 * $alpn: ALPN identifier of the protocol which generates 1239 the response. For HTTP/1, ALPN is always http/1.1, 1240 regardless of minor version. 1241 * $tls_cipher: cipher used for SSL/TLS connection. 1242 * $tls_client_fingerprint_sha256: SHA-256 fingerprint of 1243 client certificate. 1244 * $tls_client_fingerprint_sha1: SHA-1 fingerprint of 1245 client certificate. 1246 * $tls_client_subject_name: subject name in client 1247 certificate. 1248 * $tls_client_issuer_name: issuer name in client 1249 certificate. 1250 * $tls_client_serial: serial number in client 1251 certificate. 1252 * $tls_protocol: protocol for SSL/TLS connection. 1253 * $tls_session_id: session ID for SSL/TLS connection. 1254 * $tls_session_reused: "r" if SSL/TLS session was 1255 reused. Otherwise, "." 1256 * $tls_sni: SNI server name for SSL/TLS connection. 1257 * $backend_host: backend host used to fulfill the 1258 request. "-" if backend host is not available. 1259 * $backend_port: backend port used to fulfill the 1260 request. "-" if backend host is not available. 1261 * $method: HTTP method 1262 * $path: Request path including query. For CONNECT 1263 request, authority is recorded. 1264 * $path_without_query: $path up to the first '?' 1265 character. For CONNECT request, authority is 1266 recorded. 1267 * $protocol_version: HTTP version (e.g., HTTP/1.1, 1268 HTTP/2) 1269 1270 The variable can be enclosed by "{" and "}" for 1271 disambiguation (e.g., ${remote_addr}). 1272 1273 1274 Default: ``$remote_addr - - [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"`` 1275 1276.. option:: --accesslog-write-early 1277 1278 Write access log when response header fields are 1279 received from backend rather than when request 1280 transaction finishes. 1281 1282.. option:: --errorlog-file=<PATH> 1283 1284 Set path to write error log. To reopen file, send USR1 1285 signal to nghttpx. stderr will be redirected to the 1286 error log file unless :option:`--errorlog-syslog` is used. 1287 1288 Default: ``/dev/stderr`` 1289 1290.. option:: --errorlog-syslog 1291 1292 Send error log to syslog. If this option is used, 1293 :option:`--errorlog-file` option is ignored. 1294 1295.. option:: --syslog-facility=<FACILITY> 1296 1297 Set syslog facility to <FACILITY>. 1298 1299 Default: ``daemon`` 1300 1301 1302HTTP 1303~~~~ 1304 1305.. option:: --add-x-forwarded-for 1306 1307 Append X-Forwarded-For header field to the downstream 1308 request. 1309 1310.. option:: --strip-incoming-x-forwarded-for 1311 1312 Strip X-Forwarded-For header field from inbound client 1313 requests. 1314 1315.. option:: --no-add-x-forwarded-proto 1316 1317 Don't append additional X-Forwarded-Proto header field 1318 to the backend request. If inbound client sets 1319 X-Forwarded-Proto, and 1320 :option:`--no-strip-incoming-x-forwarded-proto` option is used, 1321 they are passed to the backend. 1322 1323.. option:: --no-strip-incoming-x-forwarded-proto 1324 1325 Don't strip X-Forwarded-Proto header field from inbound 1326 client requests. 1327 1328.. option:: --add-forwarded=<LIST> 1329 1330 Append RFC 7239 Forwarded header field with parameters 1331 specified in comma delimited list <LIST>. The supported 1332 parameters are "by", "for", "host", and "proto". By 1333 default, the value of "by" and "for" parameters are 1334 obfuscated string. See :option:`--forwarded-by` and 1335 :option:`--forwarded-for` options respectively. Note that nghttpx 1336 does not translate non-standard X-Forwarded-\* header 1337 fields into Forwarded header field, and vice versa. 1338 1339.. option:: --strip-incoming-forwarded 1340 1341 Strip Forwarded header field from inbound client 1342 requests. 1343 1344.. option:: --forwarded-by=(obfuscated|ip|<VALUE>) 1345 1346 Specify the parameter value sent out with "by" parameter 1347 of Forwarded header field. If "obfuscated" is given, 1348 the string is randomly generated at startup. If "ip" is 1349 given, the interface address of the connection, 1350 including port number, is sent with "by" parameter. In 1351 case of UNIX domain socket, "localhost" is used instead 1352 of address and port. User can also specify the static 1353 obfuscated string. The limitation is that it must start 1354 with "_", and only consists of character set 1355 [A-Za-z0-9._-], as described in RFC 7239. 1356 1357 Default: ``obfuscated`` 1358 1359.. option:: --forwarded-for=(obfuscated|ip) 1360 1361 Specify the parameter value sent out with "for" 1362 parameter of Forwarded header field. If "obfuscated" is 1363 given, the string is randomly generated for each client 1364 connection. If "ip" is given, the remote client address 1365 of the connection, without port number, is sent with 1366 "for" parameter. In case of UNIX domain socket, 1367 "localhost" is used instead of address. 1368 1369 Default: ``obfuscated`` 1370 1371.. option:: --no-via 1372 1373 Don't append to Via header field. If Via header field 1374 is received, it is left unaltered. 1375 1376.. option:: --no-strip-incoming-early-data 1377 1378 Don't strip Early-Data header field from inbound client 1379 requests. 1380 1381.. option:: --no-location-rewrite 1382 1383 Don't rewrite location header field in default mode. 1384 When :option:`--http2-proxy` is used, location header field will 1385 not be altered regardless of this option. 1386 1387.. option:: --host-rewrite 1388 1389 Rewrite host and :authority header fields in default 1390 mode. When :option:`--http2-proxy` is used, these headers will 1391 not be altered regardless of this option. 1392 1393.. option:: --altsvc=<PROTOID,PORT[,HOST,[ORIGIN[,PARAMS]]]> 1394 1395 Specify protocol ID, port, host and origin of 1396 alternative service. <HOST>, <ORIGIN> and <PARAMS> are 1397 optional. Empty <HOST> and <ORIGIN> are allowed and 1398 they are treated as nothing is specified. They are 1399 advertised in alt-svc header field only in HTTP/1.1 1400 frontend. This option can be used multiple times to 1401 specify multiple alternative services. 1402 Example: :option:`--altsvc`\="h2,443,,,ma=3600; persist=1" 1403 1404.. option:: --http2-altsvc=<PROTOID,PORT[,HOST,[ORIGIN[,PARAMS]]]> 1405 1406 Just like :option:`--altsvc` option, but this altsvc is only sent 1407 in HTTP/2 frontend. 1408 1409.. option:: --add-request-header=<HEADER> 1410 1411 Specify additional header field to add to request header 1412 set. The field name must be lowercase. This option 1413 just appends header field and won't replace anything 1414 already set. This option can be used several times to 1415 specify multiple header fields. 1416 Example: :option:`--add-request-header`\="foo: bar" 1417 1418.. option:: --add-response-header=<HEADER> 1419 1420 Specify additional header field to add to response 1421 header set. The field name must be lowercase. This 1422 option just appends header field and won't replace 1423 anything already set. This option can be used several 1424 times to specify multiple header fields. 1425 Example: :option:`--add-response-header`\="foo: bar" 1426 1427.. option:: --request-header-field-buffer=<SIZE> 1428 1429 Set maximum buffer size for incoming HTTP request header 1430 field list. This is the sum of header name and value in 1431 bytes. If trailer fields exist, they are counted 1432 towards this number. 1433 1434 Default: ``64K`` 1435 1436.. option:: --max-request-header-fields=<N> 1437 1438 Set maximum number of incoming HTTP request header 1439 fields. If trailer fields exist, they are counted 1440 towards this number. 1441 1442 Default: ``100`` 1443 1444.. option:: --response-header-field-buffer=<SIZE> 1445 1446 Set maximum buffer size for incoming HTTP response 1447 header field list. This is the sum of header name and 1448 value in bytes. If trailer fields exist, they are 1449 counted towards this number. 1450 1451 Default: ``64K`` 1452 1453.. option:: --max-response-header-fields=<N> 1454 1455 Set maximum number of incoming HTTP response header 1456 fields. If trailer fields exist, they are counted 1457 towards this number. 1458 1459 Default: ``500`` 1460 1461.. option:: --error-page=(<CODE>|*)=<PATH> 1462 1463 Set file path to custom error page served when nghttpx 1464 originally generates HTTP error status code <CODE>. 1465 <CODE> must be greater than or equal to 400, and at most 1466 599. If "\*" is used instead of <CODE>, it matches all 1467 HTTP status code. If error status code comes from 1468 backend server, the custom error pages are not used. 1469 1470.. option:: --server-name=<NAME> 1471 1472 Change server response header field value to <NAME>. 1473 1474 Default: ``nghttpx`` 1475 1476.. option:: --no-server-rewrite 1477 1478 Don't rewrite server header field in default mode. When 1479 :option:`--http2-proxy` is used, these headers will not be altered 1480 regardless of this option. 1481 1482.. option:: --redirect-https-port=<PORT> 1483 1484 Specify the port number which appears in Location header 1485 field when redirect to HTTPS URI is made due to 1486 "redirect-if-not-tls" parameter in :option:`--backend` option. 1487 1488 Default: ``443`` 1489 1490.. option:: --require-http-scheme 1491 1492 Always require http or https scheme in HTTP request. It 1493 also requires that https scheme must be used for an 1494 encrypted connection. Otherwise, http scheme must be 1495 used. This option is recommended for a server 1496 deployment which directly faces clients and the services 1497 it provides only require http or https scheme. 1498 1499 1500API 1501~~~ 1502 1503.. option:: --api-max-request-body=<SIZE> 1504 1505 Set the maximum size of request body for API request. 1506 1507 Default: ``32M`` 1508 1509 1510DNS 1511~~~ 1512 1513.. option:: --dns-cache-timeout=<DURATION> 1514 1515 Set duration that cached DNS results remain valid. Note 1516 that nghttpx caches the unsuccessful results as well. 1517 1518 Default: ``10s`` 1519 1520.. option:: --dns-lookup-timeout=<DURATION> 1521 1522 Set timeout that DNS server is given to respond to the 1523 initial DNS query. For the 2nd and later queries, 1524 server is given time based on this timeout, and it is 1525 scaled linearly. 1526 1527 Default: ``5s`` 1528 1529.. option:: --dns-max-try=<N> 1530 1531 Set the number of DNS query before nghttpx gives up name 1532 lookup. 1533 1534 Default: ``2`` 1535 1536.. option:: --frontend-max-requests=<N> 1537 1538 The number of requests that single frontend connection 1539 can process. For HTTP/2, this is the number of streams 1540 in one HTTP/2 connection. For HTTP/1, this is the 1541 number of keep alive requests. This is hint to nghttpx, 1542 and it may allow additional few requests. The default 1543 value is unlimited. 1544 1545 1546Debug 1547~~~~~ 1548 1549.. option:: --frontend-http2-dump-request-header=<PATH> 1550 1551 Dumps request headers received by HTTP/2 frontend to the 1552 file denoted in <PATH>. The output is done in HTTP/1 1553 header field format and each header block is followed by 1554 an empty line. This option is not thread safe and MUST 1555 NOT be used with option :option:`-n`\<N>, where <N> >= 2. 1556 1557.. option:: --frontend-http2-dump-response-header=<PATH> 1558 1559 Dumps response headers sent from HTTP/2 frontend to the 1560 file denoted in <PATH>. The output is done in HTTP/1 1561 header field format and each header block is followed by 1562 an empty line. This option is not thread safe and MUST 1563 NOT be used with option :option:`-n`\<N>, where <N> >= 2. 1564 1565.. option:: -o, --frontend-frame-debug 1566 1567 Print HTTP/2 frames in frontend to stderr. This option 1568 is not thread safe and MUST NOT be used with option 1569 :option:`-n`\=N, where N >= 2. 1570 1571 1572Process 1573~~~~~~~ 1574 1575.. option:: -D, --daemon 1576 1577 Run in a background. If :option:`-D` is used, the current working 1578 directory is changed to '*/*'. 1579 1580.. option:: --pid-file=<PATH> 1581 1582 Set path to save PID of this program. 1583 1584.. option:: --user=<USER> 1585 1586 Run this program as <USER>. This option is intended to 1587 be used to drop root privileges. 1588 1589.. option:: --single-process 1590 1591 Run this program in a single process mode for debugging 1592 purpose. Without this option, nghttpx creates at least 1593 2 processes: main and worker processes. If this option 1594 is used, main and worker are unified into a single 1595 process. nghttpx still spawns additional process if 1596 neverbleed is used. In the single process mode, the 1597 signal handling feature is disabled. 1598 1599.. option:: --max-worker-processes=<N> 1600 1601 The maximum number of worker processes. nghttpx spawns 1602 new worker process when it reloads its configuration. 1603 The previous worker process enters graceful termination 1604 period and will terminate when it finishes handling the 1605 existing connections. However, if reloading 1606 configurations happen very frequently, the worker 1607 processes might be piled up if they take a bit long time 1608 to finish the existing connections. With this option, 1609 if the number of worker processes exceeds the given 1610 value, the oldest worker process is terminated 1611 immediately. Specifying 0 means no limit and it is the 1612 default behaviour. 1613 1614.. option:: --worker-process-grace-shutdown-period=<DURATION> 1615 1616 Maximum period for a worker process to terminate 1617 gracefully. When a worker process enters in graceful 1618 shutdown period (e.g., when nghttpx reloads its 1619 configuration) and it does not finish handling the 1620 existing connections in the given period of time, it is 1621 immediately terminated. Specifying 0 means no limit and 1622 it is the default behaviour. 1623 1624 1625Scripting 1626~~~~~~~~~ 1627 1628.. option:: --mruby-file=<PATH> 1629 1630 Set mruby script file 1631 1632.. option:: --ignore-per-pattern-mruby-error 1633 1634 Ignore mruby compile error for per-pattern mruby script 1635 file. If error occurred, it is treated as if no mruby 1636 file were specified for the pattern. 1637 1638 1639HTTP/3 and QUIC 1640~~~~~~~~~~~~~~~ 1641 1642.. option:: --frontend-quic-idle-timeout=<DURATION> 1643 1644 Specify an idle timeout for QUIC connection. 1645 1646 Default: ``30s`` 1647 1648.. option:: --frontend-quic-debug-log 1649 1650 Output QUIC debug log to */dev/stderr.* 1651 1652.. option:: --quic-bpf-program-file=<PATH> 1653 1654 Specify a path to eBPF program file reuseport_kern.o to 1655 direct an incoming QUIC UDP datagram to a correct 1656 socket. 1657 1658 Default: ``/usr/local/lib/nghttp2/reuseport_kern.o`` 1659 1660.. option:: --frontend-quic-early-data 1661 1662 Enable early data on frontend QUIC connections. nghttpx 1663 sends "Early-Data" header field to a backend server if a 1664 request is received in early data and handshake has not 1665 finished. All backend servers should deal with possibly 1666 replayed requests. 1667 1668.. option:: --frontend-quic-qlog-dir=<DIR> 1669 1670 Specify a directory where a qlog file is written for 1671 frontend QUIC connections. A qlog file is created per 1672 each QUIC connection. The file name is ISO8601 basic 1673 format, followed by "-", server Source Connection ID and 1674 ".sqlog". 1675 1676.. option:: --frontend-quic-require-token 1677 1678 Require an address validation token for a frontend QUIC 1679 connection. Server sends a token in Retry packet or 1680 NEW_TOKEN frame in the previous connection. 1681 1682.. option:: --frontend-quic-congestion-controller=<CC> 1683 1684 Specify a congestion controller algorithm for a frontend 1685 QUIC connection. <CC> should be either "cubic" or 1686 "bbr". 1687 1688 Default: ``cubic`` 1689 1690.. option:: --frontend-quic-secret-file=<PATH> 1691 1692 Path to file that contains secure random data to be used 1693 as QUIC keying materials. It is used to derive keys for 1694 encrypting tokens and Connection IDs. It is not used to 1695 encrypt QUIC packets. Each line of this file must 1696 contain exactly 136 bytes hex-encoded string (when 1697 decoded the byte string is 68 bytes long). The first 3 1698 bits of decoded byte string are used to identify the 1699 keying material. An empty line or a line which starts 1700 '#' is ignored. The file can contain more than one 1701 keying materials. Because the identifier is 3 bits, at 1702 most 8 keying materials are read and the remaining data 1703 is discarded. The first keying material in the file is 1704 primarily used for encryption and decryption for new 1705 connection. The other ones are used to decrypt data for 1706 the existing connections. Specifying multiple keying 1707 materials enables key rotation. Please note that key 1708 rotation does not occur automatically. User should 1709 update files or change options values and restart 1710 nghttpx gracefully. If opening or reading given file 1711 fails, all loaded keying materials are discarded and it 1712 is treated as if none of this option is given. If this 1713 option is not given or an error occurred while opening 1714 or reading a file, a keying material is generated 1715 internally on startup and reload. 1716 1717.. option:: --quic-server-id=<HEXSTRING> 1718 1719 Specify server ID encoded in Connection ID to identify 1720 this particular server instance. Connection ID is 1721 encrypted and this part is not visible in public. It 1722 must be 4 bytes long and must be encoded in hex string 1723 (which is 8 bytes long). If this option is omitted, a 1724 random server ID is generated on startup and 1725 configuration reload. 1726 1727.. option:: --frontend-quic-initial-rtt=<DURATION> 1728 1729 Specify the initial RTT of the frontend QUIC connection. 1730 1731 Default: ``333ms`` 1732 1733.. option:: --no-quic-bpf 1734 1735 Disable eBPF. 1736 1737.. option:: --frontend-http3-window-size=<SIZE> 1738 1739 Sets the per-stream initial window size of HTTP/3 1740 frontend connection. 1741 1742 Default: ``256K`` 1743 1744.. option:: --frontend-http3-connection-window-size=<SIZE> 1745 1746 Sets the per-connection window size of HTTP/3 frontend 1747 connection. 1748 1749 Default: ``1M`` 1750 1751.. option:: --frontend-http3-max-window-size=<SIZE> 1752 1753 Sets the maximum per-stream window size of HTTP/3 1754 frontend connection. The window size is adjusted based 1755 on the receiving rate of stream data. The initial value 1756 is the value specified by :option:`--frontend-http3-window-size` 1757 and the window size grows up to <SIZE> bytes. 1758 1759 Default: ``6M`` 1760 1761.. option:: --frontend-http3-max-connection-window-size=<SIZE> 1762 1763 Sets the maximum per-connection window size of HTTP/3 1764 frontend connection. The window size is adjusted based 1765 on the receiving rate of stream data. The initial value 1766 is the value specified by 1767 :option:`--frontend-http3-connection-window-size` and the window 1768 size grows up to <SIZE> bytes. 1769 1770 Default: ``8M`` 1771 1772.. option:: --frontend-http3-max-concurrent-streams=<N> 1773 1774 Set the maximum number of the concurrent streams in one 1775 frontend HTTP/3 connection. 1776 1777 Default: ``100`` 1778 1779 1780Misc 1781~~~~ 1782 1783.. option:: --conf=<PATH> 1784 1785 Load configuration from <PATH>. Please note that 1786 nghttpx always tries to read the default configuration 1787 file if :option:`--conf` is not given. 1788 1789 Default: ``/etc/nghttpx/nghttpx.conf`` 1790 1791.. option:: --include=<PATH> 1792 1793 Load additional configurations from <PATH>. File <PATH> 1794 is read when configuration parser encountered this 1795 option. This option can be used multiple times, or even 1796 recursively. 1797 1798.. option:: -v, --version 1799 1800 Print version and exit. 1801 1802.. option:: -h, --help 1803 1804 Print this help and exit. 1805 1806 1807 1808The <SIZE> argument is an integer and an optional unit (e.g., 10K is 180910 * 1024). Units are K, M and G (powers of 1024). 1810 1811The <DURATION> argument is an integer and an optional unit (e.g., 1s 1812is 1 second and 500ms is 500 milliseconds). Units are h, m, s or ms 1813(hours, minutes, seconds and milliseconds, respectively). If a unit 1814is omitted, a second is used as unit. 1815 1816FILES 1817----- 1818 1819*/etc/nghttpx/nghttpx.conf* 1820 The default configuration file path nghttpx searches at startup. 1821 The configuration file path can be changed using :option:`--conf` 1822 option. 1823 1824 Those lines which are staring ``#`` are treated as comment. 1825 1826 The option name in the configuration file is the long command-line 1827 option name with leading ``--`` stripped (e.g., ``frontend``). Put 1828 ``=`` between option name and value. Don't put extra leading or 1829 trailing spaces. 1830 1831 When specifying arguments including characters which have special 1832 meaning to a shell, we usually use quotes so that shell does not 1833 interpret them. When writing this configuration file, quotes for 1834 this purpose must not be used. For example, specify additional 1835 request header field, do this: 1836 1837 .. code-block:: text 1838 1839 add-request-header=foo: bar 1840 1841 instead of: 1842 1843 .. code-block:: text 1844 1845 add-request-header="foo: bar" 1846 1847 The options which do not take argument in the command-line *take* 1848 argument in the configuration file. Specify ``yes`` as an argument 1849 (e.g., ``http2-proxy=yes``). If other string is given, it is 1850 ignored. 1851 1852 To specify private key and certificate file which are given as 1853 positional arguments in command-line, use ``private-key-file`` and 1854 ``certificate-file``. 1855 1856 :option:`--conf` option cannot be used in the configuration file and 1857 will be ignored if specified. 1858 1859Error log 1860 Error log is written to stderr by default. It can be configured 1861 using :option:`--errorlog-file`. The format of log message is as 1862 follows: 1863 1864 <datetime> <main-pid> <current-pid> <thread-id> <level> (<filename>:<line>) <msg> 1865 1866 <datetime> 1867 It is a combination of date and time when the log is written. It 1868 is in ISO 8601 format. 1869 1870 <main-pid> 1871 It is a main process ID. 1872 1873 <current-pid> 1874 It is a process ID which writes this log. 1875 1876 <thread-id> 1877 It is a thread ID which writes this log. It would be unique 1878 within <current-pid>. 1879 1880 <filename> and <line> 1881 They are source file name, and line number which produce this log. 1882 1883 <msg> 1884 It is a log message body. 1885 1886SIGNALS 1887------- 1888 1889SIGQUIT 1890 Shutdown gracefully. First accept pending connections and stop 1891 accepting connection. After all connections are handled, nghttpx 1892 exits. 1893 1894SIGHUP 1895 Reload configuration file given in :option:`--conf`. 1896 1897SIGUSR1 1898 Reopen log files. 1899 1900SIGUSR2 1901 1902 Fork and execute nghttpx. It will execute the binary in the same 1903 path with same command-line arguments and environment variables. As 1904 of nghttpx version 1.20.0, the new main process sends SIGQUIT to the 1905 original main process when it is ready to serve requests. For the 1906 earlier versions of nghttpx, user has to send SIGQUIT to the 1907 original main process. 1908 1909 The difference between SIGUSR2 (+ SIGQUIT) and SIGHUP is that former 1910 is usually used to execute new binary, and the main process is newly 1911 spawned. On the other hand, the latter just reloads configuration 1912 file, and the same main process continues to exist. 1913 1914.. note:: 1915 1916 nghttpx consists of multiple processes: one process for processing 1917 these signals, and another one for processing requests. The former 1918 spawns the latter. The former is called main process, and the 1919 latter is called worker process. If neverbleed is enabled, the 1920 worker process spawns neverbleed daemon process which does RSA key 1921 processing. The above signal must be sent to the main process. If 1922 the other processes received one of them, it is ignored. This 1923 behaviour of these processes may change in the future release. In 1924 other words, in the future release, the processes other than main 1925 process may terminate upon the reception of these signals. 1926 Therefore these signals should not be sent to the processes other 1927 than main process. 1928 1929SERVER PUSH 1930----------- 1931 1932nghttpx supports HTTP/2 server push in default mode with Link header 1933field. nghttpx looks for Link header field (`RFC 5988 1934<http://tools.ietf.org/html/rfc5988>`_) in response headers from 1935backend server and extracts URI-reference with parameter 1936``rel=preload`` (see `preload 1937<http://w3c.github.io/preload/#interoperability-with-http-link-header>`_) 1938and pushes those URIs to the frontend client. Here is a sample Link 1939header field to initiate server push: 1940 1941.. code-block:: text 1942 1943 Link: </fonts/font.woff>; rel=preload 1944 Link: </css/theme.css>; rel=preload 1945 1946Currently, the following restriction is applied for server push: 1947 19481. The associated stream must have method "GET" or "POST". The 1949 associated stream's status code must be 200. 1950 1951This limitation may be loosened in the future release. 1952 1953nghttpx also supports server push if both frontend and backend are 1954HTTP/2 in default mode. In this case, in addition to server push via 1955Link header field, server push from backend is forwarded to frontend 1956HTTP/2 session. 1957 1958HTTP/2 server push will be disabled if :option:`--http2-proxy` is 1959used. 1960 1961UNIX DOMAIN SOCKET 1962------------------ 1963 1964nghttpx supports UNIX domain socket with a filename for both frontend 1965and backend connections. 1966 1967Please note that current nghttpx implementation does not delete a 1968socket with a filename. And on start up, if nghttpx detects that the 1969specified socket already exists in the file system, nghttpx first 1970deletes it. However, if SIGUSR2 is used to execute new binary and 1971both old and new configurations use same filename, new binary does not 1972delete the socket and continues to use it. 1973 1974OCSP STAPLING 1975------------- 1976 1977OCSP query is done using external Python script 1978``fetch-ocsp-response``, which has been originally developed in Perl 1979as part of h2o project (https://github.com/h2o/h2o), and was 1980translated into Python. 1981 1982The script file is usually installed under 1983``$(prefix)/share/nghttp2/`` directory. The actual path to script can 1984be customized using :option:`--fetch-ocsp-response-file` option. 1985 1986If OCSP query is failed, previous OCSP response, if any, is continued 1987to be used. 1988 1989:option:`--fetch-ocsp-response-file` option provides wide range of 1990possibility to manage OCSP response. It can take an arbitrary script 1991or executable. The requirement is that it supports the command-line 1992interface of ``fetch-ocsp-response`` script, and it must return a 1993valid DER encoded OCSP response on success. It must return exit code 19940 on success, and 75 for temporary error, and the other error code for 1995generic failure. For large cluster of servers, it is not efficient 1996for each server to perform OCSP query using ``fetch-ocsp-response``. 1997Instead, you can retrieve OCSP response in some way, and store it in a 1998disk or a shared database. Then specify a program in 1999:option:`--fetch-ocsp-response-file` to fetch it from those stores. 2000This could provide a way to share the OCSP response between fleet of 2001servers, and also any OCSP query strategy can be applied which may be 2002beyond the ability of nghttpx itself or ``fetch-ocsp-response`` 2003script. 2004 2005TLS SESSION RESUMPTION 2006---------------------- 2007 2008nghttpx supports TLS session resumption through both session ID and 2009session ticket. 2010 2011SESSION ID RESUMPTION 2012~~~~~~~~~~~~~~~~~~~~~ 2013 2014By default, session ID is shared by all worker threads. 2015 2016If :option:`--tls-session-cache-memcached` is given, nghttpx will 2017insert serialized session data to memcached with 2018``nghttpx:tls-session-cache:`` + lowercase hex string of session ID 2019as a memcached entry key, with expiry time 12 hours. Session timeout 2020is set to 12 hours. 2021 2022By default, connections to memcached server are not encrypted. To 2023enable encryption, use ``tls`` keyword in 2024:option:`--tls-session-cache-memcached` option. 2025 2026TLS SESSION TICKET RESUMPTION 2027~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2028 2029By default, session ticket is shared by all worker threads. The 2030automatic key rotation is also enabled by default. Every an hour, new 2031encryption key is generated, and previous encryption key becomes 2032decryption only key. We set session timeout to 12 hours, and thus we 2033keep at most 12 keys. 2034 2035If :option:`--tls-ticket-key-memcached` is given, encryption keys are 2036retrieved from memcached. nghttpx just reads keys from memcached; one 2037has to deploy key generator program to update keys frequently (e.g., 2038every 1 hour). The example key generator tlsticketupdate.go is 2039available under contrib directory in nghttp2 archive. The memcached 2040entry key is ``nghttpx:tls-ticket-key``. The data format stored in 2041memcached is the binary format described below: 2042 2043.. code-block:: text 2044 2045 +--------------+-------+----------------+ 2046 | VERSION (4) |LEN (2)|KEY(48 or 80) ... 2047 +--------------+-------+----------------+ 2048 ^ | 2049 | | 2050 +------------------------+ 2051 (LEN, KEY) pair can be repeated 2052 2053All numbers in the above figure is bytes. All integer fields are 2054network byte order. 2055 2056First 4 bytes integer VERSION field, which must be 1. The 2 bytes 2057integer LEN field gives the length of following KEY field, which 2058contains key. If :option:`--tls-ticket-key-cipher`\=aes-128-cbc is 2059used, LEN must be 48. If 2060:option:`--tls-ticket-key-cipher`\=aes-256-cbc is used, LEN must be 206180. LEN and KEY pair can be repeated multiple times to store multiple 2062keys. The key appeared first is used as encryption key. All the 2063remaining keys are used as decryption only. 2064 2065By default, connections to memcached server are not encrypted. To 2066enable encryption, use ``tls`` keyword in 2067:option:`--tls-ticket-key-memcached` option. 2068 2069If :option:`--tls-ticket-key-file` is given, encryption key is read 2070from the given file. In this case, nghttpx does not rotate key 2071automatically. To rotate key, one has to restart nghttpx (see 2072SIGNALS). 2073 2074CERTIFICATE TRANSPARENCY 2075------------------------ 2076 2077nghttpx supports TLS ``signed_certificate_timestamp`` extension (`RFC 20786962 <https://tools.ietf.org/html/rfc6962>`_). The relevant options 2079are :option:`--tls-sct-dir` and ``sct-dir`` parameter in 2080:option:`--subcert`. They takes a directory, and nghttpx reads all 2081files whose extension is ``.sct`` under the directory. The ``*.sct`` 2082files are encoded as ``SignedCertificateTimestamp`` struct described 2083in `section 3.2 of RFC 69662 2084<https://tools.ietf.org/html/rfc6962#section-3.2>`_. This format is 2085the same one used by `nginx-ct 2086<https://github.com/grahamedgecombe/nginx-ct>`_ and `mod_ssl_ct 2087<https://httpd.apache.org/docs/trunk/mod/mod_ssl_ct.html>`_. 2088`ct-submit <https://github.com/grahamedgecombe/ct-submit>`_ can be 2089used to submit certificates to log servers, and obtain the 2090``SignedCertificateTimestamp`` struct which can be used with nghttpx. 2091 2092MRUBY SCRIPTING 2093--------------- 2094 2095.. warning:: 2096 2097 The current mruby extension API is experimental and not frozen. The 2098 API is subject to change in the future release. 2099 2100.. warning:: 2101 2102 Almost all string value returned from method, or attribute is a 2103 fresh new mruby string, which involves memory allocation, and 2104 copies. Therefore, it is strongly recommended to store a return 2105 value in a local variable, and use it, instead of calling method or 2106 accessing attribute repeatedly. 2107 2108nghttpx allows users to extend its capability using mruby scripts. 2109nghttpx has 2 hook points to execute mruby script: request phase and 2110response phase. The request phase hook is invoked after all request 2111header fields are received from client. The response phase hook is 2112invoked after all response header fields are received from backend 2113server. These hooks allows users to modify header fields, or common 2114HTTP variables, like authority or request path, and even return custom 2115response without forwarding request to backend servers. 2116 2117There are 2 levels of mruby script invocations: global and 2118per-pattern. The global mruby script is set by :option:`--mruby-file` 2119option and is called for all requests. The per-pattern mruby script 2120is set by "mruby" parameter in :option:`-b` option. It is invoked for 2121a request which matches the particular pattern. The order of hook 2122invocation is: global request phase hook, per-pattern request phase 2123hook, per-pattern response phase hook, and finally global response 2124phase hook. If a hook returns a response, any later hooks are not 2125invoked. The global request hook is invoked before the pattern 2126matching is made and changing request path may affect the pattern 2127matching. 2128 2129Please note that request and response hooks of per-pattern mruby 2130script for a single request might not come from the same script. This 2131might happen after a request hook is executed, backend failed for some 2132reason, and at the same time, backend configuration is replaced by API 2133request, and then the request uses new configuration on retry. The 2134response hook from new configuration, if it is specified, will be 2135invoked. 2136 2137The all mruby script will be evaluated once per thread on startup, and 2138it must instantiate object and evaluate it as the return value (e.g., 2139``App.new``). This object is called app object. If app object 2140defines ``on_req`` method, it is called with :rb:class:`Nghttpx::Env` 2141object on request hook. Similarly, if app object defines ``on_resp`` 2142method, it is called with :rb:class:`Nghttpx::Env` object on response 2143hook. For each method invocation, user can can access 2144:rb:class:`Nghttpx::Request` and :rb:class:`Nghttpx::Response` objects 2145via :rb:attr:`Nghttpx::Env#req` and :rb:attr:`Nghttpx::Env#resp` 2146respectively. 2147 2148.. rb:module:: Nghttpx 2149 2150.. rb:const:: REQUEST_PHASE 2151 2152 Constant to represent request phase. 2153 2154.. rb:const:: RESPONSE_PHASE 2155 2156 Constant to represent response phase. 2157 2158.. rb:class:: Env 2159 2160 Object to represent current request specific context. 2161 2162 .. rb:attr_reader:: req 2163 2164 Return :rb:class:`Request` object. 2165 2166 .. rb:attr_reader:: resp 2167 2168 Return :rb:class:`Response` object. 2169 2170 .. rb:attr_reader:: ctx 2171 2172 Return Ruby hash object. It persists until request finishes. 2173 So values set in request phase hook can be retrieved in 2174 response phase hook. 2175 2176 .. rb:attr_reader:: phase 2177 2178 Return the current phase. 2179 2180 .. rb:attr_reader:: remote_addr 2181 2182 Return IP address of a remote client. If connection is made 2183 via UNIX domain socket, this returns the string "localhost". 2184 2185 .. rb:attr_reader:: server_addr 2186 2187 Return address of server that accepted the connection. This 2188 is a string which specified in :option:`--frontend` option, 2189 excluding port number, and not a resolved IP address. For 2190 UNIX domain socket, this is a path to UNIX domain socket. 2191 2192 .. rb:attr_reader:: server_port 2193 2194 Return port number of the server frontend which accepted the 2195 connection from client. 2196 2197 .. rb:attr_reader:: tls_used 2198 2199 Return true if TLS is used on the connection. 2200 2201 .. rb:attr_reader:: tls_sni 2202 2203 Return the TLS SNI value which client sent in this connection. 2204 2205 .. rb:attr_reader:: tls_client_fingerprint_sha256 2206 2207 Return the SHA-256 fingerprint of a client certificate. 2208 2209 .. rb:attr_reader:: tls_client_fingerprint_sha1 2210 2211 Return the SHA-1 fingerprint of a client certificate. 2212 2213 .. rb:attr_reader:: tls_client_issuer_name 2214 2215 Return the issuer name of a client certificate. 2216 2217 .. rb:attr_reader:: tls_client_subject_name 2218 2219 Return the subject name of a client certificate. 2220 2221 .. rb:attr_reader:: tls_client_serial 2222 2223 Return the serial number of a client certificate. 2224 2225 .. rb:attr_reader:: tls_client_not_before 2226 2227 Return the start date of a client certificate in seconds since 2228 the epoch. 2229 2230 .. rb:attr_reader:: tls_client_not_after 2231 2232 Return the end date of a client certificate in seconds since 2233 the epoch. 2234 2235 .. rb:attr_reader:: tls_cipher 2236 2237 Return a TLS cipher negotiated in this connection. 2238 2239 .. rb:attr_reader:: tls_protocol 2240 2241 Return a TLS protocol version negotiated in this connection. 2242 2243 .. rb:attr_reader:: tls_session_id 2244 2245 Return a session ID for this connection in hex string. 2246 2247 .. rb:attr_reader:: tls_session_reused 2248 2249 Return true if, and only if a SSL/TLS session is reused. 2250 2251 .. rb:attr_reader:: alpn 2252 2253 Return ALPN identifier negotiated in this connection. 2254 2255 .. rb:attr_reader:: tls_handshake_finished 2256 2257 Return true if SSL/TLS handshake has finished. If it returns 2258 false in the request phase hook, the request is received in 2259 TLSv1.3 early data (0-RTT) and might be vulnerable to the 2260 replay attack. nghttpx will send Early-Data header field to 2261 backend servers to indicate this. 2262 2263.. rb:class:: Request 2264 2265 Object to represent request from client. The modification to 2266 Request object is allowed only in request phase hook. 2267 2268 .. rb:attr_reader:: http_version_major 2269 2270 Return HTTP major version. 2271 2272 .. rb:attr_reader:: http_version_minor 2273 2274 Return HTTP minor version. 2275 2276 .. rb:attr_accessor:: method 2277 2278 HTTP method. On assignment, copy of given value is assigned. 2279 We don't accept arbitrary method name. We will document them 2280 later, but well known methods, like GET, PUT and POST, are all 2281 supported. 2282 2283 .. rb:attr_accessor:: authority 2284 2285 Authority (i.e., example.org), including optional port 2286 component . On assignment, copy of given value is assigned. 2287 2288 .. rb:attr_accessor:: scheme 2289 2290 Scheme (i.e., http, https). On assignment, copy of given 2291 value is assigned. 2292 2293 .. rb:attr_accessor:: path 2294 2295 Request path, including query component (i.e., /index.html). 2296 On assignment, copy of given value is assigned. The path does 2297 not include authority component of URI. This may include 2298 query component. nghttpx makes certain normalization for 2299 path. It decodes percent-encoding for unreserved characters 2300 (see https://tools.ietf.org/html/rfc3986#section-2.3), and 2301 resolves ".." and ".". But it may leave characters which 2302 should be percent-encoded as is. So be careful when comparing 2303 path against desired string. 2304 2305 .. rb:attr_reader:: headers 2306 2307 Return Ruby hash containing copy of request header fields. 2308 Changing values in returned hash does not change request 2309 header fields actually used in request processing. Use 2310 :rb:meth:`Nghttpx::Request#add_header` or 2311 :rb:meth:`Nghttpx::Request#set_header` to change request 2312 header fields. 2313 2314 .. rb:method:: add_header(key, value) 2315 2316 Add header entry associated with key. The value can be single 2317 string or array of string. It does not replace any existing 2318 values associated with key. 2319 2320 .. rb:method:: set_header(key, value) 2321 2322 Set header entry associated with key. The value can be single 2323 string or array of string. It replaces any existing values 2324 associated with key. 2325 2326 .. rb:method:: clear_headers 2327 2328 Clear all existing request header fields. 2329 2330 .. rb:method:: push(uri) 2331 2332 Initiate to push resource identified by *uri*. Only HTTP/2 2333 protocol supports this feature. For the other protocols, this 2334 method is noop. *uri* can be absolute URI, absolute path or 2335 relative path to the current request. For absolute or 2336 relative path, scheme and authority are inherited from the 2337 current request. Currently, method is always GET. nghttpx 2338 will issue request to backend servers to fulfill this request. 2339 The request and response phase hooks will be called for pushed 2340 resource as well. 2341 2342.. rb:class:: Response 2343 2344 Object to represent response from backend server. 2345 2346 .. rb:attr_reader:: http_version_major 2347 2348 Return HTTP major version. 2349 2350 .. rb:attr_reader:: http_version_minor 2351 2352 Return HTTP minor version. 2353 2354 .. rb:attr_accessor:: status 2355 2356 HTTP status code. It must be in the range [200, 999], 2357 inclusive. The non-final status code is not supported in 2358 mruby scripting at the moment. 2359 2360 .. rb:attr_reader:: headers 2361 2362 Return Ruby hash containing copy of response header fields. 2363 Changing values in returned hash does not change response 2364 header fields actually used in response processing. Use 2365 :rb:meth:`Nghttpx::Response#add_header` or 2366 :rb:meth:`Nghttpx::Response#set_header` to change response 2367 header fields. 2368 2369 .. rb:method:: add_header(key, value) 2370 2371 Add header entry associated with key. The value can be single 2372 string or array of string. It does not replace any existing 2373 values associated with key. 2374 2375 .. rb:method:: set_header(key, value) 2376 2377 Set header entry associated with key. The value can be single 2378 string or array of string. It replaces any existing values 2379 associated with key. 2380 2381 .. rb:method:: clear_headers 2382 2383 Clear all existing response header fields. 2384 2385 .. rb:method:: return(body) 2386 2387 Return custom response *body* to a client. When this method 2388 is called in request phase hook, the request is not forwarded 2389 to the backend, and response phase hook for this request will 2390 not be invoked. When this method is called in response phase 2391 hook, response from backend server is canceled and discarded. 2392 The status code and response header fields should be set 2393 before using this method. To set status code, use 2394 :rb:attr:`Nghttpx::Response#status`. If status code is not 2395 set, 200 is used. To set response header fields, 2396 :rb:meth:`Nghttpx::Response#add_header` and 2397 :rb:meth:`Nghttpx::Response#set_header`. When this method is 2398 invoked in response phase hook, the response headers are 2399 filled with the ones received from backend server. To send 2400 completely custom header fields, first call 2401 :rb:meth:`Nghttpx::Response#clear_headers` to erase all 2402 existing header fields, and then add required header fields. 2403 It is an error to call this method twice for a given request. 2404 2405 .. rb:method:: send_info(status, headers) 2406 2407 Send non-final (informational) response to a client. *status* 2408 must be in the range [100, 199], inclusive. *headers* is a 2409 hash containing response header fields. Its key must be a 2410 string, and the associated value must be either string or 2411 array of strings. Since this is not a final response, even if 2412 this method is invoked, request is still forwarded to a 2413 backend unless :rb:meth:`Nghttpx::Response#return` is called. 2414 This method can be called multiple times. It cannot be called 2415 after :rb:meth:`Nghttpx::Response#return` is called. 2416 2417MRUBY EXAMPLES 2418~~~~~~~~~~~~~~ 2419 2420Modify request path: 2421 2422.. code-block:: ruby 2423 2424 class App 2425 def on_req(env) 2426 env.req.path = "/apps#{env.req.path}" 2427 end 2428 end 2429 2430 App.new 2431 2432Don't forget to instantiate and evaluate object at the last line. 2433 2434Restrict permission of viewing a content to a specific client 2435addresses: 2436 2437.. code-block:: ruby 2438 2439 class App 2440 def on_req(env) 2441 allowed_clients = ["127.0.0.1", "::1"] 2442 2443 if env.req.path.start_with?("/log/") && 2444 !allowed_clients.include?(env.remote_addr) then 2445 env.resp.status = 404 2446 env.resp.return "permission denied" 2447 end 2448 end 2449 end 2450 2451 App.new 2452 2453API ENDPOINTS 2454------------- 2455 2456nghttpx exposes API endpoints to manipulate it via HTTP based API. By 2457default, API endpoint is disabled. To enable it, add a dedicated 2458frontend for API using :option:`--frontend` option with "api" 2459parameter. All requests which come from this frontend address, will 2460be treated as API request. 2461 2462The response is normally JSON dictionary, and at least includes the 2463following keys: 2464 2465status 2466 The status of the request processing. The following values are 2467 defined: 2468 2469 Success 2470 The request was successful. 2471 2472 Failure 2473 The request was failed. No change has been made. 2474 2475code 2476 HTTP status code 2477 2478Additionally, depending on the API endpoint, ``data`` key may be 2479present, and its value contains the API endpoint specific data. 2480 2481We wrote "normally", since nghttpx may return ordinal HTML response in 2482some cases where the error has occurred before reaching API endpoint 2483(e.g., header field is too large). 2484 2485The following section describes available API endpoints. 2486 2487POST /api/v1beta1/backendconfig 2488~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2489 2490This API replaces the current backend server settings with the 2491requested ones. The request method should be POST, but PUT is also 2492acceptable. The request body must be nghttpx configuration file 2493format. For configuration file format, see `FILES`_ section. The 2494line separator inside the request body must be single LF (0x0A). 2495Currently, only :option:`backend <--backend>` option is parsed, the 2496others are simply ignored. The semantics of this API is replace the 2497current backend with the backend options in request body. Describe 2498the desired set of backend severs, and nghttpx makes it happen. If 2499there is no :option:`backend <--backend>` option is found in request 2500body, the current set of backend is replaced with the :option:`backend 2501<--backend>` option's default value, which is ``127.0.0.1,80``. 2502 2503The replacement is done instantly without breaking existing 2504connections or requests. It also avoids any process creation as is 2505the case with hot swapping with signals. 2506 2507The one limitation is that only numeric IP address is allowed in 2508:option:`backend <--backend>` in request body unless "dns" parameter 2509is used while non numeric hostname is allowed in command-line or 2510configuration file is read using :option:`--conf`. 2511 2512GET /api/v1beta1/configrevision 2513~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2514 2515This API returns configuration revision of the current nghttpx. The 2516configuration revision is opaque string, and it changes after each 2517reloading by SIGHUP. With this API, an external application knows 2518that whether nghttpx has finished reloading its configuration by 2519comparing the configuration revisions between before and after 2520reloading. It is recommended to disable persistent (keep-alive) 2521connection for this purpose in order to avoid to send a request using 2522the reused connection which may bound to an old process. 2523 2524This API returns response including ``data`` key. Its value is JSON 2525object, and it contains at least the following key: 2526 2527configRevision 2528 The configuration revision of the current nghttpx 2529 2530 2531SEE ALSO 2532-------- 2533 2534:manpage:`nghttp(1)`, :manpage:`nghttpd(1)`, :manpage:`h2load(1)` 2535