diff --git "a/nginx-docs.jsonl" "b/nginx-docs.jsonl" new file mode 100644--- /dev/null +++ "b/nginx-docs.jsonl" @@ -0,0 +1,151 @@ +{"path": "robots.txt", "extension": ".txt", "size_bytes": 72, "content": "User-Agent: *\nDisallow: /libxslt/\nSitemap: http://nginx.org/sitemap.xml\n", "encoding": "utf-8"} +{"path": "css\\style_en.css", "extension": ".css", "size_bytes": 7928, "content": "body {\n background: white;\n color: black;\n font-family: sans-serif;\n line-height: 1.4em;\n text-align: center;\n margin: 0;\n padding: 0;\n}\n\n#banner {\n background: black;\n color: #F2F2F2;\n line-height: 1.2em;\n padding: .3em 1em .3em 1em;\n box-shadow: 0 5px 10px black;\n}\n\n#banner a {\n color: #00B140;\n}\n\n#main {\n text-align: left;\n margin: 0 auto;\n min-width: 32em;\n max-width: 66em;\n}\n\n#menu {\n float: right;\n width: 13em;\n padding: 0;\n border-left: 2px solid #DDD;\n}\n.nav ul{\n margin:0;\n padding:20px;\n}\n.nav h1{\n padding:0 20px;\n}\n.nav ul li{\n list-style-type:none;\n padding:0;\n margin:0;\n}\n\n#content {\n margin-right: 13.5em;\n padding: 0 2.5em 0 1.5em;\n}\n\nh1 {\n display: block;\n font-size: 3em;\n text-align: left;\n margin: 0.5rem 0 0 0;\n}\n\nh1 img {\n width: 100%;\n}\n\nh2 {\n font-size: 2rem;\n line-height: 2.25rem;\n margin: 1rem 0 .5rem 0;\n overflow-wrap: break-word;\n}\n\nh4 {\n font-size: 1.5rem;\n margin: 2rem 0 .5rem 0;\n}\n/* Center field override */\ncenter h4 {\n text-align: left!important;\n}\n\nh5 {\n font-size: 1.25rem;\n text-align: center;\n margin: 0.25rem 0 0 0;\n}\n\np {\n text-align: justify;\n margin-bottom: 0;\n}\n\ntable.news p {\n margin-top: 0;\n}\n\ntable.news td {\n vertical-align: baseline;\n}\n\ntable.news .date {\n text-align: right;\n padding: 0.75rem 0.5rem 0 0;\n white-space: nowrap;\n}\n\ntable.donors td {\n vertical-align: baseline;\n}\n\ntable.donors li {\n text-align: left;\n}\n\n/* News Archive button */\n.dropbtn {\n background-color: #808080;\n color: white;\n padding: 0.3rem;\n font-size: 1rem;\n border: 1px solid #606060;\n}\n.dropdown {\n position: relative;\n display: inline-block;\n padding-bottom: 0.5em;\n}\n.dropdown-content {\n display: none;\n position: absolute;\n background-color: #f0f0f0;\n min-width: 160px;\n box-shadow: 0px 8px 12px 0px #909090;\n z-index: 1;\n}\n.dropdown-content a {\n padding: 0.33em;\n text-decoration: none;\n display: block;\n}\n.dropdown-content a:hover {background-color: #a0a0a0;}\n.dropdown:hover .dropdown-content {display: block;}\n.dropdown:hover .dropbtn {background-color: #909090;}\n\ndiv.directive {\n background: #F2F2F2;\n line-height: 1em;\n margin: 1em 0 1em -1em;\n padding: .7em .7em .7em 1em;\n border-top: 2px solid #DDD;\n width:100%;\n}\n\ndiv.directive th {\n padding-left: 0;\n padding-right: .5em;\n vertical-align: baseline;\n text-align: left;\n font-weight: normal;\n}\n\ndiv.directive td {\n vertical-align: baseline;\n}\n\ndiv.directive pre {\n padding: 0;\n margin: 0;\n}\n\ndiv.directive code {\n background: none!important;\n padding: 0!important;\n border: none;\n}\n\ndiv.directive p {\n margin: .5em 0 0 .1em;\n font-size: .8em;\n}\n\na.notrans {\n color: #808080;\n text-decoration:none;\n}\n\nspan.initial {\n font-size: 200%;\n float: left;\n padding-right: 10pt;\n}\n\nul, ol {\n margin: .5em 0 1em 1em;\n padding: 0 .5em;\n}\n\nol {\n list-style-position: inside;\n}\n\nli {\n padding: .5em 0 0 1px;\n}\n\n.compact li {\n padding-top: 0;\n}\n\ndl {\n margin: .5em 0 1em 0;\n}\n\ndt {\n margin: 1em 0 0 0!important;\n font-size: 0.9rem;\n}\n\n.compact dt {\n margin-bottom: .2em;\n}\n\ndd {\n margin: 0.25rem 0 1.5rem 1rem;\n padding-left: 1px;\n text-align: justify;\n}\n\ntd.list {\n background: #f2f2f2;\n}\n\nblockquote {\n margin: 0.5rem 0 0 0;\n padding: 0;\n}\n\nli blockquote, dd blockquote {\n margin: .7em 0;\n}\n\nblockquote.note {\n padding: 0.5rem;\n border: 1px dotted #999;\n line-height: 1.2em;\n text-align: justify;\n}\n\npre {\n border: 0;\n display: block;\n margin: 1em 0;\n padding: 0.6em 1em;\n overflow-x: auto;\n line-height: 1.05rem;\n}\n\ncode,.legacy{\n font-size: 100%;\n padding: 3px 7px;\n overflow-x: scroll;\n background: #eee;\n}\n\npre code{\n background: none;\n padding: 0;\n border-radius: 0;\n}\n\nblockquote pre {\n background-color: #f8f8f8!important;\n color: #222!important;\n margin: 0;\n border: 1px solid #ddd;\n}\n\nblockquote.terminal pre{\n background-color: #444!important;\n color: #fff!important;\n}\n\nblockquote.example {\n line-height: 1em;\n}\n\nsup {\n font-size: 50%;\n}\n\n.video {\n position: relative;\n padding-bottom: 56.25%;\n overflow: hidden;\n}\n\n.video iframe, .video object, .video embed {\n position: absolute;\n top:0;\n left:0;\n width:100%;\n height:100%;\n}\n\n@media screen and (max-width:750px) {\n #main {\n padding: 20px;\n min-width: inherit;\n }\n #main #content {\n width: 100%!important;\n padding: 0;\n border: none;\n }\n\n #banner-content {\n max-width: 70vw;\n }\n\n #menu {\n text-align: left;\n }\n\n /* Menu Mobile */\n :root {\n --white: #f9f9f9;\n --black: #000;\n --gray: #85888C;\n --green: #b6d7a8;\n color-scheme: light dark;\n } /* variables*/\n\n /* Nav menu */\n .nav {\n width: 15rem;\n height: 100%;\n max-height: 0;\n position: fixed;\n top: 50px;\n right: 0;\n border-left: 1px solid #909090;\n background-color: var(--white);\n overflow: hidden;\n transition: .5s ease-in-out;\n }\n .nav ul {\n margin: 0;\n padding: 20px;\n }\n .nav h1 {\n padding: 0 20px;\n }\n .nav ul li {\n list-style-type: none;\n padding:0;\n margin:0;\n }\n\n .hamb {\n cursor: pointer;\n float: right;\n position: absolute;\n top: 0;\n right: 0.25em;\n width: 3.5em;\n padding-top: 1.5em;\n z-index: 1100;\n }\n .hamb-line {\n background: var(--green);\n display: block;\n position: relative;\n height: 0.3em;\n width: 2.75em;\n border-radius:3px;\n }\n .hamb-line::before,.hamb-line::after {\n background: var(--green);\n content: '';\n display: block;\n height: 100%;\n position: absolute;\n transition: all .2s ease-in-out;\n width: 100%;\n border-radius:3px;\n }\n .hamb-line::before{\n top: 10px;\n }\n .hamb-line::after{\n top: -10px;\n }\n .side-menu {\n display: none;\n } /* Hide checkbox */\n .side-menu:checked ~ .nav{\n max-height: 100%;\n top: 50px;\n\n }\n .side-menu:checked ~ .hamb .hamb-line {\n background: transparent;\n }\n .side-menu:checked ~ .hamb .hamb-line::before {\n transform: rotate(-45deg);\n top: 0;\n }\n .side-menu:checked ~ .hamb .hamb-line::after {\n transform: rotate(45deg);\n top: 0;\n }\n\n code {\n white-space: pre-line;\n }\n}\n\n@media screen and (min-width:750px){\n .side-menu,.hamb-line {\n display: none;\n }\n}\n\n/* Dark Mode */\n@media (prefers-color-scheme: dark) {\n\tbody {\n\t\tbackground-color: #1c262d;\n color:#eee;\n\t}\n h1,h2,h3,h4,h5,h6,p {\n color: #eee;\n }\n a {\n color: #55A4F1;\n text-decoration: underline;\n }\n a:visited {\n color: #8b79c0!important;\n }\n .nav {\n background:var(--black);\n }\n #menu a {\n color: #55A4F1;\n }\n blockquote pre {\n color: #ddd!important;\n background: #0f1b29!important;\n border: 1px solid #132235;\n }\n div.directive {\n background: #0c1622!important;\n border-top: 2px solid #203c5e!important;\n }\n code {\n background:#0c1622;\n color: #ddd!important;\n }\n .lightimage {\n display: none!important;\n }\n .darkimageWrapper, .darkimage {\n display: block!important;\n }\n .dropbtn {background-color: #202020;}\n .dropdown-content {\n background-color: #404040;\n box-shadow: 0px 8px 12px 0px #101010;\n }\n .dropdown-content a:hover {background-color: #242424;}\n .dropdown:hover .dropbtn {background-color: #202020;}\n}\n", "encoding": "utf-8"} +{"path": "img\\nginx_logo.svg", "extension": ".svg", "size_bytes": 10689, "content": "\n", "encoding": "utf-8"} +{"path": "img\\nginx_logo_dark.svg", "extension": ".svg", "size_bytes": 10634, "content": "\n", "encoding": "utf-8"} +{"path": "en\\docs\\beginners_guide.html", "extension": ".html", "size_bytes": 18254, "content": "\n
| Starting, Stopping, and Reloading Configuration Configuration File’s Structure Serving Static Content Setting Up a Simple Proxy Server Setting Up FastCGI Proxying |
\nThis guide gives a basic introduction to nginx and describes some\nsimple tasks that can be done with it.\nIt is supposed that nginx is already installed on the reader’s machine.\nIf it is not, see the Installing nginx page.\nThis guide describes how to start and stop nginx, and reload its\nconfiguration, explains the structure\nof the configuration file and describes how to set up nginx\nto serve out static content, how to configure nginx as a proxy\nserver, and how to connect it with a FastCGI application.\n
\nnginx has one master process and several worker processes.\nThe main purpose of the master process is to read and evaluate configuration,\nand maintain worker processes.\nWorker processes do actual processing of requests.\nnginx employs event-based model and OS-dependent mechanisms to efficiently\ndistribute requests among worker processes.\nThe number of worker processes is defined in the configuration file and\nmay be fixed for a given configuration or automatically adjusted to the\nnumber of available CPU cores (see\nworker_processes).\n
\nThe way nginx and its modules work is determined in the configuration file.\nBy default, the configuration file is named nginx.conf\nand placed in the directory\n/usr/local/nginx/conf,\n/etc/nginx, or\n/usr/local/etc/nginx.\n
\nTo start nginx, run the executable file.\nOnce nginx is started, it can be controlled by invoking the executable\nwith the -s parameter.\nUse the following syntax:\n
\nnginx -s signal\n
\nWhere signal may be one of the following:\n
stop — fast shutdown\nquit — graceful shutdown\nreload — reloading the configuration file\nreopen — reopening the log files\n\nFor example, to stop nginx processes with waiting for the worker processes\nto finish serving current requests, the following command can be executed:\n
\nnginx -s quit\n
\n
This command should be executed under the same user that\nstarted nginx.
\n
\nChanges made in the configuration file\nwill not be applied until the command to reload configuration is\nsent to nginx or it is restarted.\nTo reload configuration, execute:\n
\nnginx -s reload\n
\n
\nOnce the master process receives the signal to reload configuration,\nit checks the syntax validity\nof the new configuration file and tries to apply the configuration provided\nin it.\nIf this is a success, the master process starts new worker processes\nand sends messages to old worker processes, requesting them to\nshut down.\nOtherwise, the master process rolls back the changes and\ncontinues to work with the old configuration.\nOld worker processes, receiving a command to shut down,\nstop accepting new connections and continue to service current requests until\nall such requests are serviced.\nAfter that, the old worker processes exit.\n
\nA signal may also be sent to nginx processes with the help of Unix tools\nsuch as the kill utility.\nIn this case a signal is sent directly to a process with a given process ID.\nThe process ID of the nginx master process is written, by default, to the\nnginx.pid in the directory\n/usr/local/nginx/logs or\n/var/run.\nFor example, if the master process ID is 1628, to send the QUIT signal\nresulting in nginx’s graceful shutdown, execute:\n
\nkill -s QUIT 1628\n
\nFor getting the list of all running nginx processes, the ps\nutility may be used, for example, in the following way:\n
\nps -ax | grep nginx\n
\nFor more information on sending signals to nginx, see\nControlling nginx.\n
\nnginx consists of modules which are controlled by directives specified\nin the configuration file.\nDirectives are divided into simple directives and block directives.\nA simple directive consists of the name and parameters separated by spaces\nand ends with a semicolon (;).\nA block directive has the same structure as a simple directive, but\ninstead of the semicolon it ends with a set of additional instructions\nsurrounded by braces ({ and }).\nIf a block directive can have other directives inside braces,\nit is called a context (examples:\nevents,\nhttp,\nserver,\nand\nlocation).\n
\nDirectives placed in the configuration file outside\nof any contexts are considered to be in the\nmain context.\nThe events and http directives\nreside in the main context, server\nin http, and location in\nserver.\n
\nThe rest of a line after the # sign is considered a comment.\n
\nAn important web server task is serving out\nfiles (such as images or static HTML pages).\nYou will implement an example where, depending on the request,\nfiles will be served from different local directories: /data/www\n(which may contain HTML files) and /data/images\n(containing images).\nThis will require editing of the configuration file and setting up of a\nserver\nblock inside the http\nblock with two location\nblocks.\n
\nFirst, create the /data/www directory and put an\nindex.html file with any text content into it and\ncreate the /data/images directory and place some\nimages in it.\n
\nNext, open the configuration file.\nThe default configuration file already includes several examples of\nthe server block, mostly commented out.\nFor now comment out all such blocks and start a new\nserver block:\n
\nhttp {\n server {\n }\n}\n \nGenerally, the configuration file may include several\nserver blocks\ndistinguished by ports on which\nthey listen to\nand by\nserver names.\nOnce nginx decides which server processes a request,\nit tests the URI specified in the request’s header against the parameters of the\nlocation directives defined inside the\nserver block.\n
\nAdd the following location block to the\nserver block:\n
\nlocation / {\n root /data/www;\n}\n \nThis location block specifies the\n“/” prefix compared with the URI from the request.\nFor matching requests, the URI will be added to the path specified in the\nroot\ndirective, that is, to /data/www,\nto form the path to the requested file on the local file system.\nIf there are several matching location blocks nginx\nselects the one with the longest prefix.\nThe location block above provides the shortest\nprefix, of length one,\nand so only if all other location\nblocks fail to provide a match, this block will be used.\n
\nNext, add the second location block:\n
\nlocation /images/ {\n root /data;\n}\n \nIt will be a match for requests starting with /images/\n(location / also matches such requests,\nbut has shorter prefix).\n
\nThe resulting configuration of the server block should\nlook like this:\n
\nserver {\n location / {\n root /data/www;\n }\n\n location /images/ {\n root /data;\n }\n}\n \nThis is already a working configuration of a server that listens\non the standard port 80 and is accessible on the local machine at\nhttp://localhost/.\nIn response to requests with URIs starting with /images/,\nthe server will send files from the /data/images directory.\nFor example, in response to the\nhttp://localhost/images/example.png request nginx will\nsend the /data/images/example.png file.\nIf such file does not exist, nginx will send a response\nindicating the 404 error.\nRequests with URIs not starting with /images/ will be\nmapped onto the /data/www directory.\nFor example, in response to the\nhttp://localhost/some/example.html request nginx will\nsend the /data/www/some/example.html file.\n
\nTo apply the new configuration, start nginx if it is not yet started or\nsend the reload signal to the nginx’s master process,\nby executing:\n
\nnginx -s reload\n
\n
\n
\nIn case something does not work as expected, you may try to find out\nthe reason inaccess.logand\nerror.logfiles in the directory\n/usr/local/nginx/logsor\n/var/log/nginx.\n
\n
\nOne of the frequent uses of nginx is setting it up as a proxy server, which\nmeans a server that receives requests, passes them to the proxied servers,\nretrieves responses from them, and sends them to the clients.\n
\nWe will configure a basic proxy server, which serves requests of\nimages with files from the local directory and sends all other requests to a\nproxied server.\nIn this example, both servers will be defined on a single nginx instance.\n
\nFirst, define the proxied server by adding one more server\nblock to the nginx’s configuration file with the following contents:\n
\nserver {\n listen 8080;\n root /data/up1;\n\n location / {\n }\n}\n \nThis will be a simple server that listens on the port 8080\n(previously, the listen directive has not been specified\nsince the standard port 80 was used) and maps\nall requests to the /data/up1 directory on the local\nfile system.\nCreate this directory and put the index.html file into it.\nNote that the root directive is placed in the\nserver context.\nSuch root directive is used when the\nlocation block selected for serving a request does not\ninclude its own root directive.\n
\nNext, use the server configuration from the previous section\nand modify it to make it a proxy server configuration.\nIn the first location block, put the\nproxy_pass\ndirective with the protocol, name and port of the proxied server specified\nin the parameter (in our case, it is http://localhost:8080):\n
\nserver {\n location / {\n proxy_pass http://localhost:8080;\n }\n\n location /images/ {\n root /data;\n }\n}\n\n
\nWe will modify the second location\nblock, which currently maps requests with the /images/\nprefix to the files under the /data/images directory,\nto make it match the requests of images with typical file extensions.\nThe modified location block looks like this:\n
\nlocation ~ \\.(gif|jpg|png)$ {\n root /data/images;\n}\n \nThe parameter is a regular expression matching all URIs ending\nwith .gif, .jpg, or .png.\nA regular expression should be preceded with ~.\nThe corresponding requests will be mapped to the /data/images\ndirectory.\n
\nWhen nginx selects a location block to serve a request\nit first checks location\ndirectives that specify prefixes, remembering location\nwith the longest prefix, and then checks regular expressions.\nIf there is a match with a regular expression, nginx picks this\nlocation or, otherwise, it picks the one remembered earlier.\n
\nThe resulting configuration of a proxy server will look like this:\n
\nserver {\n location / {\n proxy_pass http://localhost:8080/;\n }\n\n location ~ \\.(gif|jpg|png)$ {\n root /data/images;\n }\n}\n \nThis server will filter requests ending with .gif,\n.jpg, or .png\nand map them to the /data/images directory (by adding URI to the\nroot directive’s parameter) and pass all other requests\nto the proxied server configured above.\n
\nTo apply new configuration, send the reload signal to\nnginx as described in the previous sections.\n
\nThere are many more\ndirectives that may be used to further configure a proxy connection.\n
\nnginx can be used to route requests to FastCGI servers which run\napplications built with various frameworks and programming languages\nsuch as PHP.\n
\nThe most basic nginx configuration to work with a FastCGI server\nincludes using the\nfastcgi_pass\ndirective instead of the proxy_pass directive,\nand fastcgi_param\ndirectives to set parameters passed to a FastCGI server.\nSuppose the FastCGI server is accessible on localhost:9000.\nTaking the proxy configuration from the previous section as a basis,\nreplace the proxy_pass directive with the\nfastcgi_pass directive and change the parameter to\nlocalhost:9000.\nIn PHP, the SCRIPT_FILENAME parameter is used for\ndetermining the script name, and the QUERY_STRING\nparameter is used to pass request parameters.\nThe resulting configuration would be:\n
\nserver {\n location / {\n fastcgi_pass localhost:9000;\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n fastcgi_param QUERY_STRING $query_string;\n }\n\n location ~ \\.(gif|jpg|png)$ {\n root /data/images;\n }\n}\n \nThis will set up a server that will route all requests except for\nrequests for static images to the proxied server operating on\nlocalhost:9000 through the FastCGI protocol.\n
\nThe build is configured using the configure command.\nIt defines various aspects of the system, including the methods nginx\nis allowed to use for connection processing.\nAt the end it creates a Makefile.\n
\nThe configure command supports the following parameters:\n
\n
--help\n\n
\n
--prefix=path\nconfigure (except for paths to libraries sources)\nand in the nginx.conf configuration file.\nIt is set to the /usr/local/nginx directory by default.\n--sbin-path=path\nprefix/sbin/nginx.\n--modules-path=path\nprefix/modules directory is used.\n--conf-path=path\nnginx.conf configuration file.\nIf needs be, nginx can always be started with a different configuration file,\nby specifying it in the command-line parameter\n-c fileprefix/conf/nginx.conf.\n--error-log-path=path\nnginx.conf configuration file using the\nerror_log directive.\nBy default the file is named\nprefix/logs/error.log.\n--pid-path=path\nnginx.pid file\nthat will store the process ID of the main process.\nAfter installation, the file name can always be changed in the\nnginx.conf configuration file using the\npid directive.\nBy default the file is named\nprefix/logs/nginx.pid.\n--lock-path=path\nnginx.conf configuration file using the\nlock_file directive.\nBy default the value is\nprefix/logs/nginx.lock.\n\n
\n
--user=name\nnginx.conf configuration file using the\nuser directive.\nThe default user name is nobody.\n--group=name\nnginx.conf configuration file using the\nuser directive.\nBy default, a group name is set to the name of an unprivileged user.\n\n
\n
--build=name\n--builddir=path\n\n
\n
--with-select_module--without-select_module\nselect() method.\nThis module is built automatically if the platform does not appear\nto support more appropriate methods such as kqueue, epoll, or /dev/poll.\n--with-poll_module--without-poll_module\npoll() method.\nThis module is built automatically if the platform does not appear\nto support more appropriate methods such as kqueue, epoll, or /dev/poll.\n--with-threads\n--with-file-aio\n\n
\n
--with-http_ssl_module\n--with-http_v2_module\n--with-http_v3_module\n--with-http_realip_module\n--with-http_addition_module\n--with-http_xslt_module--with-http_xslt_module=dynamic\n--with-http_image_filter_module--with-http_image_filter_module=dynamic\n--with-http_geoip_module--with-http_geoip_module=dynamic\n--with-http_sub_module\n--with-http_dav_module\n--with-http_flv_module\n--with-http_mp4_module\n--with-http_gunzip_module\nContent-Encoding: gzip”\nfor clients that do not support “gzip” encoding method.\nThis module is not built by default.\n--with-http_gzip_static_module\n.gz” filename extension instead of regular files.\nThis module is not built by default.\n--with-http_auth_request_module\n--with-http_random_index_module\n/’) and picks a random\nfile in a directory to serve as an index file.\nThis module is not built by default.\n--with-http_secure_link_module\n--with-http_degradation_module\nngx_http_degradation_module module.\nThis module is not built by default.\n--with-http_slice_module\n--with-http_stub_status_module\n\n
\n
--without-http_charset_module\n--without-http_gzip_module\n--without-http_ssi_module\n--without-http_userid_module\n--without-http_access_module\n--without-http_auth_basic_module\n--without-http_mirror_module\n--without-http_autoindex_module\n/’) and produces\na directory listing in case the\nngx_http_index_module module\ncannot find an index file.\n--without-http_geo_module\n--without-http_map_module\n--without-http_split_clients_module\n--without-http_referer_module\n--without-http_rewrite_module\n--without-http_proxy_module\n--without-http_fastcgi_module\n--without-http_uwsgi_module\n--without-http_scgi_module\n--without-http_grpc_module\n--without-http_memcached_module\n--without-http_limit_conn_module\n--without-http_limit_req_module\n--without-http_empty_gif_module\n--without-http_browser_module\n--without-http_upstream_hash_module\n--without-http_upstream_ip_hash_module\n--without-http_upstream_least_conn_module\n--without-http_upstream_least_time_module\n--without-http_upstream_random_module\n--without-http_upstream_keepalive_module\n--without-http_upstream_zone_module\n--without-http_upstream_sticky_module\n\n
\n
--with-http_perl_module--with-http_perl_module=dynamic\n--with-perl_modules_path=path\n--with-perl=path\n\n
\n
--http-log-path=path\nnginx.conf configuration file using the\naccess_log directive.\nBy default the file is named\nprefix/logs/access.log.\n--http-client-body-temp-path=path\nnginx.conf configuration file using the\nclient_body_temp_path\ndirective.\nBy default the directory is named\nprefix/client_body_temp.\n--http-proxy-temp-path=path\nnginx.conf configuration file using the\nproxy_temp_path\ndirective.\nBy default the directory is named\nprefix/proxy_temp.\n--http-fastcgi-temp-path=path\nnginx.conf configuration file using the\nfastcgi_temp_path\ndirective.\nBy default the directory is named\nprefix/fastcgi_temp.\n--http-uwsgi-temp-path=path\nnginx.conf configuration file using the\nuwsgi_temp_path\ndirective.\nBy default the directory is named\nprefix/uwsgi_temp.\n--http-scgi-temp-path=path\nnginx.conf configuration file using the\nscgi_temp_path\ndirective.\nBy default the directory is named\nprefix/scgi_temp.\n\n
\n
--without-http\n--without-http-cache\n\n
\n
--with-mail--with-mail=dynamic\n--with-mail_ssl_module\n--without-mail_pop3_module\n--without-mail_imap_module\n--without-mail_smtp_module\n\n
\n
--with-stream--with-stream=dynamic\n--with-stream_ssl_module\n--with-stream_realip_module\n--with-stream_geoip_module--with-stream_geoip_module=dynamic\n--with-stream_ssl_preread_module\n--without-stream_limit_conn_module\n--without-stream_access_module\n--without-stream_geo_module\n--without-stream_map_module\n--without-stream_split_clients_module\n--without-stream_return_module\n--without-stream_pass_module\n--without-stream_set_module\n--without-stream_upstream_hash_module\n--without-stream_upstream_least_conn_module\n--without-stream_upstream_least_time_module\n--without-stream_upstream_random_module\n--without-stream_upstream_zone_module\n\n
\n
--with-google_perftools_module\n--with-cpp_test_module\nngx_cpp_test_module module.\n\n
\n
--add-module=path\n--add-dynamic-module=path\n\n
\n
--with-compat\n\n
\n
--with-cc=path\n--with-cpp=path\n--with-cc-opt=parameters\n--with-cc-opt=\"-I /usr/local/include\"\nshould be specified.\nIf the number of files supported by select() needs to be\nincreased it can also be specified here such as this:\n--with-cc-opt=\"-D FD_SETSIZE=2048\".\n--with-ld-opt=parameters\n--with-ld-opt=\"-L /usr/local/lib\"\nshould be specified.\n--with-cpu-opt=cpu\npentium, pentiumpro,\npentium3, pentium4,\nathlon, opteron,\nsparc32, sparc64,\nppc64.\n\n
\n
--without-pcre\n--with-pcre\n--with-pcre=path\n./configure and\nmake.\nThe library is required for regular expressions support in the\nlocation directive\nand for the\nngx_http_rewrite_module\nmodule.\n--with-pcre-opt=parameters\n--with-pcre-jit\n--without-pcre2\n\n
\n
--with-zlib=path\n./configure and\nmake.\nThe library is required for the\nngx_http_gzip_module module.\n--with-zlib-opt=parameters\n--with-zlib-asm=cpu\npentium, pentiumpro.\n\n
\n
--with-libatomic\n--with-libatomic=path\n\n
\n
--with-openssl=path\n--with-openssl-opt=parameters\n\n
\n
--with-debug\n\n
\nExample of parameters usage (all of this needs to be typed in one line):\n
\n./configure\n --sbin-path=/usr/local/nginx/nginx\n --conf-path=/usr/local/nginx/nginx.conf\n --pid-path=/usr/local/nginx/nginx.pid\n --with-http_ssl_module\n --with-pcre=../pcre2-10.39\n --with-zlib=../zlib-1.3\n
\n
\nAfter configuration,\nnginx is compiled and installed using make.\n
| Getting Sources Formatting Changes Before Submitting Submitting Changes Website License |
\nGitHub is used\nto store source code.\nThe repository can be cloned\nwith the following command:\n
\ngit clone https://github.com/nginx/nginx.git\n
\n
\nChanges should be formatted according to the\ncode style\nused by nginx.\nSometimes, there is no clear rule; in such cases\nexamine how existing nginx sources are formatted and mimic this style.\nChanges will more likely be accepted if style corresponds to the surrounding\ncode.\n
\nCommit\nthe changes in your nginx GitHub fork.\nPlease ensure that the specified\ne-mail\naddress and real name of the author are correct.\n
\nThe commit message should have a single-line synopsis followed by verbose\ndescription after an empty line.\nLimit the subject and commit message body lines to 72 characters.\nThe resulting commit can be obtained using the\ngit show command:\n
\ncommit 067d766f210ee914b750d79d9284cbf8801058f3\nAuthor: Zoey <username@example.com>\nDate: Sun Apr 5 11:31:15 2026 +0200\n\n Fix $request_port and $is_request_port in subrequests\n\n Closes #1247.\n\ndiff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c\nindex 0c46106db..53ddf39bb 100644\n--- a/src/http/ngx_http_core_module.c\n+++ b/src/http/ngx_http_core_module.c\n@@ -2453,6 +2453,8 @@ ngx_http_subrequest(ngx_http_request_t *r,\n sr->method = NGX_HTTP_GET;\n sr->http_version = r->http_version;\n\n+ sr->port = r->port;\n+\n sr->request_line = r->request_line;\n sr->uri = *uri;\n\n
\n
\nSeveral points are worth to consider before submitting changes:\n
\n\ngit clone https://github.com/nginx/nginx-tests.git\n
\n
\nThe proposed changes should be submitted from your fork to\nnginx repository\nas a\npull request.\n
\nGitHub is used to store the sources for this website.\nThe repository\ncan be cloned with the following command:\n
\ngit clone https://github.com/nginx/nginx.org.git\n
\nDocumentation changes should be submitted from your fork\nas a pull request.\n
\nSubmitting changes implies granting project a permission to use it under\nan appropriate license.\n
| Changing Configuration Rotating Log-files Upgrading Executable on the Fly |
\nnginx can be controlled with signals.\nThe process ID of the master process is written to the file\n/usr/local/nginx/logs/nginx.pid by default.\nThis name may be changed at configuration time, or in\nnginx.conf using the\npid\ndirective.\nThe master process supports the following signals:\n
\n\n\n
\n\n TERM, INT fast shutdown \n QUIT graceful shutdown \n HUP changing configuration,\nkeeping up with a changed time zone (only for FreeBSD and Linux),\nstarting new worker processes with a new configuration,\ngraceful shutdown of old worker processes \n USR1 re-opening log files \n USR2 upgrading an executable file \n\n WINCH graceful shutdown of worker processes
\n
\nIndividual worker processes can be controlled with signals as well,\nthough it is not required.\nThe supported signals are:\n
\n\n\n
\n\n TERM, INT fast shutdown \n QUIT graceful shutdown \n USR1 re-opening log files \n\n WINCH abnormal termination for debugging\n(requires debug_points to be enabled)\n
\n
\nIn order for nginx to re-read the configuration file, a HUP\nsignal should be sent to the master process.\nThe master process first checks the syntax validity, then tries\nto apply new configuration, that is, to open log files and new\nlisten sockets.\nIf this fails, it rolls back changes and continues to work\nwith old configuration.\nIf this succeeds, it starts new worker processes, and\nsends messages to old worker processes requesting them to\nshut down gracefully.\nOld worker processes close listen sockets and continue to service\nold clients.\nAfter all clients are serviced, old worker processes are shut down.\n
\nLet’s illustrate this by example.\nImagine that nginx is run on FreeBSD and the command\n
\nps axw -o pid,ppid,user,%cpu,vsz,wchan,command | egrep '(nginx|PID)'\n
\nproduces the following output:\n
\n PID PPID USER %CPU VSZ WCHAN COMMAND\n33126 1 root 0.0 1148 pause nginx: master process /usr/local/nginx/sbin/nginx\n33127 33126 nobody 0.0 1380 kqread nginx: worker process (nginx)\n33128 33126 nobody 0.0 1364 kqread nginx: worker process (nginx)\n33129 33126 nobody 0.0 1364 kqread nginx: worker process (nginx)\n
\n
\nIf HUP is sent to the master process, the output becomes:\n
\n PID PPID USER %CPU VSZ WCHAN COMMAND\n33126 1 root 0.0 1164 pause nginx: master process /usr/local/nginx/sbin/nginx\n33129 33126 nobody 0.0 1380 kqread nginx: worker process is shutting down (nginx)\n33134 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)\n33135 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)\n33136 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)\n
\n
\nOne of the old worker processes with PID 33129 still continues to work.\nAfter some time it exits:\n
\n PID PPID USER %CPU VSZ WCHAN COMMAND\n33126 1 root 0.0 1164 pause nginx: master process /usr/local/nginx/sbin/nginx\n33134 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)\n33135 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)\n33136 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)\n
\n
\nIn order to rotate log files, they need to be renamed first.\nAfter that USR1 signal should be sent to the master process.\nThe master process will then re-open all currently open log files and\nassign them an unprivileged user under which the worker processes\nare running, as an owner.\nAfter successful re-opening, the master process closes all open files and\nsends the message to worker process to ask them to re-open files.\nWorker processes also open new files and close old files right away.\nAs a result, old files are almost immediately available for post\nprocessing, such as compression.\n
\nIn order to upgrade the server executable, the new executable file\nshould be put in place of an old file first.\nAfter that USR2 signal should be sent to the master process.\nThe master process first renames its file with the process ID to a\nnew file with the .oldbin suffix, e.g.\n/usr/local/nginx/logs/nginx.pid.oldbin,\nthen starts a new executable file that in turn starts new\nworker processes:\n
\n PID PPID USER %CPU VSZ WCHAN COMMAND\n33126 1 root 0.0 1164 pause nginx: master process /usr/local/nginx/sbin/nginx\n33134 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)\n33135 33126 nobody 0.0 1380 kqread nginx: worker process (nginx)\n33136 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)\n36264 33126 root 0.0 1148 pause nginx: master process /usr/local/nginx/sbin/nginx\n36265 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)\n36266 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)\n36267 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)\n
\n
\nAfter that all worker processes (old and new ones) continue to accept requests.\nIf the WINCH signal is sent to the first master process, it will\nsend messages to its worker processes, requesting them to shut\ndown gracefully, and they will start to exit:\n
\n PID PPID USER %CPU VSZ WCHAN COMMAND\n33126 1 root 0.0 1164 pause nginx: master process /usr/local/nginx/sbin/nginx\n33135 33126 nobody 0.0 1380 kqread nginx: worker process is shutting down (nginx)\n36264 33126 root 0.0 1148 pause nginx: master process /usr/local/nginx/sbin/nginx\n36265 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)\n36266 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)\n36267 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)\n
\n
\nAfter some time, only the new worker processes will process requests:\n
\n PID PPID USER %CPU VSZ WCHAN COMMAND\n33126 1 root 0.0 1164 pause nginx: master process /usr/local/nginx/sbin/nginx\n36264 33126 root 0.0 1148 pause nginx: master process /usr/local/nginx/sbin/nginx\n36265 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)\n36266 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)\n36267 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)\n
\n
\nIt should be noted that the old master process does not close its listen\nsockets, and it can be managed to start its worker processes again if needed.\nIf for some reason the new executable file works unacceptably, one of the\nfollowing can be done:\n
\nSend the HUP signal to the old master process.\nThe old master process will start new worker processes\nwithout re-reading the configuration.\nAfter that, all new processes can be shut down gracefully,\nby sending the QUIT signal to the new master process.\n
\n\nSend the TERM signal to the new master process.\nIt will then send a message to its worker processes requesting them\nto exit immediately, and they will all exit almost immediately.\n(If new processes do not exit for some reason,\nthe KILL signal should be sent to them to force them to exit.)\nWhen the new master process exits, the old master process will start new\nworker processes automatically.\n
\n\n\n
\nIf the new master process exits then the old master process discards\nthe .oldbin suffix from the file name with the process ID.\n
\nIf upgrade was successful, then the QUIT signal should be sent to\nthe old master process, and only new processes will stay:\n
\n PID PPID USER %CPU VSZ WCHAN COMMAND\n36264 1 root 0.0 1148 pause nginx: master process /usr/local/nginx/sbin/nginx\n36265 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)\n36266 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)\n36267 36264 nobody 0.0 1364 kqread nginx: worker process (nginx)\n
\n
| Debugging log for selected clients Logging to a cyclic memory buffer |
\nTo enable a debugging log, nginx needs to be configured to support\ndebugging during the build:\n\n
\n./configure --with-debug ...\n
\n\nThen the debug level should be set with the\nerror_log directive:\n\n
\nerror_log /path/to/log debug;\n
\n\nTo verify that nginx is configured to support debugging,\nrun the nginx -V command:\n\n
\nconfigure arguments: --with-debug ...\n
\n\nPre-built Linux packages\nprovide out-of-the-box support for debugging log with\nthe nginx-debug binary (1.9.8)\nwhich can be run using commands\n\n
\nservice nginx stop\nservice nginx-debug start\n
\n\nand then set the debug level.\nThe nginx binary version for Windows is always built with the debugging log\nsupport, so only setting the debug level will suffice.\n
\nNote that redefining the log without also specifying the\ndebug\nlevel will disable the debugging log.\nIn the example below, redefining the log on the\nserver\nlevel disables the debugging log for this server:\n
\nerror_log /path/to/log debug;\n\nhttp {\n server {\n error_log /path/to/log;\n ...\n \nTo avoid this, either the line redefining the log should be\ncommented out, or the debug level specification should\nalso be added:\n
\nerror_log /path/to/log debug;\n\nhttp {\n server {\n error_log /path/to/log debug;\n ...\n\n
\nIt is also possible to enable the debugging log for\nselected\nclient addresses only:\n\n
\nerror_log /path/to/log;\n\nevents {\n debug_connection 192.168.1.1;\n debug_connection 192.168.10.0/24;\n}\n\n
\nThe debugging log can be written to a cyclic memory buffer:\n
\nerror_log memory:32m debug;\n
\nLogging to the memory buffer on the debug level\ndoes not have significant impact on performance even under high load.\nIn this case, the log can be extracted using\na gdb script like the following one:\n
\nset $log = ngx_cycle->log\n\nwhile $log->writer != ngx_log_memory_writer\n set $log = $log->next\nend\n\nset $buf = (ngx_log_memory_buf_t *) $log->wdata\ndump binary memory debug_log.txt $buf->start $buf->end\n
\nOr using an lldb script as follows:\n
\nexpr ngx_log_t *$log = ngx_cycle->log\nexpr while ($log->writer != ngx_log_memory_writer) { $log = $log->next; }\nexpr ngx_log_memory_buf_t *$buf = (ngx_log_memory_buf_t *) $log->wdata\nmemory read --force --outfile debug_log.txt --binary $buf->start $buf->end\n\n
\n absolute_redirect
accept_mutex
accept_mutex_delay
accept_terms_of_service
access_log (ngx_http_log_module)
access_log (ngx_stream_log_module)
account_key
acme_certificate
acme_issuer
acme_shared_zone
add_after_body
add_before_body
add_header
add_header_inherit
add_trailer
add_trailer_inherit
addition_types
aio
aio_write
alias
allow (ngx_http_access_module)
allow (ngx_stream_access_module)
ancient_browser
ancient_browser_value
api
auth_basic
auth_basic_user_file
auth_delay
auth_http
auth_http_header
auth_http_pass_client_cert
auth_http_timeout
auth_jwt
auth_jwt_claim_set
auth_jwt_header_set
auth_jwt_key_cache
auth_jwt_key_file
auth_jwt_key_request
auth_jwt_leeway
auth_jwt_require
auth_jwt_type
auth_oidc
auth_request
auth_request_set
auth_require
autoindex
autoindex_exact_size
autoindex_format
autoindex_localtime
break
challenge
charset
charset_map
charset_types
chunked_transfer_encoding
client_body_buffer_size
client_body_in_file_only
client_body_in_single_buffer
client_body_temp_path
client_body_timeout
client_header_buffer_size
client_header_timeout
client_id
client_max_body_size
client_secret
common_name_in_csr
config_url
connection_pool_size
contact
cookie_name
create_full_put_path
daemon
dav_access
dav_methods
debug_connection
debug_points
default_type
deny (ngx_http_access_module)
deny (ngx_stream_access_module)
directio
directio_alignment
disable_symlinks
early_hints
empty_gif
enforce_initial_report
env
error_log
error_log_tag
error_page
etag
events
expires
external_account_key
extra_auth_args
f4f
f4f_buffer_size
fastcgi_allow_upstream
fastcgi_bind
fastcgi_bind_dynamic
fastcgi_buffer_size
fastcgi_buffering
fastcgi_buffers
fastcgi_busy_buffers_size
fastcgi_cache
fastcgi_cache_background_update
fastcgi_cache_bypass
fastcgi_cache_key
fastcgi_cache_lock
fastcgi_cache_lock_age
fastcgi_cache_lock_timeout
fastcgi_cache_max_range_offset
fastcgi_cache_methods
fastcgi_cache_min_uses
fastcgi_cache_path
fastcgi_cache_purge
fastcgi_cache_revalidate
fastcgi_cache_use_stale
fastcgi_cache_valid
fastcgi_catch_stderr
fastcgi_connect_timeout
fastcgi_force_ranges
fastcgi_hide_header
fastcgi_ignore_client_abort
fastcgi_ignore_headers
fastcgi_index
fastcgi_intercept_errors
fastcgi_keep_conn
fastcgi_limit_rate
fastcgi_max_temp_file_size
fastcgi_next_upstream
fastcgi_next_upstream_timeout
fastcgi_next_upstream_tries
fastcgi_no_cache
fastcgi_param
fastcgi_pass
fastcgi_pass_header
fastcgi_pass_request_body
fastcgi_pass_request_headers
fastcgi_read_timeout
fastcgi_request_buffering
fastcgi_request_dynamic
fastcgi_send_lowat
fastcgi_send_timeout
fastcgi_socket_keepalive
fastcgi_split_path_info
fastcgi_store
fastcgi_store_access
fastcgi_temp_file_write_size
fastcgi_temp_path
flv
frontchannel_logout_uri
geo (ngx_http_geo_module)
geo (ngx_stream_geo_module)
geoip_city (ngx_http_geoip_module)
geoip_city (ngx_stream_geoip_module)
geoip_country (ngx_http_geoip_module)
geoip_country (ngx_stream_geoip_module)
geoip_org (ngx_http_geoip_module)
geoip_org (ngx_stream_geoip_module)
geoip_proxy
geoip_proxy_recursive
google_perftools_profiles
grpc_allow_upstream
grpc_bind
grpc_bind_dynamic
grpc_buffer_size
grpc_connect_timeout
grpc_hide_header
grpc_ignore_headers
grpc_intercept_errors
grpc_next_upstream
grpc_next_upstream_timeout
grpc_next_upstream_tries
grpc_pass
grpc_pass_header
grpc_read_timeout
grpc_request_dynamic
grpc_send_timeout
grpc_set_header
grpc_socket_keepalive
grpc_ssl_certificate
grpc_ssl_certificate_cache
grpc_ssl_certificate_key
grpc_ssl_ciphers
grpc_ssl_conf_command
grpc_ssl_crl
grpc_ssl_key_log
grpc_ssl_name
grpc_ssl_password_file
grpc_ssl_protocols
grpc_ssl_server_name
grpc_ssl_session_reuse
grpc_ssl_trusted_certificate
grpc_ssl_verify
grpc_ssl_verify_depth
gunzip
gunzip_buffers
gzip
gzip_buffers
gzip_comp_level
gzip_disable
gzip_http_version
gzip_min_length
gzip_proxied
gzip_static
gzip_types
gzip_vary
hash (ngx_http_upstream_module)
hash (ngx_stream_upstream_module)
health_check (ngx_http_upstream_hc_module)
health_check (ngx_stream_upstream_hc_module)
health_check_timeout
hls
hls_buffers
hls_forward_args
hls_fragment
hls_mp4_buffer_size
hls_mp4_max_buffer_size
http
http2
http2_body_preread_size
http2_chunk_size
http2_idle_timeout
http2_max_concurrent_pushes
http2_max_concurrent_streams
http2_max_field_size
http2_max_header_size
http2_max_requests
http2_push
http2_push_preload
http2_recv_buffer_size
http2_recv_timeout
http3
http3_hq
http3_max_concurrent_streams
http3_stream_buffer_size
if
if_modified_since
ignore_invalid_headers
image_filter
image_filter_buffer
image_filter_interlace
image_filter_jpeg_quality
image_filter_sharpen
image_filter_transparency
image_filter_webp_quality
imap_auth
imap_capabilities
imap_client_buffer
include
index
internal
internal_redirect
ip_hash
issuer
js_access (ngx_http_js_module)
js_access (ngx_stream_js_module)
js_body_filter
js_content
js_context_reuse (ngx_http_js_module)
js_context_reuse (ngx_stream_js_module)
js_engine (ngx_http_js_module)
js_engine (ngx_stream_js_module)
js_fetch_buffer_size (ngx_http_js_module)
js_fetch_buffer_size (ngx_stream_js_module)
js_fetch_ciphers (ngx_http_js_module)
js_fetch_ciphers (ngx_stream_js_module)
js_fetch_keepalive (ngx_http_js_module)
js_fetch_keepalive (ngx_stream_js_module)
js_fetch_keepalive_requests (ngx_http_js_module)
js_fetch_keepalive_requests (ngx_stream_js_module)
js_fetch_keepalive_time (ngx_http_js_module)
js_fetch_keepalive_time (ngx_stream_js_module)
js_fetch_keepalive_timeout (ngx_http_js_module)
js_fetch_keepalive_timeout (ngx_stream_js_module)
js_fetch_max_response_buffer_size (ngx_http_js_module)
js_fetch_max_response_buffer_size (ngx_stream_js_module)
js_fetch_protocols (ngx_http_js_module)
js_fetch_protocols (ngx_stream_js_module)
js_fetch_proxy (ngx_http_js_module)
js_fetch_proxy (ngx_stream_js_module)
js_fetch_timeout (ngx_http_js_module)
js_fetch_timeout (ngx_stream_js_module)
js_fetch_trusted_certificate (ngx_http_js_module)
js_fetch_trusted_certificate (ngx_stream_js_module)
js_fetch_verify (ngx_http_js_module)
js_fetch_verify (ngx_stream_js_module)
js_fetch_verify_depth (ngx_http_js_module)
js_fetch_verify_depth (ngx_stream_js_module)
js_filter
js_header_filter
js_import (ngx_http_js_module)
js_import (ngx_stream_js_module)
js_include (ngx_http_js_module)
js_include (ngx_stream_js_module)
js_load_http_native_module
js_load_stream_native_module
js_path (ngx_http_js_module)
js_path (ngx_stream_js_module)
js_periodic (ngx_http_js_module)
js_periodic (ngx_stream_js_module)
js_preload_object (ngx_http_js_module)
js_preload_object (ngx_stream_js_module)
js_preread
js_set (ngx_http_js_module)
js_set (ngx_stream_js_module)
js_shared_dict_zone (ngx_http_js_module)
js_shared_dict_zone (ngx_stream_js_module)
js_var (ngx_http_js_module)
js_var (ngx_stream_js_module)
keepalive
keepalive_disable
keepalive_min_timeout
keepalive_requests (ngx_http_core_module)
keepalive_requests (ngx_http_upstream_module)
keepalive_time (ngx_http_core_module)
keepalive_time (ngx_http_upstream_module)
keepalive_timeout (ngx_http_core_module)
keepalive_timeout (ngx_http_upstream_module)
keyval (ngx_http_keyval_module)
keyval (ngx_stream_keyval_module)
keyval_zone (ngx_http_keyval_module)
keyval_zone (ngx_stream_keyval_module)
large_client_header_buffers
least_conn (ngx_http_upstream_module)
least_conn (ngx_stream_upstream_module)
least_time (ngx_http_upstream_module)
least_time (ngx_stream_upstream_module)
license_token
limit_conn (ngx_http_limit_conn_module)
limit_conn (ngx_stream_limit_conn_module)
limit_conn_dry_run (ngx_http_limit_conn_module)
limit_conn_dry_run (ngx_stream_limit_conn_module)
limit_conn_log_level (ngx_http_limit_conn_module)
limit_conn_log_level (ngx_stream_limit_conn_module)
limit_conn_status
limit_conn_zone (ngx_http_limit_conn_module)
limit_conn_zone (ngx_stream_limit_conn_module)
limit_except
limit_rate
limit_rate_after
limit_req
limit_req_dry_run
limit_req_log_level
limit_req_status
limit_req_zone
limit_zone
lingering_close
lingering_time
lingering_timeout
listen (ngx_http_core_module)
listen (ngx_mail_core_module)
listen (ngx_stream_core_module)
load_module
location
lock_file
log_format (ngx_http_log_module)
log_format (ngx_stream_log_module)
log_not_found
log_subrequest
logout_token_hint
logout_uri
mail
map (ngx_http_map_module)
map (ngx_stream_map_module)
map_hash_bucket_size (ngx_http_map_module)
map_hash_bucket_size (ngx_stream_map_module)
map_hash_max_size (ngx_http_map_module)
map_hash_max_size (ngx_stream_map_module)
master_process
match (ngx_http_upstream_hc_module)
match (ngx_stream_upstream_hc_module)
max_errors
max_headers
max_ranges
memcached_allow_upstream
memcached_bind
memcached_bind_dynamic
memcached_buffer_size
memcached_connect_timeout
memcached_gzip_flag
memcached_next_upstream
memcached_next_upstream_timeout
memcached_next_upstream_tries
memcached_pass
memcached_read_timeout
memcached_send_timeout
memcached_socket_keepalive
merge_slashes
mgmt
min_delete_depth
mirror
mirror_request_body
modern_browser
modern_browser_value
mp4
mp4_buffer_size
mp4_limit_rate
mp4_limit_rate_after
mp4_max_buffer_size
mp4_start_key_frame
mqtt
mqtt_buffers
mqtt_preread
mqtt_rewrite_buffer_size
mqtt_set_connect
msie_padding
msie_refresh
multi_accept
ntlm
num_map (ngx_http_num_map_module)
num_map (ngx_stream_num_map_module)
oidc_provider
open_file_cache
open_file_cache_errors
open_file_cache_min_uses
open_file_cache_valid
open_log_file_cache (ngx_http_log_module)
open_log_file_cache (ngx_stream_log_module)
otel_exporter
otel_resource_attr
otel_service_name
otel_span_attr
otel_span_name
otel_trace
otel_trace_context
output_buffers
override_charset
pass
pcre_jit
perl
perl_modules
perl_require
perl_set
pid
pkce
pop3_auth
pop3_capabilities
port_in_redirect
post_logout_uri
postpone_output
preferred_chain
preread_buffer_size
preread_timeout
profile
protocol
proxy
proxy_allow_upstream
proxy_bind (ngx_http_proxy_module)
proxy_bind (ngx_stream_proxy_module)
proxy_bind_dynamic (ngx_http_proxy_module)
proxy_bind_dynamic (ngx_stream_proxy_module)
proxy_buffer
proxy_buffer_size (ngx_http_proxy_module)
proxy_buffer_size (ngx_stream_proxy_module)
proxy_buffering
proxy_buffers
proxy_busy_buffers_size
proxy_cache
proxy_cache_background_update
proxy_cache_bypass
proxy_cache_convert_head
proxy_cache_key
proxy_cache_lock
proxy_cache_lock_age
proxy_cache_lock_timeout
proxy_cache_max_range_offset
proxy_cache_methods
proxy_cache_min_uses
proxy_cache_path
proxy_cache_purge
proxy_cache_revalidate
proxy_cache_use_stale
proxy_cache_valid
proxy_connect_timeout (ngx_http_proxy_module)
proxy_connect_timeout (ngx_stream_proxy_module)
proxy_cookie_domain
proxy_cookie_flags
proxy_cookie_path
proxy_download_rate
proxy_force_ranges
proxy_half_close
proxy_headers_hash_bucket_size
proxy_headers_hash_max_size
proxy_hide_header
proxy_http_version
proxy_ignore_client_abort
proxy_ignore_headers
proxy_intercept_errors
proxy_limit_rate
proxy_max_temp_file_size
proxy_method
proxy_next_upstream (ngx_http_proxy_module)
proxy_next_upstream (ngx_stream_proxy_module)
proxy_next_upstream_timeout (ngx_http_proxy_module)
proxy_next_upstream_timeout (ngx_stream_proxy_module)
proxy_next_upstream_tries (ngx_http_proxy_module)
proxy_next_upstream_tries (ngx_stream_proxy_module)
proxy_no_cache
proxy_pass (ngx_http_proxy_module)
proxy_pass (ngx_stream_proxy_module)
proxy_pass_error_message
proxy_pass_header
proxy_pass_request_body
proxy_pass_request_headers
proxy_pass_trailers
proxy_password
proxy_protocol (ngx_mail_proxy_module)
proxy_protocol (ngx_stream_proxy_module)
proxy_protocol_timeout
proxy_read_timeout
proxy_redirect
proxy_request_buffering
proxy_request_dynamic
proxy_requests
proxy_responses
proxy_send_lowat
proxy_send_timeout
proxy_session_drop
proxy_set_body
proxy_set_header
proxy_smtp_auth
proxy_socket_keepalive (ngx_http_proxy_module)
proxy_socket_keepalive (ngx_stream_proxy_module)
proxy_ssl
proxy_ssl_alpn
proxy_ssl_certificate (ngx_http_proxy_module)
proxy_ssl_certificate (ngx_stream_proxy_module)
proxy_ssl_certificate_cache (ngx_http_proxy_module)
proxy_ssl_certificate_cache (ngx_stream_proxy_module)
proxy_ssl_certificate_key (ngx_http_proxy_module)
proxy_ssl_certificate_key (ngx_stream_proxy_module)
proxy_ssl_ciphers (ngx_http_proxy_module)
proxy_ssl_ciphers (ngx_stream_proxy_module)
proxy_ssl_conf_command (ngx_http_proxy_module)
proxy_ssl_conf_command (ngx_stream_proxy_module)
proxy_ssl_crl (ngx_http_proxy_module)
proxy_ssl_crl (ngx_stream_proxy_module)
proxy_ssl_key_log (ngx_http_proxy_module)
proxy_ssl_key_log (ngx_stream_proxy_module)
proxy_ssl_name (ngx_http_proxy_module)
proxy_ssl_name (ngx_stream_proxy_module)
proxy_ssl_password_file (ngx_http_proxy_module)
proxy_ssl_password_file (ngx_stream_proxy_module)
proxy_ssl_protocols (ngx_http_proxy_module)
proxy_ssl_protocols (ngx_stream_proxy_module)
proxy_ssl_server_name (ngx_http_proxy_module)
proxy_ssl_server_name (ngx_stream_proxy_module)
proxy_ssl_session_reuse (ngx_http_proxy_module)
proxy_ssl_session_reuse (ngx_stream_proxy_module)
proxy_ssl_trusted_certificate (ngx_http_proxy_module)
proxy_ssl_trusted_certificate (ngx_stream_proxy_module)
proxy_ssl_verify (ngx_http_proxy_module)
proxy_ssl_verify (ngx_stream_proxy_module)
proxy_ssl_verify_depth (ngx_http_proxy_module)
proxy_ssl_verify_depth (ngx_stream_proxy_module)
proxy_store
proxy_store_access
proxy_temp_file_write_size
proxy_temp_path
proxy_timeout (ngx_mail_proxy_module)
proxy_timeout (ngx_stream_proxy_module)
proxy_upload_rate
proxy_username
queue
quic_active_connection_id_limit
quic_bpf
quic_gso
quic_host_key
quic_retry
random (ngx_http_upstream_module)
random (ngx_stream_upstream_module)
random_index
read_ahead
real_ip_header
real_ip_recursive
recursive_error_pages
redirect_uri
referer_hash_bucket_size
referer_hash_max_size
request_pool_size
reset_timedout_connection
resolver (ngx_http_core_module)
resolver (ngx_http_upstream_module)
resolver (ngx_mail_core_module)
resolver (ngx_stream_core_module)
resolver (ngx_stream_upstream_module)
resolver (ngx_mgmt_module)
resolver_timeout (ngx_http_core_module)
resolver_timeout (ngx_http_upstream_module)
resolver_timeout (ngx_mail_core_module)
resolver_timeout (ngx_stream_core_module)
resolver_timeout (ngx_stream_upstream_module)
return (ngx_http_rewrite_module)
return (ngx_stream_return_module)
rewrite
rewrite_log
root
satisfy
scgi_allow_upstream
scgi_bind
scgi_bind_dynamic
scgi_buffer_size
scgi_buffering
scgi_buffers
scgi_busy_buffers_size
scgi_cache
scgi_cache_background_update
scgi_cache_bypass
scgi_cache_key
scgi_cache_lock
scgi_cache_lock_age
scgi_cache_lock_timeout
scgi_cache_max_range_offset
scgi_cache_methods
scgi_cache_min_uses
scgi_cache_path
scgi_cache_purge
scgi_cache_revalidate
scgi_cache_use_stale
scgi_cache_valid
scgi_connect_timeout
scgi_force_ranges
scgi_hide_header
scgi_ignore_client_abort
scgi_ignore_headers
scgi_intercept_errors
scgi_limit_rate
scgi_max_temp_file_size
scgi_next_upstream
scgi_next_upstream_timeout
scgi_next_upstream_tries
scgi_no_cache
scgi_param
scgi_pass
scgi_pass_header
scgi_pass_request_body
scgi_pass_request_headers
scgi_read_timeout
scgi_request_buffering
scgi_request_dynamic
scgi_send_timeout
scgi_socket_keepalive
scgi_store
scgi_store_access
scgi_temp_file_write_size
scgi_temp_path
scope
secure_link
secure_link_md5
secure_link_secret
send_lowat
send_timeout
sendfile
sendfile_max_chunk
server (ngx_http_core_module)
server (ngx_http_upstream_module)
server (ngx_mail_core_module)
server (ngx_stream_core_module)
server (ngx_stream_upstream_module)
server_name (ngx_http_core_module)
server_name (ngx_mail_core_module)
server_name (ngx_stream_core_module)
server_name_in_redirect
server_names_hash_bucket_size (ngx_http_core_module)
server_names_hash_bucket_size (ngx_stream_core_module)
server_names_hash_max_size (ngx_http_core_module)
server_names_hash_max_size (ngx_stream_core_module)
server_tokens
session_log
session_log_format
session_log_zone
session_store
session_timeout
set (ngx_http_rewrite_module)
set (ngx_stream_set_module)
set_real_ip_from (ngx_http_realip_module)
set_real_ip_from (ngx_mail_realip_module)
set_real_ip_from (ngx_stream_realip_module)
slice
smtp_auth
smtp_capabilities
smtp_client_buffer
smtp_greeting_delay
source_charset
split_clients (ngx_http_split_clients_module)
split_clients (ngx_stream_split_clients_module)
ssi
ssi_last_modified
ssi_min_file_chunk
ssi_silent_errors
ssi_types
ssi_value_length
ssl (ngx_http_ssl_module)
ssl (ngx_mail_ssl_module)
ssl_alpn
ssl_buffer_size
ssl_certificate (ngx_http_ssl_module)
ssl_certificate (ngx_mail_ssl_module)
ssl_certificate (ngx_stream_ssl_module)
ssl_certificate_cache (ngx_http_ssl_module)
ssl_certificate_cache (ngx_stream_ssl_module)
ssl_certificate_compression (ngx_http_ssl_module)
ssl_certificate_compression (ngx_mail_ssl_module)
ssl_certificate_compression (ngx_stream_ssl_module)
ssl_certificate_key (ngx_http_ssl_module)
ssl_certificate_key (ngx_mail_ssl_module)
ssl_certificate_key (ngx_stream_ssl_module)
ssl_ciphers (ngx_http_ssl_module)
ssl_ciphers (ngx_mail_ssl_module)
ssl_ciphers (ngx_stream_ssl_module)
ssl_client_certificate (ngx_http_ssl_module)
ssl_client_certificate (ngx_mail_ssl_module)
ssl_client_certificate (ngx_stream_ssl_module)
ssl_conf_command (ngx_http_ssl_module)
ssl_conf_command (ngx_mail_ssl_module)
ssl_conf_command (ngx_stream_ssl_module)
ssl_crl (ngx_http_oidc_module)
ssl_crl (ngx_http_ssl_module)
ssl_crl (ngx_mail_ssl_module)
ssl_crl (ngx_stream_ssl_module)
ssl_crl (ngx_mgmt_module)
ssl_dhparam (ngx_http_ssl_module)
ssl_dhparam (ngx_mail_ssl_module)
ssl_dhparam (ngx_stream_ssl_module)
ssl_early_data
ssl_ecdh_curve (ngx_http_ssl_module)
ssl_ecdh_curve (ngx_mail_ssl_module)
ssl_ecdh_curve (ngx_stream_ssl_module)
ssl_ech_file (ngx_http_ssl_module)
ssl_ech_file (ngx_stream_ssl_module)
ssl_engine
ssl_handshake_timeout
ssl_key_log (ngx_http_ssl_module)
ssl_key_log (ngx_stream_ssl_module)
ssl_object_cache_inheritable
ssl_ocsp (ngx_http_ssl_module)
ssl_ocsp (ngx_stream_ssl_module)
ssl_ocsp_cache (ngx_http_ssl_module)
ssl_ocsp_cache (ngx_stream_ssl_module)
ssl_ocsp_responder (ngx_http_ssl_module)
ssl_ocsp_responder (ngx_stream_ssl_module)
ssl_password_file (ngx_http_ssl_module)
ssl_password_file (ngx_mail_ssl_module)
ssl_password_file (ngx_stream_ssl_module)
ssl_prefer_server_ciphers (ngx_http_ssl_module)
ssl_prefer_server_ciphers (ngx_mail_ssl_module)
ssl_prefer_server_ciphers (ngx_stream_ssl_module)
ssl_preread
ssl_protocols (ngx_http_ssl_module)
ssl_protocols (ngx_mail_ssl_module)
ssl_protocols (ngx_stream_ssl_module)
ssl_reject_handshake (ngx_http_ssl_module)
ssl_reject_handshake (ngx_stream_ssl_module)
ssl_session_cache (ngx_http_ssl_module)
ssl_session_cache (ngx_mail_ssl_module)
ssl_session_cache (ngx_stream_ssl_module)
ssl_session_ticket_key (ngx_http_ssl_module)
ssl_session_ticket_key (ngx_mail_ssl_module)
ssl_session_ticket_key (ngx_stream_ssl_module)
ssl_session_tickets (ngx_http_ssl_module)
ssl_session_tickets (ngx_mail_ssl_module)
ssl_session_tickets (ngx_stream_ssl_module)
ssl_session_timeout (ngx_http_ssl_module)
ssl_session_timeout (ngx_mail_ssl_module)
ssl_session_timeout (ngx_stream_ssl_module)
ssl_stapling (ngx_http_ssl_module)
ssl_stapling (ngx_stream_ssl_module)
ssl_stapling_file (ngx_http_ssl_module)
ssl_stapling_file (ngx_stream_ssl_module)
ssl_stapling_responder (ngx_http_ssl_module)
ssl_stapling_responder (ngx_stream_ssl_module)
ssl_stapling_verify (ngx_http_ssl_module)
ssl_stapling_verify (ngx_stream_ssl_module)
ssl_trusted_certificate (ngx_http_oidc_module)
ssl_trusted_certificate (ngx_http_ssl_module)
ssl_trusted_certificate (ngx_http_acme_module)
ssl_trusted_certificate (ngx_mail_ssl_module)
ssl_trusted_certificate (ngx_stream_ssl_module)
ssl_trusted_certificate (ngx_mgmt_module)
ssl_verify (ngx_http_acme_module)
ssl_verify (ngx_mgmt_module)
ssl_verify_client (ngx_http_ssl_module)
ssl_verify_client (ngx_mail_ssl_module)
ssl_verify_client (ngx_stream_ssl_module)
ssl_verify_depth (ngx_http_ssl_module)
ssl_verify_depth (ngx_mail_ssl_module)
ssl_verify_depth (ngx_stream_ssl_module)
stall_threshold
starttls
state (ngx_http_upstream_module)
state (ngx_stream_upstream_module)
state_path (ngx_http_acme_module)
state_path (ngx_mgmt_module)
status
status_format
status_zone (ngx_http_api_module)
status_zone (ngx_http_status_module)
sticky
stream
stub_status
sub_filter
sub_filter_last_modified
sub_filter_once
sub_filter_types
subrequest_output_buffer_size
tcp_nodelay (ngx_http_core_module)
tcp_nodelay (ngx_stream_core_module)
tcp_nopush
thread_pool
timeout
timer_resolution
try_files
tunnel_allow_upstream
tunnel_bind
tunnel_bind_dynamic
tunnel_buffer_size
tunnel_connect_timeout
tunnel_next_upstream
tunnel_next_upstream_timeout
tunnel_next_upstream_tries
tunnel_pass
tunnel_read_timeout
tunnel_send_lowat
tunnel_send_timeout
tunnel_socket_keepalive
types
types_hash_bucket_size
types_hash_max_size
underscores_in_headers
uninitialized_variable_warn
upstream (ngx_http_upstream_module)
upstream (ngx_stream_upstream_module)
upstream_conf
uri
usage_report
use
user
userid
userid_domain
userid_expires
userid_flags
userid_mark
userid_name
userid_p3p
userid_path
userid_service
userinfo
uwsgi_allow_upstream
uwsgi_bind
uwsgi_bind_dynamic
uwsgi_buffer_size
uwsgi_buffering
uwsgi_buffers
uwsgi_busy_buffers_size
uwsgi_cache
uwsgi_cache_background_update
uwsgi_cache_bypass
uwsgi_cache_key
uwsgi_cache_lock
uwsgi_cache_lock_age
uwsgi_cache_lock_timeout
uwsgi_cache_max_range_offset
uwsgi_cache_methods
uwsgi_cache_min_uses
uwsgi_cache_path
uwsgi_cache_purge
uwsgi_cache_revalidate
uwsgi_cache_use_stale
uwsgi_cache_valid
uwsgi_connect_timeout
uwsgi_force_ranges
uwsgi_hide_header
uwsgi_ignore_client_abort
uwsgi_ignore_headers
uwsgi_intercept_errors
uwsgi_limit_rate
uwsgi_max_temp_file_size
uwsgi_modifier1
uwsgi_modifier2
uwsgi_next_upstream
uwsgi_next_upstream_timeout
uwsgi_next_upstream_tries
uwsgi_no_cache
uwsgi_param
uwsgi_pass
uwsgi_pass_header
uwsgi_pass_request_body
uwsgi_pass_request_headers
uwsgi_read_timeout
uwsgi_request_buffering
uwsgi_request_dynamic
uwsgi_send_timeout
uwsgi_socket_keepalive
uwsgi_ssl_certificate
uwsgi_ssl_certificate_cache
uwsgi_ssl_certificate_key
uwsgi_ssl_ciphers
uwsgi_ssl_conf_command
uwsgi_ssl_crl
uwsgi_ssl_key_log
uwsgi_ssl_name
uwsgi_ssl_password_file
uwsgi_ssl_protocols
uwsgi_ssl_server_name
uwsgi_ssl_session_reuse
uwsgi_ssl_trusted_certificate
uwsgi_ssl_verify
uwsgi_ssl_verify_depth
uwsgi_store
uwsgi_store_access
uwsgi_temp_file_write_size
uwsgi_temp_path
valid_referers
variables_hash_bucket_size (ngx_http_core_module)
variables_hash_bucket_size (ngx_stream_core_module)
variables_hash_max_size (ngx_http_core_module)
variables_hash_max_size (ngx_stream_core_module)
worker_aio_requests
worker_connections
worker_cpu_affinity
worker_priority
worker_processes
worker_rlimit_core
worker_rlimit_nofile
worker_shutdown_timeout
working_directory
xclient
xml_entities
xslt_last_modified
xslt_param
xslt_string_param
xslt_stylesheet
xslt_types
zone (ngx_http_upstream_module)
zone (ngx_stream_upstream_module)
zone_sync
zone_sync_buffers
zone_sync_connect_retry_interval
zone_sync_connect_timeout
zone_sync_interval
zone_sync_recv_buffer_size
zone_sync_server
zone_sync_ssl
zone_sync_ssl_certificate
zone_sync_ssl_certificate_key
zone_sync_ssl_ciphers
zone_sync_ssl_conf_command
zone_sync_ssl_crl
zone_sync_ssl_name
zone_sync_ssl_password_file
zone_sync_ssl_protocols
zone_sync_ssl_server_name
zone_sync_ssl_trusted_certificate
zone_sync_ssl_verify
zone_sync_ssl_verify_depth
zone_sync_timeout
\n
\nnginx supports a variety of connection processing methods.\nThe availability of a particular method depends on the platform used.\nOn platforms that support several methods nginx will normally\nselect the most efficient method automatically.\nHowever, if needed, a connection processing method can be selected\nexplicitly with the\nuse directive.\n
\nThe following connection processing methods are supported:\n
\nselect — standard method.\nThe supporting module is built automatically on platforms that lack\nmore efficient methods.\nThe --with-select_module and\n--without-select_module configuration parameters\ncan be used to forcibly enable or disable the build of this module.\n
\npoll — standard method.\nThe supporting module is built automatically on platforms that lack\nmore efficient methods.\nThe --with-poll_module and\n--without-poll_module configuration parameters\ncan be used to forcibly enable or disable the build of this module.\n
\nkqueue — efficient method used on\nFreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0, and macOS.\n
\nepoll — efficient method used on\nLinux 2.6+.\n
\nTheEPOLLRDHUP(Linux 2.6.17, glibc 2.8)\nandEPOLLEXCLUSIVE(Linux 4.5, glibc 2.24)\nflags are supported since 1.11.3.\n
\n
\nSome older distributions like SuSE 8.2 provide patches\nthat add epoll support to 2.4 kernels.\n
\n
\n\n/dev/poll — efficient method used on\nSolaris 7 11/99+, HP/UX 11.22+ (eventport), IRIX 6.5.15+,\nand Tru64 UNIX 5.1A+.\n
\neventport — event ports, method\nused on Solaris 10+ (due to known issues,\nit is recommended using the /dev/poll method instead).\n
\n
\n
\n
\nTo quickly process static sets of data such as server names,\nmap directive’s values,\nMIME types, names of request header strings,\nnginx uses hash tables.\nDuring the start and each re-configuration nginx selects the\nminimum possible sizes of hash tables such that the bucket size\nthat stores keys with identical hash values does not exceed the\nconfigured parameter (hash bucket size).\nThe size of a table is expressed in buckets.\nThe adjustment is continued until the table size exceeds the\nhash max size parameter.\nMost hashes have the corresponding directives that allow changing\nthese parameters, for example, for the server names hash they are\nserver_names_hash_max_size\nand server_names_hash_bucket_size.\n
\nThe hash bucket size parameter is aligned to the size that is a\nmultiple of the processor’s cache line size. This speeds up\nkey search in a hash on modern processors by reducing the number\nof memory accesses.\nIf hash bucket size is equal to one processor’s cache line size\nthen the number of memory accesses during the key search will be\ntwo in the worst case — first to compute the bucket address,\nand second during the key search inside the bucket.\nTherefore, if nginx emits the message requesting to increase\neither hash max size or hash bucket size then the first parameter\nshould first be increased.\n
| Build steps See also |
\nTo build nginx on the Microsoft Win32® platform you need:\n\n
\n\n
\nEnsure that paths to Perl, Git and MSYS bin directories are added to\nPATH environment variable before you start build. To set Visual C environment\nrun vcvarsall.bat script from Visual C directory.\n
\n\nTo build nginx:\n
\n\ngit clone https://github.com/nginx/nginx.git\n
\n\nmkdir objs\nmkdir objs/lib\ncd objs/lib\ntar -xzf ../../pcre2-10.39.tar.gz\ntar -xzf ../../zlib-1.3.1.tar.gz\ntar -xzf ../../openssl-3.0.14.tar.gz\n
\n\nauto/configure \\\n --with-cc=cl \\\n --with-debug \\\n --prefix= \\\n --conf-path=conf/nginx.conf \\\n --pid-path=logs/nginx.pid \\\n --http-log-path=logs/access.log \\\n --error-log-path=logs/error.log \\\n --sbin-path=nginx.exe \\\n --http-client-body-temp-path=temp/client_body_temp \\\n --http-proxy-temp-path=temp/proxy_temp \\\n --http-fastcgi-temp-path=temp/fastcgi_temp \\\n --http-scgi-temp-path=temp/scgi_temp \\\n --http-uwsgi-temp-path=temp/uwsgi_temp \\\n --with-cc-opt=-DFD_SETSIZE=1024 \\\n --with-pcre=objs/lib/pcre2-10.39 \\\n --with-zlib=objs/lib/zlib-1.3.1 \\\n --with-openssl=objs/lib/openssl-3.0.14 \\\n --with-openssl-opt=no-asm \\\n --with-http_ssl_module\n
\n\nnmake\n
\n\n
\n
\n
\n
\n\n
\n\n
\n\n
\n\n
\n
\n
\n\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\nnginx can be installed differently, depending on the operating system.\n
\nFor Linux, nginx packages\nfrom nginx.org can be used.\n
\nOn FreeBSD, nginx can be installed either from the packages\nor through the\nports\nsystem.\nThe ports system provides greater flexibility, allowing selection among\na wide range of options.\nThe port will compile nginx with the specified options and install it.\n
\nIf some special functionality is required, not available with packages and\nports, nginx can also be compiled from source files.\nWhile more flexible, this approach may be complex for a beginner.\nFor more information, see Building nginx from Sources.\n
\nThis article assumes the reader has a general knowledge of nginx internals and\nDTrace.\n
\nAlthough nginx built with the --with-debug\noption already provides a lot of information about request processing,\nit is sometimes desirable to trace particular parts of code path more\nthoroughly and at the same time omit the rest of debugging output.\nDTrace pid provider (available on Solaris, macOS) is a useful tool to\nexplore userland program’s internals, since it doesn’t require any code\nchanges and it can help with the task.\nA simple DTrace script to trace and print nginx function calls\nmay look like this:\n\n
\n#pragma D option flowindent\n\npid$target:nginx::entry {\n}\n\npid$target:nginx::return {\n}\n\n\n
\nDTrace capabilities for function calls tracing provide only a limited amount\nof useful information, though.\nReal-time inspection of function arguments is typically more interesting,\nbut also a bit more complicated.\nExamples below are intended to help the reader become more familiar with\nDTrace and the process of analyzing nginx behavior using DTrace.\n
\nOne of the common scenarios for using DTrace with nginx is the following:\nattach to the nginx worker process to log request lines and request start times.\nThe corresponding function to attach is\nngx_http_process_request(), and the argument in question\nis a pointer to the ngx_http_request_t structure.\nDTrace script for such request logging can be as simple as:\n\n
\npid$target::*ngx_http_process_request:entry\n{\n this->request = (ngx_http_request_t *)copyin(arg0, sizeof(ngx_http_request_t));\n this->request_line = stringof(copyin((uintptr_t)this->request->request_line.data,\n this->request->request_line.len));\n printf(\"request line = %s\\n\", this->request_line);\n printf(\"request start sec = %d\\n\", this->request->start_sec);\n}\n\n\n
\nIt should be noted that in the example above DTrace requires some knowledge\nabout the ngx_http_request_t structure.\nUnfortunately while it is possible to use a specific #include\ndirective in the DTrace script and then pass it to a C preprocessor\n(with the -C flag), that doesn’t really work.\nDue to a lot of cross dependencies, almost all nginx header files\nhave to be included.\nIn turn, based on configure script settings,\nnginx headers will include PCRE,\nOpenSSL and a variety of system header files.\nWhile in theory all those header files related to a specific nginx build\nmight be included in DTrace script preprocessing and compilation, in reality\nDTrace script most probably will fail to compile because of unknown syntax in\nsome header files.\n
\nThe problem above can be solved by including only the relevant and\nnecessary structure and type definitions in the DTrace script.\nDTrace has to know sizes of structures, types, and fields offsets.\nThus dependencies can be further reduced by manually optimizing\nstructure definitions for use with DTrace.\n
\nLet’s use DTrace script example above and see what structure definitions\nit needs to work properly.\n
\nFirst of all objs/ngx_auto_config.h file generated by\nconfigure should be included, because it defines a number of constants\naffecting various #ifdef’s.\nAfter that, some basic types and definitions\nlike ngx_str_t, ngx_table_elt_t,\nngx_uint_t etc. should be put at the beginning of the\nDTrace script.\nThese definitions are compact, commonly used and unlikely to be\nfrequently changed.\n
\nThen there’s the ngx_http_request_t structure that\ncontains a lot of pointers to other structures.\nBecause these pointers are really irrelevant to this script, and because they\nhave the same size, it is possible to just replace them with void pointers.\nInstead of changing definitions, it is better to add appropriate typedefs,\nthough:\n\n
\ntypedef ngx_http_upstream_t void;\ntypedef ngx_http_request_body_t void;\n
\n\nLast but not least it is necessary to add definitions of two member structures\n(ngx_http_headers_in_t,\nngx_http_headers_out_t),\ndeclarations of callback functions and definitions of constants.\n
\nThe final DTrace script can be downloaded from\nhere.\n
\nThe following example shows the output of running this script:\n\n
\n# dtrace -C -I ./objs -s trace_process_request.d -p 4848\ndtrace: script 'trace_process_request.d' matched 1 probe\nCPU ID FUNCTION:NAME\n 1 4 .XAbmO.ngx_http_process_request:entry request line = GET / HTTP/1.1\nrequest start sec = 1349162898\n\n 0 4 .XAbmO.ngx_http_process_request:entry request line = GET /en/docs/nginx_dtrace_pid_provider.html HTTP/1.1\nrequest start sec = 1349162899\n
\n\n
Using similar techniques the reader should be able to trace other\nnginx function calls.\n
\n
\n
\n
\nuser www www;\nworker_processes 2;\n\nerror_log /var/log/nginx-error.log info;\n\nevents {\n use kqueue;\n worker_connections 2048;\n}\n\n...\n\n
\n\n\n| \n Syntax:\n | \n\n accept_mutex \n | \n
|---|---|
| \n Default:\n | \n\n accept_mutex off;\n | \n
| \n Context:\n | \n\n events\n | \n
\nIf accept_mutex is enabled,\nworker processes will accept new connections by turn.\nOtherwise, all worker processes will be notified about new connections,\nand if volume of new connections is low, some of the worker processes\nmay just waste system resources.\n
\nThere is no need to enable accept_mutex\non systems that support the\nEPOLLEXCLUSIVE flag (1.11.3) or\nwhen using reuseport.\n\n
\nPrior to version 1.11.3, the default value was on.\n\n
| \n Syntax:\n | \n\n accept_mutex_delay \n | \n
|---|---|
| \n Default:\n | \n\n accept_mutex_delay 500ms;\n | \n
| \n Context:\n | \n\n events\n | \n
\nIf accept_mutex is enabled, specifies the maximum time\nduring which a worker process will try to restart accepting new\nconnections if another worker process is currently accepting\nnew connections.\n
| \n Syntax:\n | \n\n daemon \n | \n
|---|---|
| \n Default:\n | \n\n daemon on;\n | \n
| \n Context:\n | \n\n main\n | \n
\nDetermines whether nginx should become a daemon.\nMainly used during development.\n
| \n Syntax:\n | \n\n debug_connection \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n events\n | \n
\nEnables debugging log for selected client connections.\nOther connections will use logging level set by the\nerror_log directive.\nDebugged connections are specified by IPv4 or IPv6 (1.3.0, 1.2.1)\naddress or network.\nA connection may also be specified using a hostname.\nFor connections using UNIX-domain sockets (1.3.0, 1.2.1),\ndebugging log is enabled by the “unix:” parameter.\n
\nevents {\n debug_connection 127.0.0.1;\n debug_connection localhost;\n debug_connection 192.0.2.0/24;\n debug_connection ::1;\n debug_connection 2001:0db8::/32;\n debug_connection unix:;\n ...\n}\n\n
\nFor this directive to work, nginx needs to\nbe built with --with-debug,\nsee “A debugging log”.\n\n
| \n Syntax:\n | \n\n debug_points \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
\nThis directive is used for debugging.\n
\nWhen internal error is detected, e.g. the leak of sockets on\nrestart of working processes, enabling debug_points\nleads to a core file creation (abort)\nor to stopping of a process (stop) for further\nanalysis using a system debugger.\n
| \n Syntax:\n | \n\n env \n | \n
|---|---|
| \n Default:\n | \n\n env TZ;\n | \n
| \n Context:\n | \n\n main\n | \n
\nBy default, nginx removes all environment variables inherited\nfrom its parent process except the TZ variable.\nThis directive allows preserving some of the inherited variables,\nchanging their values, or creating new environment variables.\nThese variables are then:\n
\n
\nThe TZ variable is always inherited and available to the\nngx_http_perl_module\nmodule, unless it is configured explicitly.\n
\nUsage example:\n
\nenv MALLOC_OPTIONS;\nenv PERL5LIB=/data/site/modules;\nenv OPENSSL_ALLOW_PROXY_CERTS=1;\n
\n
\n
\nThe NGINX environment variable is used internally by nginx\nand should not be set directly by the user.\n
\n
| \n Syntax:\n | \n\n error_log \n | \n
|---|---|
| \n Default:\n | \n\n error_log logs/error.log error;\n | \n
| \n Context:\n | \n\n main, http, mail, stream, server, location\n | \n
\nConfigures logging.\nSeveral logs can be specified on the same configuration level (1.5.2).\nIf on the main configuration level writing a log to a file\nis not explicitly defined, the default file will be used.\n
\nThe first parameter defines a file that will store the log.\n\nThe special value stderr selects the standard error file.\nLogging to syslog can be configured by specifying\nthe “syslog:” prefix.\nLogging to a\ncyclic memory buffer\ncan be configured by specifying the “memory:” prefix and\nbuffer size, and is generally used for debugging (1.7.11).\n
\nThe second parameter determines the level of logging,\nand can be one of the following:\ndebug, info, notice,\nwarn, error, crit,\nalert, or emerg.\nLog levels above are listed in the order of increasing severity.\nSetting a certain log level will cause all messages of\nthe specified and more severe log levels to be logged.\nFor example, the default level error will\ncause error, crit,\nalert, and emerg messages\nto be logged.\nIf this parameter is omitted then error is used.\n
\nFordebuglogging to work, nginx needs to\nbe built with--with-debug,\nsee “A debugging log”.\n
\n
\nThe json parameter (1.29.8)\nenables writing a log in the JSON format,\nwith support for\ncontext tags:\n
\n{\n \"level\": \"error\",\n \"timestamp\": \"2026-05-13T10:30:15.042+00:00\",\n \"pid\": 12345, \"tid\": 12345, \"cnum\": 3,\n \"msg\": \"connect() failed\",\n \"client\": \"192.168.1.10\", \"server\": \"example.com\",\n \"request\": \"GET /api HTTP/1.1\",\n \"upstream\": \"http://127.0.0.1:8080/api\",\n \"errno\": 111,\n \"errtext\": \"Connection refused\"\n}\n \nA log entry cannot exceed 2 KB,\ndata beyond this limit is truncated to “truncated”:1.\nDebug logging is not supported for JSON. \n
\nThis parameter is available as part of our\ncommercial subscription.\n
\n
\n
\nThe directive can be specified on the\nstreamlevel\nstarting from version 1.7.11,\nand on the
\n
| \n Syntax:\n | \n\n events { ... }\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
\nProvides the configuration file context in which the directives that\naffect connection processing are specified.\n
| \n Syntax:\n | \n\n include \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n any\n | \n
\nIncludes another file, or files matching the\nspecified mask, into configuration.\nIncluded files should consist of\nsyntactically correct directives and blocks.\n
\nUsage example:\n
\ninclude mime.types;\ninclude vhosts/*.conf;\n
\n
| \n Syntax:\n | \n\n load_module \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
This directive appeared in version 1.9.11.\n
\nLoads a dynamic module.\n
\nExample:\n
\nload_module modules/ngx_mail_module.so;\n
\n
| \n Syntax:\n | \n\n lock_file \n | \n
|---|---|
| \n Default:\n | \n\n lock_file logs/nginx.lock;\n | \n
| \n Context:\n | \n\n main\n | \n
\nnginx uses the locking mechanism to implement accept_mutex\nand serialize access to shared memory.\nOn most systems the locks are implemented using atomic operations,\nand this directive is ignored.\nOn other systems the “lock file” mechanism is used.\nThis directive specifies a prefix for the names of lock files.\n
| \n Syntax:\n | \n\n master_process \n | \n
|---|---|
| \n Default:\n | \n\n master_process on;\n | \n
| \n Context:\n | \n\n main\n | \n
\nDetermines whether worker processes are started.\nThis directive is intended for nginx developers.\n
| \n Syntax:\n | \n\n multi_accept \n | \n
|---|---|
| \n Default:\n | \n\n multi_accept off;\n | \n
| \n Context:\n | \n\n events\n | \n
\nIf multi_accept is disabled, a worker process\nwill accept one new connection at a time.\nOtherwise, a worker process\nwill accept all new connections at a time.\n
\nThe directive is ignored if kqueue\nconnection processing method is used, because it reports\nthe number of new connections waiting to be accepted.\n
\n
| \n Syntax:\n | \n\n pcre_jit \n | \n
|---|---|
| \n Default:\n | \n\n pcre_jit off;\n | \n
| \n Context:\n | \n\n main\n | \n
This directive appeared in version 1.1.12.\n
\nEnables or disables the use of “just-in-time compilation” (PCRE JIT)\nfor the regular expressions known by the time of configuration parsing.\n
\nPCRE JIT can speed up processing of regular expressions significantly.\n
\nThe JIT is available in PCRE libraries starting from version 8.20\nbuilt with the--enable-jitconfiguration parameter.\nWhen the PCRE library is built with nginx (--with-pcre=),\nthe JIT support is enabled via the\n--with-pcre-jitconfiguration parameter.\n
\n
| \n Syntax:\n | \n\n pid \n | \n
|---|---|
| \n Default:\n | \n\n pid logs/nginx.pid;\n | \n
| \n Context:\n | \n\n main\n | \n
\nDefines a file that will store the process ID of the main process.\n
| \n Syntax:\n | \n\n ssl_engine \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
\nDefines the name of the hardware SSL accelerator.\n
\n
\nThe module may be dynamically loaded by OpenSSL during configuration testing.\n
\n
| \n Syntax:\n | \n\n ssl_object_cache_inheritable \n | \n
|---|---|
| \n Default:\n | \n\n ssl_object_cache_inheritable on;\n | \n
| \n Context:\n | \n\n main\n | \n
This directive appeared in version 1.27.4.\n
\nIf enabled, SSL objects\n(SSL certificates, secret keys, trusted CA certificates, CRL lists)\nwill be inherited across configuration reloads.\n
\nSSL objects loaded from a file are inherited\nif the modification time and file index has not been changed\nsince the previous configuration load.\nSecret keys specified as\nengine:name:id are never inherited.\nSecret keys specified as\ndata:value are always inherited.\n
\n
\nSSL objects loaded from variables cannot be inherited.\n
\n
\nExample:\n
\nssl_object_cache_inheritable on;\n\nhttp {\n ...\n server {\n ...\n ssl_certificate example.com.crt;\n ssl_certificate_key example.com.key;\n }\n}\n\n
| \n Syntax:\n | \n\n stall_threshold \n | \n
|---|---|
| \n Default:\n | \n\n stall_threshold 1000ms;\n | \n
| \n Context:\n | \n\n events\n | \n
This directive appeared in version 1.29.0.\n
\nAllows overriding the default time threshold for the event loop iteration\nbefore a stall is reported.\nBy default, a stall is reported\nwhen an event loop iteration exceeds 1000ms.\nIf the timer_resolution directive is enabled,\nthe time threshold will be ignored.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n thread_pool \n \n | \n
|---|---|
| \n Default:\n | \n\n thread_pool default threads=32 max_queue=65536;\n | \n
| \n Context:\n | \n\n main\n | \n
This directive appeared in version 1.7.11.\n
\nDefines the name and parameters of a thread pool\nused for multi-threaded reading and sending of files\nwithout blocking\nworker processes.\n
\nThe threads parameter\ndefines the number of threads in the pool.\n
\nIn the event that all threads in the pool are busy,\na new task will wait in the queue.\nThe max_queue parameter limits the number\nof tasks allowed to be waiting in the queue.\nBy default, up to 65536 tasks can wait in the queue.\nWhen the queue overflows, the task is completed with an error.\n
| \n Syntax:\n | \n\n timer_resolution \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
\nReduces timer resolution in worker processes, thus reducing the\nnumber of gettimeofday() system calls made.\nBy default, gettimeofday() is called each time\na kernel event is received.\nWith reduced resolution, gettimeofday() is only\ncalled once per specified interval.\n
\nExample:\n
\ntimer_resolution 100ms;\n
\n
\nInternal implementation of the interval depends on the method used:\n
EVFILT_TIMER filter if kqueue is used;\ntimer_create() if eventport is used;\nsetitimer() otherwise.\n\n
| \n Syntax:\n | \n\n use \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n events\n | \n
\nSpecifies the connection processing\nmethod to use.\nThere is normally no need to specify it explicitly, because nginx will\nby default use the most efficient method.\n
| \n Syntax:\n | \n\n user \n | \n
|---|---|
| \n Default:\n | \n\n user nobody nobody;\n | \n
| \n Context:\n | \n\n main\n | \n
\nDefines user and group\ncredentials used by worker processes.\nIf group is omitted, a group whose name equals\nthat of user is used.\n
| \n Syntax:\n | \n\n worker_aio_requests \n | \n
|---|---|
| \n Default:\n | \n\n worker_aio_requests 32;\n | \n
| \n Context:\n | \n\n events\n | \n
\n This directive appeared in versions 1.1.4 and 1.0.7.\n \n
\n\nWhen using aio\nwith the epoll\nconnection processing method, sets the maximum number of\noutstanding asynchronous I/O operations\nfor a single worker process.\n
| \n Syntax:\n | \n\n worker_connections \n | \n
|---|---|
| \n Default:\n | \n\n worker_connections 512;\n | \n
| \n Context:\n | \n\n events\n | \n
\nSets the maximum number of simultaneous connections that\ncan be opened by a worker process.\n
\nIt should be kept in mind that this number includes all connections\n(e.g. connections with proxied servers, among others),\nnot only connections with clients.\nAnother consideration is that the actual number of simultaneous\nconnections cannot exceed the current limit on\nthe maximum number of open files, which can be changed by\nworker_rlimit_nofile.\n
| \n Syntax:\n | \n\n worker_cpu_affinity worker_cpu_affinity \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
\nBinds worker processes to the sets of CPUs.\nEach CPU set is represented by a bitmask of allowed CPUs.\nThere should be a separate set defined for each of the worker processes.\nBy default, worker processes are not bound to any specific CPUs.\n
\nFor example,\n
\nworker_processes 4;\nworker_cpu_affinity 0001 0010 0100 1000;\n
\nbinds each worker process to a separate CPU, while\n
\nworker_processes 2;\nworker_cpu_affinity 0101 1010;\n
\nbinds the first worker process to CPU0/CPU2,\nand the second worker process to CPU1/CPU3.\nThe second example is suitable for hyper-threading.\n
\nThe special value auto (1.9.10) allows\nbinding worker processes automatically to available CPUs:\n
\nworker_processes auto;\nworker_cpu_affinity auto;\n
\nThe optional mask parameter can be used to limit the CPUs\navailable for automatic binding:\n
\nworker_cpu_affinity auto 01010101;\n
\n
\n
\nThe directive is only available on FreeBSD and Linux.\n
\n
| \n Syntax:\n | \n\n worker_priority \n | \n
|---|---|
| \n Default:\n | \n\n worker_priority 0;\n | \n
| \n Context:\n | \n\n main\n | \n
\nDefines the scheduling priority for worker processes like it is\ndone by the nice command: a negative\nnumber\nmeans higher priority.\nAllowed range normally varies from -20 to 20.\n
\nExample:\n
\nworker_priority -10;\n
\n
| \n Syntax:\n | \n\n worker_processes \n | \n
|---|---|
| \n Default:\n | \n\n worker_processes 1;\n | \n
| \n Context:\n | \n\n main\n | \n
\nDefines the number of worker processes.\n
\nThe optimal value depends on many factors including (but not\nlimited to) the number of CPU cores, the number of hard disk\ndrives that store data, and load pattern.\nWhen one is in doubt, setting it to the number of available CPU cores\nwould be a good start (the value “auto”\nwill try to autodetect it).\n
\nThe auto parameter is supported starting from\nversions 1.3.8 and 1.2.5.\n\n
| \n Syntax:\n | \n\n worker_rlimit_core \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
\nChanges the limit on the largest size of a core file\n(RLIMIT_CORE) for worker processes.\nUsed to increase the limit without restarting the main process.\n
| \n Syntax:\n | \n\n worker_rlimit_nofile \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
\nChanges the limit on the maximum number of open files\n(RLIMIT_NOFILE) for worker processes.\nUsed to increase the limit without restarting the main process.\n
| \n Syntax:\n | \n\n worker_shutdown_timeout \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
This directive appeared in version 1.11.11.\n
\nConfigures a timeout for a graceful shutdown of worker processes.\nWhen the time expires,\nnginx will try to close all the connections currently open\nto facilitate shutdown.\n
| \n Syntax:\n | \n\n working_directory \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
\nDefines the current working directory for a worker process.\nIt is primarily used when writing a core-file, in which case\na worker process should have write permission for the\nspecified directory.\n
\n\n| Example Configuration Directives google_perftools_profiles |
\nThe ngx_google_perftools_module module (0.6.29) enables\nprofiling of nginx worker processes using\nGoogle Performance Tools.\nThe module is intended for nginx developers.\n
\nThis module is not built by default, it should be enabled with the\n--with-google_perftools_module\nconfiguration parameter.\n
\nThis module requires the\ngperftools library.\n
\n
\n\n\n\n
\ngoogle_perftools_profiles /path/to/profile;\n
\nProfiles will be stored as\n/path/to/profile.<worker_pid>.\n
| \n Syntax:\n | \n\n google_perftools_profiles \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
\nSets a file name that keeps profiling information of\nnginx worker process.\nThe ID of the worker process is always a part of the file name\nand is appended to the end of the file name, after a dot.\n
\n\n| Example Configuration Directives mgmt enforce_initial_report license_token proxy proxy_username proxy_password resolver ssl_crl ssl_trusted_certificate ssl_verify state_path usage_report |
\nThe ngx_mgmt_module module enables\nNGINX Plus license verification and usage reporting.\nThis is mandatory for each NGINX Plus instance since 1.27.2 (\nNGINX Plus R33).\n
\nA JWT license file named license.jwt\nshould be located at\n/etc/nginx/ for Linux or\n/usr/local/etc/nginx/ for FreeBSD\nor at the path specified by the license_token directive.\nThe license file is available from\nMyF5.\n
\nUsage report is sent directly or via proxy\nto F5 licensing endpoint\nevery hour using the\nsecure connection.\nOptionally, in network-restricted environments\nreporting can be configured to\nF5 NGINX\nInstance Manager from which the report can be sent\nto F5 licensing endpoint.\n
\nBy default, if the initial usage report\nis not received by F5 licensing endpoint, nginx will stop processing traffic.\n
\nAutomatic license renewal is supported since 1.29.0\n(NGINX Plus R35)\nfor instances that report directly to the F5 licensing endpoint.\nOn renewal, NGINX downloads the updated JWT from F5 licensing endpoint\nand applies it without\nconfiguration reload.\nThe updated license is stored\nin the state_path directory.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nmgmt {\n # in case if custom path is required\n license_token custom/file/path/license.jwt;\n\n # in case of reporting to NGINX Instance Manager\n usage_report endpoint=NIM_FQDN;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n mgmt { ... }\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
\nProvides the configuration file context in which\nusage reporting and license management directives\nare specified.\n
| \n Syntax:\n | \n\n enforce_initial_report \n | \n
|---|---|
| \n Default:\n | \n\n enforce_initial_report on;\n | \n
| \n Context:\n | \n\n mgmt\n | \n
This directive appeared in version 1.27.2.\n
\nEnables or disables the 180-day grace period\nfor sending the initial usage report.\n
\nThe initial usage report is sent immediately\nupon nginx first start after installation.\nBy default, if the initial report is not received by F5 licensing endpoint,\nnginx stops processing traffic until the report is successfully delivered.\nSetting the directive value to off enables\nthe 180-day grace period during which\nthe initial usage report must be received by F5 licensing endpoint.\n
| \n Syntax:\n | \n\n license_token \n | \n
|---|---|
| \n Default:\n | \n\n license_token license.jwt;\n | \n
| \n Context:\n | \n\n mgmt\n | \n
This directive appeared in version 1.27.2.\n
\nSpecifies a JWT license file.\nBy default, the license.jwt file is expected to be at\n/etc/nginx/ for Linux or at\n/usr/local/etc/nginx/ for FreeBSD.\n
| \n Syntax:\n | \n\n proxy \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mgmt\n | \n
This directive appeared in version 1.27.4.\n
\nSets the HTTP CONNECT proxy\nused for sending the usage report.\n
| \n Syntax:\n | \n\n proxy_username \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mgmt\n | \n
This directive appeared in version 1.27.4.\n
\nSets the user name used for authentication on\nthe proxy.\n
| \n Syntax:\n | \n\n proxy_password \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mgmt\n | \n
This directive appeared in version 1.27.4.\n
\nSets the password used for authentication on\nthe proxy.\n
\nThe password is sent unencrypted by default.\nIf the proxy supports TLS, the connection to the proxy can be\nprotected with the stream\nmodule:\n
\nmgmt {\n proxy 127.0.0.1:8080;\n proxy_username <name>;\n proxy_password <password>;\n}\n\nstream {\n server {\n listen 127.0.0.1:8080;\n \n proxy_ssl on;\n proxy_ssl_verify on;\n proxy_ssl_trusted_certificate <proxy_ca_file>;\n\n proxy_pass <proxy_host>:<proxy_port>;\n }\n}\n\n
| \n Syntax:\n | \n\n resolver \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mgmt\n | \n
\nConfigures name servers used to resolve usage reporting endpoint name.\nBy default, the system resolver is used.\n
\nSee resolver for details.\n
| \n Syntax:\n | \n\n ssl_crl \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mgmt\n | \n
\nSpecifies a file with revoked certificates (CRL)\nin the PEM format used to verify\nthe certificate of the usage reporting endpoint.\nWhen using intermediate certificates, their CRLs should be\nspecified in the same file.\n
| \n Syntax:\n | \n\n ssl_trusted_certificate \n | \n
|---|---|
| \n Default:\n | \n\n ssl_trusted_certificate system CA bundle;\n | \n
| \n Context:\n | \n\n mgmt\n | \n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to verify\nthe certificate of the usage reporting endpoint.\n
| \n Syntax:\n | \n\n ssl_verify \n | \n
|---|---|
| \n Default:\n | \n\n ssl_verify on;\n | \n
| \n Context:\n | \n\n mgmt\n | \n
\nEnables or disables verification of the usage reporting endpoint certificate.\n
\n
\nBefore 1.27.2, the default value was off.\n\n
| \n Syntax:\n | \n\n state_path \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mgmt\n | \n
This directive appeared in version 1.27.2.\n
\nDefines a directory for storing state files\n(nginx-mgmt-*)\ncreated by the ngx_mgmt_module module.\nThe default directory\nfor Linux is /var/lib/nginx/state,\nfor FreeBSD is /var/db/nginx/state.\n
| \n Syntax:\n | \n\n usage_report [\n | \n
|---|---|
| \n Default:\n | \n\n usage_report endpoint=product.connect.nginx.com interval=1h;\n | \n
| \n Context:\n | \n\n mgmt\n | \n
\nSets the address and port\nof the usage reporting endpoint.\nThe interval parameter sets an interval between\ntwo consecutive reports.\n
\nBefore 1.27.2, the default values were\nnginx-mgmt.localand\n30m.\n
\n
\n\n| Example Configuration Directives otel_exporter otel_service_name otel_resource_attr otel_trace otel_trace_context otel_span_name otel_span_attr Default span attributes Embedded Variables |
\nThe ngx_otel_module module provides\nOpenTelemetry\ndistributed tracing support.\nThe module supports\nW3C\ncontext propagation and OTLP/gRPC export protocol.\n
\nThe source code of the module is available\nhere.\nDownload and install instructions are available\nhere.\n
\nThe module is also available in a prebuilt\nnginx-module-otel\npackage\nsince 1.25.3\nand in nginx-plus-module-otel package\nas part of our\ncommercial subscription since 1.23.4.\n
\n
\nload_module modules/ngx_otel_module.so;\n\nevents {\n}\n\nhttp {\n\n otel_exporter {\n endpoint localhost:4317;\n }\n\n server {\n listen 127.0.0.1:8080;\n\n location / {\n otel_trace on;\n otel_trace_context inject;\n\n proxy_pass http://backend;\n }\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n otel_exporter { ... }\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nSpecifies OTel data export parameters:\n\n
\n endpoint [(http|https)://]host:port;\n trusted_certificate path;header name value;interval time;5 seconds.\nbatch_size number;512.\nbatch_count number;4.\n\nExample:\n
\notel_exporter {\n endpoint https://otel-example.nginx.com:4317;\n\n header X-API-Token \"my-token-value\";\n}\n\n
| \n Syntax:\n | \n\n otel_service_name \n | \n
|---|---|
| \n Default:\n | \n\n otel_service_name unknown_service:nginx;\n | \n
| \n Context:\n | \n\n http\n | \n
\nSets the\n“service.name”\nattribute of the OTel resource.\n
| \n Syntax:\n | \n\n otel_resource_attr \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
This directive appeared in version 0.1.2.\n
\nSets a custom OTel resource attribute.\n
| \n Syntax:\n | \n\n otel_trace \n | \n
|---|---|
| \n Default:\n | \n\n otel_trace off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables OpenTelemetry tracing.\nThe directive can also be enabled by specifying a variable:\n
\nsplit_clients \"$otel_trace_id\" $ratio_sampler {\n 10% on;\n * off;\n}\n\nserver {\n location / {\n otel_trace $ratio_sampler;\n otel_trace_context inject;\n proxy_pass http://backend;\n }\n}\n\n
| \n Syntax:\n | \n\n otel_trace_context \n | \n
|---|---|
| \n Default:\n | \n\n otel_trace_context ignore;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies how to propagate\ntraceparent/tracestate headers:\n\n
extractinjectpropagateignore\n
| \n Syntax:\n | \n\n otel_span_name \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines the name of the OTel\nspan.\nBy default, it is a name of the location for a request.\nThe name can contain variables.\n
| \n Syntax:\n | \n\n otel_span_attr \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nAdds a custom OTel span attribute.\nThe value can contain variables.\n
\n\n\n\nThe following\nspan\nattributes\nare added automatically:\n\n
http.method\nhttp.target\nhttp.route\nhttp.scheme\nhttp.flavor\nhttp.user_agent\nhttp.request_content_length\nhttp.response_content_length\nhttp.status_code\nnet.host.name\nnet.host.port\nnet.sock.peer.addr\nnet.sock.peer.port\n\n
\n\n\n\n
$otel_trace_id56552bc4daa3bf39c08362527e1dd6c4\n$otel_span_id4c0b8531ec38ca59\n$otel_parent_iddc94d281b0f884ea\n$otel_parent_sampledsampled” flag of the parent span,\ncan be “1” or “0”\n\n
\n\n| Building from sources Configuration tips Troubleshooting |
\nSupport for\nQUIC\nand\nHTTP/3\nprotocols is available since 1.25.0, it is included in\nLinux binary packages.\nPlease refer to the\nngx_http_v3_module\ndocumentation.\n
\nThe build is configured using the configure command.\nPlease refer to Building nginx from Sources for details.\n
\nThe OpenSSL library\nversion 3.5.1 or higher is recommended to build nginx with QUIC support.\nOtherwise, the OpenSSL\ncompatibility layer will be used that does not support\nearly data.\nAlternatively,\nBoringSSL,\nLibreSSL, or\nQuicTLS\nprebuilt libraries can be used.\n
\nUse the following command to configure nginx with\nBoringSSL:\n
\n./configure\n --with-debug\n --with-http_v3_module\n --with-cc-opt=\"-I../boringssl/include\"\n --with-ld-opt=\"-L../boringssl/build -lstdc++\"\n
\n
\nAlternatively, nginx can be configured with\nQuicTLS:\n
\n./configure\n --with-debug\n --with-http_v3_module\n --with-cc-opt=\"-I../quictls/build/include\"\n --with-ld-opt=\"-L../quictls/build/lib\"\n
\n
\nAlternatively, nginx can be configured with\nLibreSSL:\n
\n./configure\n --with-debug\n --with-http_v3_module\n --with-cc-opt=\"-I../libressl/build/include\"\n --with-ld-opt=\"-L../libressl/build/lib\"\n
\n
\nAfter configuration,\nnginx is compiled and installed using make.\n
\nThe listen directive in\nngx_http_core_module\nmodule got a new parameter\nquic\nwhich enables HTTP/3 over QUIC on the specified port.\n
\nAlong with the quic parameter\nit is also possible to specify the\nreuseport\nparameter to make it work properly with multiple workers.\n
\nTo enable\naddress validation:\n
\nquic_retry on;\n
\n\nTo enable\n0-RTT:\n
\nssl_early_data on;\n
\n\nTo enable\nGSO (Generic Segmentation Offloading):\n
\nquic_gso on;\n
\n\nTo set\nhost key for various tokens:\n
\nquic_host_key <filename>;\n
\n
\nQUIC requires TLSv1.3 protocol version which is enabled by default\nin the ssl_protocols directive.\n
\nBy default,\nGSO Linux-specific optimization\nis disabled.\nEnable it in case a corresponding network interface is configured\nto support GSO.\n
\nTips that may help to identify problems:\n
nginx -V shows what it is currently used).\nquic” prefix\nand can be easily filtered out.\nNGX_QUIC_DEBUG_PACKETS,\nNGX_QUIC_DEBUG_FRAMES,\nNGX_QUIC_DEBUG_ALLOC,\nNGX_QUIC_DEBUG_CRYPTO.\n\n\n
\n./configure\n --with-http_v3_module\n --with-debug\n --with-cc-opt=\"-DNGX_QUIC_DEBUG_PACKETS -DNGX_QUIC_DEBUG_CRYPTO\"\n
\n
\n\n
\nnginx supports the following command-line parameters:\n
-? | -h — print help\nfor command-line parameters.\n-c file — use an alternative\nconfiguration file instead of a default file.\n-e file — use an alternative\nerror log file to store the log\ninstead of a default file (1.19.5).\nThe special value stderr selects the standard error file.\n-g directives — set\nglobal configuration directives,\nfor example,\n\n\nnginx -g \"pid /var/run/nginx.pid; worker_processes `sysctl -n hw.ncpu`;\"\n
-l port — enable\nnginx control REST API\non a specified port or UNIX-domain socket (1.29.8).\n\n
\nThis parameter is available as part of our\ncommercial subscription.\n
\n
\n-p prefix — set nginx path prefix,\ni.e. a directory that will keep server files\n(default value is /usr/local/nginx).\n-q — suppress non-error messages\nduring configuration testing.\n-s signal — send a signal\nto the master process.\nThe argument signal can be one of:\nstop — shut down quickly\nquit — shut down gracefully\nreload — reload configuration,\nstart the new worker process with a new configuration,\ngracefully shut down old worker processes.\nreopen — reopen log files\n-t — test the configuration file: nginx checks the\nconfiguration for correct syntax, and then tries to open files\nreferred in the configuration.\n-T — same as -t,\nbut additionally dump configuration files to standard output (1.9.2).\n-v — print nginx version.\n-V — print nginx version, compiler version,\nand configure parameters.\n\n
| Sizes and offsets Time intervals |
\nnginx supports several measurement units for specifying\nsizes, offsets, and time intervals within configuration files.\n
\nSizes can be specified in bytes, kilobytes, or megabytes\nusing the following suffixes:\n\n
k and K for kilobytes\nm and M for megabytes\n\n
\nFor example,\n“1024”, “8k”, “1m”.\n
\nOffsets can be also specified in gigabytes using the\ng or G suffixes.\n
\nTime intervals can be specified in milliseconds, seconds,\nminutes, hours, days and so on, using the following suffixes:\n
| ms | milliseconds |
| s | seconds (default) |
| m | minutes |
| h | hours |
| d | days |
| w | weeks |
| M | months, 30 days |
| y | years, 365 days |
\nMultiple units can be combined in a single value\nby specifying them in the order from the most to the least significant,\nand optionally separated by whitespace.\nFor example, “1h 30m” specifies the same time\nas “90m” or “5400s”.\n
\n
\nA value without a suffix means seconds.\n
\n\nIt is recommended to always specify a suffix.\n
\n\nCertain time intervals can be specified only with a seconds resolution.\n
\n\n
\nThe\nerror_log\nand\naccess_log\ndirectives support logging to syslog.\nThe following parameters configure logging to syslog:\n
server=addressunix:” prefix.\nIf port is not specified, the UDP port 514 is used.\nIf a domain name resolves to several IP addresses, the first resolved\naddress is used.\nfacility=stringkern”, “user”,\n“mail”, “daemon”,\n“auth”, “intern”,\n“lpr”, “news”, “uucp”,\n“clock”, “authpriv”,\n“ftp”, “ntp”, “audit”,\n“alert”, “cron”,\n“local0”..“local7”.\nDefault is “local7”.\nseverity=stringinfo”.\n\nSeverity of error messages is determined by nginx, thus the parameter\nis ignored in the error_log directive.\n\ntag=stringnginx”.\nnohostname\nExample syslog configuration:\n
\nerror_log syslog:server=192.168.1.1 debug;\n\naccess_log syslog:server=unix:/var/log/nginx.sock,nohostname;\naccess_log syslog:server=[2001:db8::1]:12345,facility=local7,tag=nginx,severity=info combined;\n
\n
\n
\nLogging to syslog is available since version 1.7.1.\nAs part of our\ncommercial subscription\nlogging to syslog is available since version 1.5.3.\n
\n
\nQ:\nWhile building nginx version 0.7.66, 0.8.35 or higher on Linux\nthe following warning messages are issued:\n\n
\nwarning: `sys_errlist' is deprecated;\n use `strerror' or `strerror_r' instead\nwarning: `sys_nerr' is deprecated;\n use `strerror' or `strerror_r' instead\n
\n\n
\nA:\nThis is normal: nginx has to use the deprecated sys_errlist[] and sys_nerr\nin signal handlers because strerror() and strerror_r() functions\nare not Async-Signal-Safe.\n
\n $acme_certificate
$acme_certificate_key
$ancient_browser
$arg_
$args
$binary_remote_addr (ngx_http_core_module)
$binary_remote_addr (ngx_stream_core_module)
$body_bytes_sent
$bytes_received
$bytes_sent (ngx_http_core_module)
$bytes_sent (ngx_http_log_module)
$bytes_sent (ngx_stream_core_module)
$connection (ngx_http_core_module)
$connection (ngx_http_log_module)
$connection (ngx_stream_core_module)
$connection_requests (ngx_http_core_module)
$connection_requests (ngx_http_log_module)
$connection_time
$connections_active
$connections_reading
$connections_waiting
$connections_writing
$content_length
$content_type
$cookie_
$date_gmt
$date_local
$document_root
$document_uri
$fastcgi_path_info
$fastcgi_script_name
$geoip_area_code (ngx_http_geoip_module)
$geoip_area_code (ngx_stream_geoip_module)
$geoip_city (ngx_http_geoip_module)
$geoip_city (ngx_stream_geoip_module)
$geoip_city_continent_code (ngx_http_geoip_module)
$geoip_city_continent_code (ngx_stream_geoip_module)
$geoip_city_country_code (ngx_http_geoip_module)
$geoip_city_country_code (ngx_stream_geoip_module)
$geoip_city_country_code3 (ngx_http_geoip_module)
$geoip_city_country_code3 (ngx_stream_geoip_module)
$geoip_city_country_name (ngx_http_geoip_module)
$geoip_city_country_name (ngx_stream_geoip_module)
$geoip_country_code (ngx_http_geoip_module)
$geoip_country_code (ngx_stream_geoip_module)
$geoip_country_code3 (ngx_http_geoip_module)
$geoip_country_code3 (ngx_stream_geoip_module)
$geoip_country_name (ngx_http_geoip_module)
$geoip_country_name (ngx_stream_geoip_module)
$geoip_dma_code (ngx_http_geoip_module)
$geoip_dma_code (ngx_stream_geoip_module)
$geoip_latitude (ngx_http_geoip_module)
$geoip_latitude (ngx_stream_geoip_module)
$geoip_longitude (ngx_http_geoip_module)
$geoip_longitude (ngx_stream_geoip_module)
$geoip_org (ngx_http_geoip_module)
$geoip_org (ngx_stream_geoip_module)
$geoip_postal_code (ngx_http_geoip_module)
$geoip_postal_code (ngx_stream_geoip_module)
$geoip_region (ngx_http_geoip_module)
$geoip_region (ngx_stream_geoip_module)
$geoip_region_name (ngx_http_geoip_module)
$geoip_region_name (ngx_stream_geoip_module)
$gzip_ratio
$host
$hostname (ngx_http_core_module)
$hostname (ngx_stream_core_module)
$http2
$http3
$http_
$https
$invalid_referer
$is_args
$is_request_port
$jwt_claim_
$jwt_header_
$jwt_payload
$limit_conn_status (ngx_http_limit_conn_module)
$limit_conn_status (ngx_stream_limit_conn_module)
$limit_rate
$limit_req_status
$memcached_key
$modern_browser
$mqtt_preread_clientid
$mqtt_preread_username
$msec (ngx_http_core_module)
$msec (ngx_http_log_module)
$msec (ngx_stream_core_module)
$msie
$nginx_version (ngx_http_core_module)
$nginx_version (ngx_stream_core_module)
$oidc_access_token
$oidc_claim_
$oidc_id_token
$oidc_userinfo
$otel_parent_id
$otel_parent_sampled
$otel_span_id
$otel_trace_id
$pid (ngx_http_core_module)
$pid (ngx_stream_core_module)
$pipe (ngx_http_core_module)
$pipe (ngx_http_log_module)
$protocol
$proxy_add_x_forwarded_for
$proxy_host
$proxy_port
$proxy_protocol_addr (ngx_http_core_module)
$proxy_protocol_addr (ngx_stream_core_module)
$proxy_protocol_port (ngx_http_core_module)
$proxy_protocol_port (ngx_stream_core_module)
$proxy_protocol_server_addr (ngx_http_core_module)
$proxy_protocol_server_addr (ngx_stream_core_module)
$proxy_protocol_server_port (ngx_http_core_module)
$proxy_protocol_server_port (ngx_stream_core_module)
$proxy_protocol_tlv_ (ngx_http_core_module)
$proxy_protocol_tlv_ (ngx_stream_core_module)
$proxy_protocol_tlv_aws_vpce_id (ngx_http_proxy_protocol_vendor_module)
$proxy_protocol_tlv_aws_vpce_id (ngx_stream_proxy_protocol_vendor_module)
$proxy_protocol_tlv_azure_pel_id (ngx_http_proxy_protocol_vendor_module)
$proxy_protocol_tlv_azure_pel_id (ngx_stream_proxy_protocol_vendor_module)
$proxy_protocol_tlv_gcp_conn_id (ngx_http_proxy_protocol_vendor_module)
$proxy_protocol_tlv_gcp_conn_id (ngx_stream_proxy_protocol_vendor_module)
$query_string
$realip_remote_addr (ngx_http_realip_module)
$realip_remote_addr (ngx_stream_realip_module)
$realip_remote_port (ngx_http_realip_module)
$realip_remote_port (ngx_stream_realip_module)
$realpath_root
$remote_addr (ngx_http_core_module)
$remote_addr (ngx_stream_core_module)
$remote_port (ngx_http_core_module)
$remote_port (ngx_stream_core_module)
$remote_user
$request
$request_body
$request_body_file
$request_completion
$request_filename
$request_id
$request_length (ngx_http_core_module)
$request_length (ngx_http_log_module)
$request_method
$request_port
$request_time (ngx_http_core_module)
$request_time (ngx_http_log_module)
$request_uri
$scheme
$secure_link
$secure_link_expires
$sent_http_
$sent_trailer_
$server_addr (ngx_http_core_module)
$server_addr (ngx_stream_core_module)
$server_name
$server_port (ngx_http_core_module)
$server_port (ngx_stream_core_module)
$server_protocol
$session_log_binary_id
$session_log_id
$session_time
$slice_range
$ssl_alpn_protocol (ngx_http_ssl_module)
$ssl_alpn_protocol (ngx_stream_ssl_module)
$ssl_cipher (ngx_http_ssl_module)
$ssl_cipher (ngx_stream_ssl_module)
$ssl_ciphers (ngx_http_ssl_module)
$ssl_ciphers (ngx_stream_ssl_module)
$ssl_client_cert (ngx_http_ssl_module)
$ssl_client_cert (ngx_stream_ssl_module)
$ssl_client_escaped_cert
$ssl_client_fingerprint (ngx_http_ssl_module)
$ssl_client_fingerprint (ngx_stream_ssl_module)
$ssl_client_i_dn (ngx_http_ssl_module)
$ssl_client_i_dn (ngx_stream_ssl_module)
$ssl_client_i_dn_legacy
$ssl_client_raw_cert (ngx_http_ssl_module)
$ssl_client_raw_cert (ngx_stream_ssl_module)
$ssl_client_s_dn (ngx_http_ssl_module)
$ssl_client_s_dn (ngx_stream_ssl_module)
$ssl_client_s_dn_legacy
$ssl_client_serial (ngx_http_ssl_module)
$ssl_client_serial (ngx_stream_ssl_module)
$ssl_client_sigalg (ngx_http_ssl_module)
$ssl_client_sigalg (ngx_stream_ssl_module)
$ssl_client_v_end (ngx_http_ssl_module)
$ssl_client_v_end (ngx_stream_ssl_module)
$ssl_client_v_remain (ngx_http_ssl_module)
$ssl_client_v_remain (ngx_stream_ssl_module)
$ssl_client_v_start (ngx_http_ssl_module)
$ssl_client_v_start (ngx_stream_ssl_module)
$ssl_client_verify (ngx_http_ssl_module)
$ssl_client_verify (ngx_stream_ssl_module)
$ssl_curve (ngx_http_ssl_module)
$ssl_curve (ngx_stream_ssl_module)
$ssl_curves (ngx_http_ssl_module)
$ssl_curves (ngx_stream_ssl_module)
$ssl_early_data
$ssl_ech_outer_server_name (ngx_http_ssl_module)
$ssl_ech_outer_server_name (ngx_stream_ssl_module)
$ssl_ech_status (ngx_http_ssl_module)
$ssl_ech_status (ngx_stream_ssl_module)
$ssl_preread_alpn_protocols
$ssl_preread_protocol
$ssl_preread_server_name
$ssl_protocol (ngx_http_ssl_module)
$ssl_protocol (ngx_stream_ssl_module)
$ssl_server_name (ngx_http_ssl_module)
$ssl_server_name (ngx_stream_ssl_module)
$ssl_session_id (ngx_http_ssl_module)
$ssl_session_id (ngx_stream_ssl_module)
$ssl_session_reused (ngx_http_ssl_module)
$ssl_session_reused (ngx_stream_ssl_module)
$ssl_sigalg (ngx_http_ssl_module)
$ssl_sigalg (ngx_stream_ssl_module)
$status (ngx_http_core_module)
$status (ngx_http_log_module)
$status (ngx_stream_core_module)
$tcpinfo_rtt
$tcpinfo_rttvar
$tcpinfo_snd_cwnd
$tcpinfo_rcv_space
$time_iso8601 (ngx_http_core_module)
$time_iso8601 (ngx_http_log_module)
$time_iso8601 (ngx_stream_core_module)
$time_iso8601_ms (ngx_http_core_module)
$time_iso8601_ms (ngx_stream_core_module)
$time_local (ngx_http_core_module)
$time_local (ngx_http_log_module)
$time_local (ngx_stream_core_module)
$uid_got
$uid_reset
$uid_set
$upstream_addr (ngx_http_upstream_module)
$upstream_addr (ngx_stream_upstream_module)
$upstream_bytes_received (ngx_http_upstream_module)
$upstream_bytes_received (ngx_stream_upstream_module)
$upstream_bytes_sent (ngx_http_upstream_module)
$upstream_bytes_sent (ngx_stream_upstream_module)
$upstream_cache_status
$upstream_connect_time (ngx_http_upstream_module)
$upstream_connect_time (ngx_stream_upstream_module)
$upstream_cookie_
$upstream_first_byte_time
$upstream_header_time
$upstream_http_
$upstream_last_addr (ngx_http_upstream_module)
$upstream_last_addr (ngx_stream_upstream_module)
$upstream_last_server_name
$upstream_queue_time
$upstream_response_length
$upstream_response_time
$upstream_session_time
$upstream_status
$upstream_trailer_
$uri
\n
\nQ:\nI am trying to open Facebook, Yahoo!, Yandex, Google, or some\nother well known web site and instead I am getting a blank web page\nwith a message referring to nginx: “Welcome to nginx!” or\n“404 Not Found / nginx”.\n
\nI suspect something is wrong and there is probably a malicious attempt\nto direct me to a rogue web page (to break into my computer, do\nphishing etc.). Why is that, and what has nginx to do with my attempts\nto connect to Facebook (Yahoo!, Google, etc.) ?\n
\n \n
\nA:\nFirst of all, the “Welcome to nginx!” page you see is\nNOT our website. At nginx, we write and distribute a free\n\nopen source web server software. A web page saying\n“Welcome to nginx!” is just a diagnostics response that\ncan be produced by any of the websites out there, running nginx\nweb server. Currently, nginx is the 2nd most popular open source\nweb server in the world, it’s being used by over 126,000,000 (or\n14% of the Internet) websites. Most of these websites are\nlegitimate, but some aren’t. Our software was created with a good\nreason of enabling performance and scalability on the Internet,\nit is licensed under \npopular open source license, and has nothing to do with any\nkind of threatening or malicious activity per se —\nnginx is NOT a malware, and it is NOT on your computer. But someone’s\nmalware could have indeed tampered with your computer or router,\nredirecting you to a fraudulent Internet server.\n
\nWe recommend running an anti-virus check on your computer, and\nwe recommend to check and verify your entire system setup with the\nhelp of your ISP, or another support personnel:\n
\n(Disclaimer: at nginx we are not responsible for any negative\nimpact or effects that the actions below might cause. Use the\nfollowing recommendations at your own risk, especially if\nyou aren’t an experienced user of your operating system and/or\nInternet applications. In no event shall nginx be liable for\nany direct, indirect, incidental, special, exemplary, or\nconsequential damages, including, but not limited to loss of\nuse, data, or profits; or business interruption).\n
\n
\n
\nSomething must be wrong with your operating\nsystem settings, home router setup, or browser\nconfiguration, if you are trying to access a well known web site\nand what you get instead is “Welcome to nginx!”.\nThis should NOT happen if your computers and network are\nclean and safe.\n
\nIf changing DNS servers to Google Public DNS, flushing DNS resolver\ncache, fixing your browser configuration, or cleaning \"hosts\" file\n(when applicable) have helped, it might be that there’s a malware\nsomewhere on your PC or around. Find and clean it using\nyour preferred anti-virus and anti-malware tools.\n
\nAdditional articles that might be helpful:\n
\nDCWG.org:\n
\n\nHow can you detect if your computer has been violated and infected\nwith DNS Changer?\n
\n\nHow to clean up or fix malicious software (“malware”)\nassociated with DNS Changer\n
\nMicrosoft:\n
\n\nMalicious Software Removal Tool\n
\n\nHow can I reset the Hosts file back to the default?\n
\n\nHow to reset Internet Protocol (TCP/IP)\n
\nFirefox Help:\n
\n\nDisable or remove Add-ons\n
\nTech-Recipes:\n
\n\nDNS Cache Flush, Clear, or Reset in Vista,\nWindows 7, and Windows 8\n
| Known issues Possible future enhancements |
\nVersion of nginx for Windows uses the native Win32 API (not the Cygwin emulation\nlayer).\nOnly the select() and poll() (1.15.9)\nconnection processing methods are currently used,\nso high performance and scalability should not be expected.\nDue to this and some other known issues version of nginx for Windows\nis considered to be a beta version.\nAt this time, it provides almost the same functionality as a UNIX version\nof nginx except for\nXSLT filter, image filter, GeoIP module, and embedded Perl language.\n
\nTo install nginx/Windows, download\nthe latest mainline version distribution (1.31.0),\nsince the mainline branch of nginx contains all known fixes.\nThen unpack the distribution, go to the\nnginx-1.31.0\ndirectory, and run nginx.\nHere is an example for the drive C: root directory:\n\n
\ncd c:\\\nunzip nginx-1.31.0.zip\ncd nginx-1.31.0\nstart nginx\n
\n\nRun the tasklist command-line utility\nto see nginx processes:\n\n
\nC:\\nginx-1.31.0>tasklist /fi \"imagename eq nginx.exe\"\n\nImage Name PID Session Name Session# Mem Usage\n=============== ======== ============== ========== ============\nnginx.exe 652 Console 0 2 780 K\nnginx.exe 1332 Console 0 3 112 K\n
\n\nOne of the processes is the master process and another is the worker process.\nIf nginx does not start, look for the reason in\nthe error log file logs\\error.log.\nIf the log file has not been created, the reason for this should be reported\nin the Windows Event Log.\nIf an error page is displayed instead of the expected page, also look\nfor the reason in the logs\\error.log file.\n
\nnginx/Windows uses the directory where it has been run as the prefix\nfor relative paths in the configuration.\nIn the example above, the prefix is\nC:\\nginx-1.31.0\\.\nPaths in a configuration file must be specified in UNIX-style using\nforward slashes:\n\n
\naccess_log logs/site.log;\nroot C:/web/html;\n
\n
\nnginx/Windows runs as a standard console application (not a service),\nand it can be managed using the following commands:\n\n
\n\n\n
\n \n\nnginx -s stop \nfast shutdown \n\n \n\nnginx -s quit \ngraceful shutdown \n\n \n\nnginx -s reload \n\nchanging configuration,\nstarting new worker processes with a new configuration,\ngraceful shutdown of old worker processes\n \n\n \n\nnginx -s reopen \nre-opening log files \n
auto — Build scripts\nsrc\n\ncore — Basic types and functions — string, array, log,\npool, etc.\nevent — Event core\n\nmodules — Event notification modules:\nepoll, kqueue, select\netc.\nhttp — Core HTTP module and common code\n\nmodules — Other HTTP modules\nv2 — HTTP/2\nmail — Mail modules\nos — Platform-specific code\n\nunix\nwin32\nstream — Stream modules\n\nThe following two #include statements must appear at the\nbeginning of every nginx file:\n
\n#include <ngx_config.h>\n#include <ngx_core.h>\n
\nIn addition to that, HTTP code should include\n
\n#include <ngx_http.h>\n
\nMail code should include\n
\n#include <ngx_mail.h>\n
\nStream code should include\n
\n#include <ngx_stream.h>\n
\nFor general purposes, nginx code uses two integer types,\nngx_int_t and ngx_uint_t, which are\ntypedefs for intptr_t and uintptr_t\nrespectively.\n
\nMost functions in nginx return the following codes:\n
NGX_OK — Operation succeeded.\nNGX_ERROR — Operation failed.\nNGX_AGAIN — Operation incomplete; call the function again.\nNGX_DECLINED — Operation rejected, for example, because it is\ndisabled in the configuration. This is never an error.\nNGX_BUSY — Resource is not available.\nNGX_DONE — Operation complete or continued elsewhere.\nAlso used as an alternative success code.\nNGX_ABORT — Function was aborted.\nAlso used as an alternative error code.\n\nThe ngx_errno macro returns the last system error code.\nIt's mapped to errno on POSIX platforms and to\nGetLastError() call in Windows.\nThe ngx_socket_errno macro returns the last socket error\nnumber.\nLike the ngx_errno macro, it's mapped to\nerrno on POSIX platforms.\nIt's mapped to the WSAGetLastError() call on Windows.\nAccessing the values of ngx_errno or\nngx_socket_errno more than once in a row can cause\nperformance issues.\nIf the error value might be used multiple times, store it in a local variable\nof type ngx_err_t.\nTo set errors, use the ngx_set_errno(errno) and\nngx_set_socket_errno(errno) macros.\n
\nThe values of ngx_errno and\nngx_socket_errno can be passed to the logging functions\nngx_log_error() and ngx_log_debugX(), in\nwhich case system error text is added to the log message.\n
\nExample using ngx_errno:\n
\nngx_int_t\nngx_my_kill(ngx_pid_t pid, ngx_log_t *log, int signo)\n{\n ngx_err_t err;\n\n if (kill(pid, signo) == -1) {\n err = ngx_errno;\n\n ngx_log_error(NGX_LOG_ALERT, log, err, \"kill(%P, %d) failed\", pid, signo);\n\n if (err == NGX_ESRCH) {\n return 2;\n }\n\n return 1;\n }\n\n return 0;\n}\n\nFor C strings, nginx uses the unsigned character type pointer\nu_char *.\n
\nThe nginx string type ngx_str_t is defined as follows:\n
\ntypedef struct {\n size_t len;\n u_char *data;\n} ngx_str_t;\n\nThe len field holds the string length and\ndata holds the string data.\nThe string, held in ngx_str_t, may or may not be\nnull-terminated after the len bytes.\nIn most cases it’s not.\nHowever, in certain parts of the code (for example, when parsing configuration),\nngx_str_t objects are known to be null-terminated, which\nsimplifies string comparison and makes it easier to pass the strings to\nsyscalls.\n
\nThe string operations in nginx are declared in\nsrc/core/ngx_string.h\nSome of them are wrappers around standard C functions:\n
\n
ngx_strcmp()\nngx_strncmp()\nngx_strstr()\nngx_strlen()\nngx_strchr()\nngx_memcmp()\nngx_memset()\nngx_memcpy()\nngx_memmove()\n\n\n
\nOther string functions are nginx-specific\n
\n
ngx_memzero() — Fills memory with zeroes.\nngx_explicit_memzero() — Does the same as\nngx_memzero(), but this call is never removed by the\ncompiler's dead store elimination optimization.\nThis function can be used to clear sensitive data such as passwords and keys.\nngx_cpymem() — Does the same as\nngx_memcpy(), but returns the final destination address\nThis one is handy for appending multiple strings in a row.\nngx_movemem() — Does the same as\nngx_memmove(), but returns the final destination address.\nngx_strlchr() — Searches for a character in a string,\ndelimited by two pointers.\n\n
\nThe following functions perform case conversion and comparison:\n
\n
ngx_tolower()\nngx_toupper()\nngx_strlow()\nngx_strcasecmp()\nngx_strncasecmp()\n\n
\nThe following macros simplify string initialization:\n
ngx_string(text) — static initializer for the\nngx_str_t type from the C string literal\ntext\nngx_null_string — static empty string initializer for the\nngx_str_t type\nngx_str_set(str, text) — initializes string\nstr of ngx_str_t * type with the C string\nliteral text\nngx_str_null(str) — initializes string str\nof ngx_str_t * type with the empty string\n\nThe following formatting functions support nginx-specific types:\n
\n
ngx_sprintf(buf, fmt, ...)\nngx_snprintf(buf, max, fmt, ...)\nngx_slprintf(buf, last, fmt, ...)\nngx_vslprintf(buf, last, fmt, args)\nngx_vsnprintf(buf, max, fmt, args)\n\n
\nThe full list of formatting options, supported by these functions is\nin src/core/ngx_string.c. Some of them are:\n
%O — off_t\n%T — time_t\n%z — ssize_t\n%i — ngx_int_t\n%p — void *\n%V — ngx_str_t *\n%s — u_char * (null-terminated)\n%*s — size_t + u_char *\n\nYou can prepend u on most types to make them unsigned.\nTo convert output to hex, use X or x.\n
\nFor example:\n\n
\nu_char buf[NGX_INT_T_LEN];\nsize_t len;\nngx_uint_t n;\n\n/* set n here */\n\nlen = ngx_sprintf(buf, \"%ui\", n) — buf;\n
\n\n
\nSeveral functions for numeric conversion are implemented in nginx.\nThe first four each convert a string of given length to a positive integer of\nthe indicated type.\nThey return NGX_ERROR on error.\n\n
ngx_atoi(line, n) — ngx_int_t\nngx_atosz(line, n) — ssize_t\nngx_atoof(line, n) — off_t\nngx_atotm(line, n) — time_t\n\n
\nThere are two additional numeric conversion functions.\nLike the first four, they return NGX_ERROR on error.\n\n
ngx_atofp(line, n, point) — Converts a fixed point floating\nnumber of given length to a positive integer of type\nngx_int_t.\nThe result is shifted left by point decimal\npositions.\nThe string representation of the number is expected to have no more\nthan points fractional digits.\nFor example, ngx_atofp(\"10.5\", 4, 2) returns\n1050.\nngx_hextoi(line, n) — Converts a hexadecimal representation\nof a positive integer to ngx_int_t.\n\n
\nThe regular expressions interface in nginx is a wrapper around\nthe PCRE\nlibrary.\nThe corresponding header file is src/core/ngx_regex.h.\n
\nTo use a regular expression for string matching, it first needs to be\ncompiled, which is usually done at the configuration phase.\nNote that since PCRE support is optional, all code using the interface must\nbe protected by the surrounding NGX_PCRE macro:\n\n
\n#if (NGX_PCRE)\nngx_regex_t *re;\nngx_regex_compile_t rc;\n\nu_char errstr[NGX_MAX_CONF_ERRSTR];\n\nngx_str_t value = ngx_string(\"message (\\\\d\\\\d\\\\d).*Codeword is '(?<cw>\\\\w+)'\");\n\nngx_memzero(&rc, sizeof(ngx_regex_compile_t));\n\nrc.pattern = value;\nrc.pool = cf->pool;\nrc.err.len = NGX_MAX_CONF_ERRSTR;\nrc.err.data = errstr;\n/* rc.options can be set to NGX_REGEX_CASELESS */\n\nif (ngx_regex_compile(&rc) != NGX_OK) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, \"%V\", &rc.err);\n return NGX_CONF_ERROR;\n}\n\nre = rc.regex;\n#endif\n \nAfter successful compilation, the captures and\nnamed_captures fields in the\nngx_regex_compile_t structure contain the count of all\ncaptures and named captures, respectively, found in the regular expression.\n
\nThe compiled regular expression can then be used for matching against strings:\n
\nngx_int_t n;\nint captures[(1 + rc.captures) * 3];\n\nngx_str_t input = ngx_string(\"This is message 123. Codeword is 'foobar'.\");\n\nn = ngx_regex_exec(re, &input, captures, (1 + rc.captures) * 3);\nif (n >= 0) {\n /* string matches expression */\n\n} else if (n == NGX_REGEX_NO_MATCHED) {\n /* no match was found */\n\n} else {\n /* some error */\n ngx_log_error(NGX_LOG_ALERT, log, 0, ngx_regex_exec_n \" failed: %i\", n);\n}\n \nThe arguments to ngx_regex_exec() are the compiled regular\nexpression re, the string to match input,\nan optional array of integers to hold any captures that are\nfound, and the array's size.\nThe size of the captures array must be a multiple of three,\nas required by the\nPCRE API.\nIn the example, the size is calculated from the total number of captures plus\none for the matched string itself.\n
\nIf there are matches, captures can be accessed as follows:\n
\nu_char *p;\nsize_t size;\nngx_str_t name, value;\n\n/* all captures */\nfor (i = 0; i < n * 2; i += 2) {\n value.data = input.data + captures[i];\n value.len = captures[i + 1] — captures[i];\n}\n\n/* accessing named captures */\n\nsize = rc.name_size;\np = rc.names;\n\nfor (i = 0; i < rc.named_captures; i++, p += size) {\n\n /* capture name */\n name.data = &p[2];\n name.len = ngx_strlen(name.data);\n\n n = 2 * ((p[0] << 8) + p[1]);\n\n /* captured value */\n value.data = &input.data[captures[n]];\n value.len = captures[n + 1] — captures[n];\n}\n\n
\nThe ngx_regex_exec_array() function accepts the array of\nngx_regex_elt_t elements (which are just compiled regular\nexpressions with associated names), a string to match, and a log.\nThe function applies expressions from the array to the string until\neither a match is found or no more expressions are left.\nThe return value is NGX_OK when there is a match and\nNGX_DECLINED otherwise, or NGX_ERROR\nin case of error.\n
\nThe ngx_time_t structure represents time with three separate\ntypes for seconds, milliseconds, and the GMT offset:\n
\ntypedef struct {\n time_t sec;\n ngx_uint_t msec;\n ngx_int_t gmtoff;\n} ngx_time_t;\n \nThe ngx_tm_t structure is an alias for\nstruct tm on UNIX platforms and SYSTEMTIME\non Windows.\n
\nTo obtain the current time, it is usually sufficient to access one of the\navailable global variables, representing the cached time value in the desired\nformat.\n
\nThe available string representations are:\n\n
ngx_cached_err_log_time — Used in error log entries:\n\"1970/09/28 12:00:00\"\nngx_cached_http_log_time — Used in HTTP access log entries:\n\"28/Sep/1970:12:00:00 +0600\"\nngx_cached_syslog_time — Used in syslog entries:\n\"Sep 28 12:00:00\"\nngx_cached_http_time — Used in HTTP headers:\n\"Mon, 28 Sep 1970 06:00:00 GMT\"\nngx_cached_http_log_iso8601 — The ISO 8601\nstandard format:\n\"1970-09-28T12:00:00+06:00\"\n\n
\nThe ngx_time() and ngx_timeofday() macros\nreturn the current time value in seconds and are the preferred way to access\nthe cached time value.\n
\nTo obtain the time explicitly, use ngx_gettimeofday(),\nwhich updates its argument (pointer to\nstruct timeval).\nThe time is always updated when nginx returns to the event loop from system\ncalls.\nTo update the time immediately, call ngx_time_update(),\nor ngx_time_sigsafe_update() if updating the time in the\nsignal handler context.\n
\nThe following functions convert time_t into the indicated\nbroken-down time representation.\nThe first function in each pair converts time_t to\nngx_tm_t and the second (with the _libc_\ninfix) to struct tm:\n\n
ngx_gmtime(), ngx_libc_gmtime() — Time expressed as UTC\nngx_localtime(), ngx_libc_localtime() — Time expressed\nrelative to the local time zone\n \n\nThe ngx_http_time(buf, time) function returns a string\nrepresentation suitable for use in HTTP headers (for example,\n\"Mon, 28 Sep 1970 06:00:00 GMT\").\nThe ngx_http_cookie_time(buf, time) returns a string\nrepresentation function returns a string representation suitable\nfor HTTP cookies (\"Thu, 31-Dec-37 23:55:55 GMT\").\n
\nThe nginx array type ngx_array_t is defined as follows\n
\ntypedef struct {\n void *elts;\n ngx_uint_t nelts;\n size_t size;\n ngx_uint_t nalloc;\n ngx_pool_t *pool;\n} ngx_array_t;\n\nThe elements of the array are available in the elts field.\nThe nelts field holds the number of elements.\nThe size field holds the size of a single element and is set\nwhen the array is initialized.\n
\nUse the ngx_array_create(pool, n, size) call to create an\narray in a pool, and the ngx_array_init(array, pool, n, size)\ncall to initialize an array object that has already been allocated.\n
\nngx_array_t *a, b;\n\n/* create an array of strings with preallocated memory for 10 elements */\na = ngx_array_create(pool, 10, sizeof(ngx_str_t));\n\n/* initialize string array for 10 elements */\nngx_array_init(&b, pool, 10, sizeof(ngx_str_t));\n
\nUse the following functions to add elements to an array:\n
\n
ngx_array_push(a) adds one tail element and returns pointer\nto it\nngx_array_push_n(a, n) adds n tail elements\nand returns pointer to the first one\n\n
\nIf the currently allocated amount of memory is not large enough to accommodate\nthe new elements, a new block of memory is allocated and the existing elements\nare copied to it.\nThe new memory block is normally twice as large as the existing one.\n
\ns = ngx_array_push(a);\nss = ngx_array_push_n(&b, 3);\n
\nIn nginx a list is a sequence of arrays, optimized for inserting a potentially\nlarge number of items.\nThe ngx_list_t list type is defined as follows:\n
\ntypedef struct {\n ngx_list_part_t *last;\n ngx_list_part_t part;\n size_t size;\n ngx_uint_t nalloc;\n ngx_pool_t *pool;\n} ngx_list_t;\n\nThe actual items are stored in list parts, which are defined as follows:\n
\ntypedef struct ngx_list_part_s ngx_list_part_t;\n\nstruct ngx_list_part_s {\n void *elts;\n ngx_uint_t nelts;\n ngx_list_part_t *next;\n};\n\nBefore use, a list must be initialized by calling\nngx_list_init(list, pool, n, size) or created by calling\nngx_list_create(pool, n, size).\nBoth functions take as arguments the size of a single item and a number of\nitems per list part.\nTo add an item to a list, use the ngx_list_push(list)\nfunction.\nTo iterate over the items, directly access the list fields as shown in the\nexample:\n
\nngx_str_t *v;\nngx_uint_t i;\nngx_list_t *list;\nngx_list_part_t *part;\n\nlist = ngx_list_create(pool, 100, sizeof(ngx_str_t));\nif (list == NULL) { /* error */ }\n\n/* add items to the list */\n\nv = ngx_list_push(list);\nif (v == NULL) { /* error */ }\nngx_str_set(v, \"foo\");\n\nv = ngx_list_push(list);\nif (v == NULL) { /* error */ }\nngx_str_set(v, \"bar\");\n\n/* iterate over the list */\n\npart = &list->part;\nv = part->elts;\n\nfor (i = 0; /* void */; i++) {\n\n if (i >= part->nelts) {\n if (part->next == NULL) {\n break;\n }\n\n part = part->next;\n v = part->elts;\n i = 0;\n }\n\n ngx_do_smth(&v[i]);\n}\n\nLists are primarily used for HTTP input and output headers.\n
\nLists do not support item removal.\nHowever, when needed, items can internally be marked as missing without actually\nbeing removed from the list.\nFor example, to mark HTTP output headers (which are stored as\nngx_table_elt_t objects) as missing, set the\nhash field in ngx_table_elt_t to\nzero.\nItems marked in this way are explicitly skipped when the headers are iterated\nover.\n
\nIn nginx a queue is an intrusive doubly linked list, with each node defined as\nfollows:\n
\ntypedef struct ngx_queue_s ngx_queue_t;\n\nstruct ngx_queue_s {\n ngx_queue_t *prev;\n ngx_queue_t *next;\n};\n\nThe head queue node is not linked with any data.\nUse the ngx_queue_init(q) call to initialize the list head\nbefore use.\nQueues support the following operations:\n
\n
ngx_queue_insert_head(h, x),\nngx_queue_insert_tail(h, x) — Insert a new node\nngx_queue_remove(x) — Remove a queue node\nngx_queue_split(h, q, n) — Split a queue at a node,\nreturning the queue tail in a separate queue\nngx_queue_add(h, n) — Add a second queue to the first queue\nngx_queue_head(h),\nngx_queue_last(h) — Get first or last queue node\nngx_queue_sentinel(h) - Get a queue sentinel object to end\niteration at\nngx_queue_data(q, type, link) — Get a reference to the\nbeginning of a queue node data structure, considering the queue field offset in\nit\n\n
\nAn example:\n
\ntypedef struct {\n ngx_str_t value;\n ngx_queue_t queue;\n} ngx_foo_t;\n\nngx_foo_t *f;\nngx_queue_t values, *q;\n\nngx_queue_init(&values);\n\nf = ngx_palloc(pool, sizeof(ngx_foo_t));\nif (f == NULL) { /* error */ }\nngx_str_set(&f->value, \"foo\");\n\nngx_queue_insert_tail(&values, &f->queue);\n\n/* insert more nodes here */\n\nfor (q = ngx_queue_head(&values);\n q != ngx_queue_sentinel(&values);\n q = ngx_queue_next(q))\n{\n f = ngx_queue_data(q, ngx_foo_t, queue);\n\n ngx_do_smth(&f->value);\n}\n\nThe src/core/ngx_rbtree.h header file provides access to the\neffective implementation of red-black trees.\n
\ntypedef struct {\n ngx_rbtree_t rbtree;\n ngx_rbtree_node_t sentinel;\n\n /* custom per-tree data here */\n} my_tree_t;\n\ntypedef struct {\n ngx_rbtree_node_t rbnode;\n\n /* custom per-node data */\n foo_t val;\n} my_node_t;\n\nTo deal with a tree as a whole, you need two nodes: root and sentinel.\nTypically, they are added to a custom structure, allowing you to\norganize your data into a tree in which the leaves contain a link to or embed\nyour data.\n
\nTo initialize a tree:\n
\nmy_tree_t root;\n\nngx_rbtree_init(&root.rbtree, &root.sentinel, insert_value_function);\n
\nTo traverse a tree and insert new values, use the\n\"insert_value\" functions.\nFor example, the ngx_str_rbtree_insert_value function deals\nwith the ngx_str_t type.\nIts arguments are pointers to a root node of an insertion, the newly created\nnode to be added, and a tree sentinel.\n
\nvoid ngx_str_rbtree_insert_value(ngx_rbtree_node_t *temp,\n ngx_rbtree_node_t *node,\n ngx_rbtree_node_t *sentinel)\n
\nThe traversal is pretty straightforward and can be demonstrated with the\nfollowing lookup function pattern:\n
\nmy_node_t *\nmy_rbtree_lookup(ngx_rbtree_t *rbtree, foo_t *val, uint32_t hash)\n{\n ngx_int_t rc;\n my_node_t *n;\n ngx_rbtree_node_t *node, *sentinel;\n\n node = rbtree->root;\n sentinel = rbtree->sentinel;\n\n while (node != sentinel) {\n\n n = (my_node_t *) node;\n\n if (hash != node->key) {\n node = (hash < node->key) ? node->left : node->right;\n continue;\n }\n\n rc = compare(val, node->val);\n\n if (rc < 0) {\n node = node->left;\n continue;\n }\n\n if (rc > 0) {\n node = node->right;\n continue;\n }\n\n return n;\n }\n\n return NULL;\n}\n\nThe compare() function is a classic comparator function that\nreturns a value less than, equal to, or greater than zero.\nTo speed up lookups and avoid comparing user objects that can be big, an integer\nhash field is used.\n
\nTo add a node to a tree, allocate a new node, initialize it and call\nngx_rbtree_insert():\n
\n my_node_t *my_node;\n ngx_rbtree_node_t *node;\n\n my_node = ngx_palloc(...);\n init_custom_data(&my_node->val);\n\n node = &my_node->rbnode;\n node->key = create_key(my_node->val);\n\n ngx_rbtree_insert(&root->rbtree, node);\n
\nTo remove a node, call the ngx_rbtree_delete() function:\n
\nngx_rbtree_delete(&root->rbtree, node);\n
\nHash table functions are declared in src/core/ngx_hash.h.\nBoth exact and wildcard matching are supported.\nThe latter requires extra setup and is described in a separate section below.\n
\nBefore initializing a hash, you need to know the number of elements it will\nhold so that nginx can build it optimally.\nTwo parameters that need to be configured are max_size\nand bucket_size, as detailed in a separate\ndocument.\nThey are usually configurable by the user.\nHash initialization settings are stored with the\nngx_hash_init_t type, and the hash itself is\nngx_hash_t:\n
\nngx_hash_t foo_hash;\nngx_hash_init_t hash;\n\nhash.hash = &foo_hash;\nhash.key = ngx_hash_key;\nhash.max_size = 512;\nhash.bucket_size = ngx_align(64, ngx_cacheline_size);\nhash.name = \"foo_hash\";\nhash.pool = cf->pool;\nhash.temp_pool = cf->temp_pool;\n
\nThe key is a pointer to a function that creates the hash\ninteger key from a string.\nThere are two generic key-creation functions:\nngx_hash_key(data, len) and\nngx_hash_key_lc(data, len).\nThe latter converts a string to all lowercase characters, so the passed string\nmust be writable.\nIf that is not true, pass the NGX_HASH_READONLY_KEY flag\nto the function, initializing the key array (see below).\n
\nThe hash keys are stored in ngx_hash_keys_arrays_t and\nare initialized with ngx_hash_keys_array_init(arr, type):\nThe second parameter (type) controls the amount of resources\npreallocated for the hash and can be either NGX_HASH_SMALL or\nNGX_HASH_LARGE.\nThe latter is appropriate if you expect the hash to contain thousands of\nelements.\n\n
\nngx_hash_keys_arrays_t foo_keys;\n\nfoo_keys.pool = cf->pool;\nfoo_keys.temp_pool = cf->temp_pool;\n\nngx_hash_keys_array_init(&foo_keys, NGX_HASH_SMALL);\n
\n
\nTo insert keys into a hash keys array, use the\nngx_hash_add_key(keys_array, key, value, flags) function:\n
\nngx_str_t k1 = ngx_string(\"key1\");\nngx_str_t k2 = ngx_string(\"key2\");\n\nngx_hash_add_key(&foo_keys, &k1, &my_data_ptr_1, NGX_HASH_READONLY_KEY);\nngx_hash_add_key(&foo_keys, &k2, &my_data_ptr_2, NGX_HASH_READONLY_KEY);\n
\n
\nTo build the hash table, call the\nngx_hash_init(hinit, key_names, nelts) function:\n\n
\nngx_hash_init(&hash, foo_keys.keys.elts, foo_keys.keys.nelts);\n
\n\nThe function fails if max_size or\nbucket_size parameters are not big enough.\n
\nWhen the hash is built, use the\nngx_hash_find(hash, key, name, len) function to look up\nelements:\n
\nmy_data_t *data;\nngx_uint_t key;\n\nkey = ngx_hash_key(k1.data, k1.len);\n\ndata = ngx_hash_find(&foo_hash, key, k1.data, k1.len);\nif (data == NULL) {\n /* key not found */\n}\n\n\n
\nTo create a hash that works with wildcards, use the\nngx_hash_combined_t type.\nIt includes the hash type described above and has two additional keys arrays:\ndns_wc_head and dns_wc_tail.\nThe initialization of basic properties is similar to a regular hash:\n
\nngx_hash_init_t hash\nngx_hash_combined_t foo_hash;\n\nhash.hash = &foo_hash.hash;\nhash.key = ...;\n
\n
\nIt is possible to add wildcard keys using the\nNGX_HASH_WILDCARD_KEY flag:\n
\n/* k1 = \".example.org\"; */\n/* k2 = \"foo.*\"; */\nngx_hash_add_key(&foo_keys, &k1, &data1, NGX_HASH_WILDCARD_KEY);\nngx_hash_add_key(&foo_keys, &k2, &data2, NGX_HASH_WILDCARD_KEY);\n
\nThe function recognizes wildcards and adds keys into the corresponding arrays.\nPlease refer to the\nmap module\ndocumentation for the description of the wildcard syntax and the\nmatching algorithm.\n
\nDepending on the contents of added keys, you may need to initialize up to three\nkey arrays: one for exact matching (described above), and two more to enable\nmatching starting from the head or tail of a string:\n
\nif (foo_keys.dns_wc_head.nelts) {\n\n ngx_qsort(foo_keys.dns_wc_head.elts,\n (size_t) foo_keys.dns_wc_head.nelts,\n sizeof(ngx_hash_key_t),\n cmp_dns_wildcards);\n\n hash.hash = NULL;\n hash.temp_pool = pool;\n\n if (ngx_hash_wildcard_init(&hash, foo_keys.dns_wc_head.elts,\n foo_keys.dns_wc_head.nelts)\n != NGX_OK)\n {\n return NGX_ERROR;\n }\n\n foo_hash.wc_head = (ngx_hash_wildcard_t *) hash.hash;\n}\n \nThe keys array needs to be sorted, and initialization results must be added\nto the combined hash.\nThe initialization of dns_wc_tail array is done similarly.\n
\nThe lookup in a combined hash is handled by the\nngx_hash_find_combined(chash, key, name, len):\n
\n/* key = \"bar.example.org\"; — will match \".example.org\" */\n/* key = \"foo.example.com\"; — will match \"foo.*\" */\n\nhkey = ngx_hash_key(key.data, key.len);\nres = ngx_hash_find_combined(&foo_hash, hkey, key.data, key.len);\n
\n
\nTo allocate memory from system heap, use the following functions:\n
\n
ngx_alloc(size, log) — Allocate memory from system heap.\nThis is a wrapper around malloc() with logging support.\nAllocation error and debugging information is logged to log.\nngx_calloc(size, log) — Allocate memory from system heap\nlike ngx_alloc(), but fill memory with zeros after\nallocation.\nngx_memalign(alignment, size, log) — Allocate aligned memory\nfrom system heap.\nThis is a wrapper around posix_memalign()\non those platforms that provide that function.\nOtherwise implementation falls back to ngx_alloc() which\nprovides maximum alignment.\nngx_free(p) — Free allocated memory.\nThis is a wrapper around free()\n\n
\nMost nginx allocations are done in pools.\nMemory allocated in an nginx pool is freed automatically when the pool is\ndestroyed.\nThis provides good allocation performance and makes memory control easy.\n
\nA pool internally allocates objects in continuous blocks of memory.\nOnce a block is full, a new one is allocated and added to the pool memory\nblock list.\nWhen the requested allocation is too large to fit into a block, the request\nis forwarded to the system allocator and the\nreturned pointer is stored in the pool for further deallocation.\n
\nThe type for nginx pools is ngx_pool_t.\nThe following operations are supported:\n
\n
ngx_create_pool(size, log) — Create a pool with specified\nblock size.\nThe pool object returned is allocated in the pool as well.\nThe size\nshould be at least NGX_MIN_POOL_SIZE\nand a multiple of NGX_POOL_ALIGNMENT.\nngx_destroy_pool(pool) — Free all pool memory, including\nthe pool object itself.\nngx_palloc(pool, size) — Allocate aligned memory from the\nspecified pool.\nngx_pcalloc(pool, size) — Allocate aligned memory\nfrom the specified pool and fill it with zeroes.\nngx_pnalloc(pool, size) — Allocate unaligned memory from the\nspecified pool.\nMostly used for allocating strings.\nngx_pfree(pool, p) — Free memory that was previously\nallocated in the specified pool.\nOnly allocations that result from requests forwarded to the system allocator\ncan be freed.\n\n
\nu_char *p;\nngx_str_t *s;\nngx_pool_t *pool;\n\npool = ngx_create_pool(1024, log);\nif (pool == NULL) { /* error */ }\n\ns = ngx_palloc(pool, sizeof(ngx_str_t));\nif (s == NULL) { /* error */ }\nngx_str_set(s, \"foo\");\n\np = ngx_pnalloc(pool, 3);\nif (p == NULL) { /* error */ }\nngx_memcpy(p, \"foo\", 3);\n\nChain links (ngx_chain_t) are actively used in nginx,\nso the nginx pool implementation provides a way to reuse them.\nThe chain field of ngx_pool_t keeps a\nlist of previously allocated links ready for reuse.\nFor efficient allocation of a chain link in a pool, use the\nngx_alloc_chain_link(pool) function.\nThis function looks up a free chain link in the pool list and allocates a new\nchain link if the pool list is empty.\nTo free a link, call the ngx_free_chain(pool, cl) function.\n
\nCleanup handlers can be registered in a pool.\nA cleanup handler is a callback with an argument which is called when pool is\ndestroyed.\nA pool is usually tied to a specific nginx object (like an HTTP request) and is\ndestroyed when the object reaches the end of its lifetime.\nRegistering a pool cleanup is a convenient way to release resources, close\nfile descriptors or make final adjustments to the shared data associated with\nthe main object.\n
\nTo register a pool cleanup, call\nngx_pool_cleanup_add(pool, size), which returns a\nngx_pool_cleanup_t pointer to\nbe filled in by the caller.\nUse the size argument to allocate context for the cleanup\nhandler.\n
\nngx_pool_cleanup_t *cln;\n\ncln = ngx_pool_cleanup_add(pool, 0);\nif (cln == NULL) { /* error */ }\n\ncln->handler = ngx_my_cleanup;\ncln->data = \"foo\";\n\n...\n\nstatic void\nngx_my_cleanup(void *data)\n{\n u_char *msg = data;\n\n ngx_do_smth(msg);\n}\n\nShared memory is used by nginx to share common data between processes.\nThe ngx_shared_memory_add(cf, name, size, tag) function adds\na new shared memory entry ngx_shm_zone_t to a cycle.\nThe function receives the name and size\nof the zone.\nEach shared zone must have a unique name.\nIf a shared zone entry with the provided name and\ntag already exists, the existing zone entry is reused.\nThe function fails with an error if an existing entry with the same name has a\ndifferent tag.\nUsually, the address of the module structure is passed as\ntag, making it possible to reuse shared zones by name within\none nginx module.\n
\nThe shared memory entry structure ngx_shm_zone_t has the\nfollowing fields:\n
\n
init — Initialization callback, called after the shared zone\nis mapped to actual memory\ndata — Data context, used to pass arbitrary data to the\ninit callback\nnoreuse — Flag that disables reuse of a shared zone from the\nold cycle\ntag — Shared zone tag\nshm — Platform-specific object of type\nngx_shm_t, having at least the following fields:\naddr — Mapped shared memory address, initially NULL\nsize — Shared memory size\nname — Shared memory name\nlog — Shared memory log\nexists — Flag that indicates shared memory was inherited\nfrom the master process (Windows-specific)\n\n
\nShared zone entries are mapped to actual memory in\nngx_init_cycle() after the configuration is parsed.\nOn POSIX systems, the mmap() syscall is used to create the\nshared anonymous mapping.\nOn Windows, the CreateFileMapping()/\nMapViewOfFileEx() pair is used.\n
\nFor allocating in shared memory, nginx provides the slab pool\nngx_slab_pool_t type.\nA slab pool for allocating memory is automatically created in each nginx shared\nzone.\nThe pool is located in the beginning of the shared zone and can be accessed by\nthe expression (ngx_slab_pool_t *) shm_zone->shm.addr.\nTo allocate memory in a shared zone, call either\nngx_slab_alloc(pool, size) or\nngx_slab_calloc(pool, size).\nTo free memory, call ngx_slab_free(pool, p).\n
\nSlab pool divides all shared zone into pages.\nEach page is used for allocating objects of the same size.\nThe specified size must be a power of 2, and greater than the minimum size of\n8 bytes.\nNonconforming values are rounded up.\nA bitmask for each page tracks which blocks are in use and which are free for\nallocation.\nFor sizes greater than a half page (which is usually 2048 bytes), allocation is\ndone an entire page at a time\n
\nTo protect data in shared memory from concurrent access, use the mutex\navailable in the mutex field of\nngx_slab_pool_t.\nA mutex is most commonly used by the slab pool while allocating and freeing\nmemory, but it can be used to protect any other user data structures allocated\nin the shared zone.\nTo lock or unlock a mutex, call\nngx_shmtx_lock(&shpool->mutex) or\nngx_shmtx_unlock(&shpool->mutex) respectively.\n
\nngx_str_t name;\nngx_foo_ctx_t *ctx;\nngx_shm_zone_t *shm_zone;\n\nngx_str_set(&name, \"foo\");\n\n/* allocate shared zone context */\nctx = ngx_pcalloc(cf->pool, sizeof(ngx_foo_ctx_t));\nif (ctx == NULL) {\n /* error */\n}\n\n/* add an entry for 64k shared zone */\nshm_zone = ngx_shared_memory_add(cf, &name, 65536, &ngx_foo_module);\nif (shm_zone == NULL) {\n /* error */\n}\n\n/* register init callback and context */\nshm_zone->init = ngx_foo_init_zone;\nshm_zone->data = ctx;\n\n\n...\n\n\nstatic ngx_int_t\nngx_foo_init_zone(ngx_shm_zone_t *shm_zone, void *data)\n{\n ngx_foo_ctx_t *octx = data;\n\n size_t len;\n ngx_foo_ctx_t *ctx;\n ngx_slab_pool_t *shpool;\n\n value = shm_zone->data;\n\n if (octx) {\n /* reusing a shared zone from old cycle */\n ctx->value = octx->value;\n return NGX_OK;\n }\n\n shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;\n\n if (shm_zone->shm.exists) {\n /* initialize shared zone context in Windows nginx worker */\n ctx->value = shpool->data;\n return NGX_OK;\n }\n\n /* initialize shared zone */\n\n ctx->value = ngx_slab_alloc(shpool, sizeof(ngx_uint_t));\n if (ctx->value == NULL) {\n return NGX_ERROR;\n }\n\n shpool->data = ctx->value;\n\n return NGX_OK;\n}\n\nFor logging nginx uses ngx_log_t objects.\nThe nginx logger supports several types of output:\n\n
\n
\nA logger instance can be a chain of loggers, linked to each other with\nthe next field.\nIn this case, each message is written to all loggers in the chain.\n
\nFor each logger, a severity level controls which messages are written to the\nlog (only events assigned that level or higher are logged).\nThe following severity levels are supported:\n
\n
NGX_LOG_EMERG\nNGX_LOG_ALERT\nNGX_LOG_CRIT\nNGX_LOG_ERR\nNGX_LOG_WARN\nNGX_LOG_NOTICE\nNGX_LOG_INFO\nNGX_LOG_DEBUG\n\n
\nFor debug logging, the debug mask is checked as well.\nThe debug masks are:\n
\n
NGX_LOG_DEBUG_CORE\nNGX_LOG_DEBUG_ALLOC\nNGX_LOG_DEBUG_MUTEX\nNGX_LOG_DEBUG_EVENT\nNGX_LOG_DEBUG_HTTP\nNGX_LOG_DEBUG_MAIL\nNGX_LOG_DEBUG_STREAM\n\n
\nNormally, loggers are created by existing nginx code from\nerror_log directives and are available at nearly every stage\nof processing in cycle, configuration, client connection and other objects.\n
\nNginx provides the following logging macros:\n
\n
ngx_log_error(level, log, err, fmt, ...) — Error logging\nngx_log_debug0(level, log, err, fmt),\nngx_log_debug1(level, log, err, fmt, arg1) etc — Debug\nlogging with up to eight supported formatting arguments\n\n
\nA log message is formatted in a buffer of size\nNGX_MAX_ERROR_STR (currently, 2048 bytes) on stack.\nThe message is prepended with the severity level, process ID (PID), connection\nID (stored in log->connection), and the system error text.\nFor non-debug messages log->handler is called as well to\nprepend more specific information to the log message.\nHTTP module sets ngx_http_log_error() function as log\nhandler to log client and server addresses, current action (stored in\nlog->action), client request line, server name etc.\n
\n/* specify what is currently done */\nlog->action = \"sending mp4 to client\";\n\n/* error and debug log */\nngx_log_error(NGX_LOG_INFO, c->log, 0, \"client prematurely\n closed connection\");\n\nngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,\n \"mp4 start:%ui, length:%ui\", mp4->start, mp4->length);\n
\nThe example above results in log entries like these:\n
\n2016/09/16 22:08:52 [info] 17445#0: *1 client prematurely closed connection while\nsending mp4 to client, client: 127.0.0.1, server: , request: \"GET /file.mp4 HTTP/1.1\"\n2016/09/16 23:28:33 [debug] 22140#0: *1 mp4 start:0, length:10000\n
\nA cycle object stores the nginx runtime context created from a specific\nconfiguration.\nIts type is ngx_cycle_t.\nThe current cycle is referenced by the ngx_cycle global\nvariable and inherited by nginx workers as they start.\nEach time the nginx configuration is reloaded, a new cycle is created from the\nnew nginx configuration; the old cycle is usually deleted after the new one is\nsuccessfully created.\n
\nA cycle is created by the ngx_init_cycle() function, which\ntakes the previous cycle as its argument.\nThe function locates the previous cycle's configuration file and inherits as\nmany resources as possible from the previous cycle.\nA placeholder cycle called \"init cycle\" is created as nginx start, then is\nreplaced by an actual cycle built from configuration.\n
\nMembers of the cycle include:\n
\n
pool — Cycle pool.\nCreated for each new cycle.\nlog — Cycle log.\nInitially inherited from the old cycle, it is set to point to\nnew_log after the configuration is read.\nnew_log — Cycle log, created by the configuration.\nIt's affected by the root-scope error_log directive.\nconnections, connection_n —\nArray of connections of type ngx_connection_t, created by\nthe event module while initializing each nginx worker.\nThe worker_connections directive in the nginx configuration\nsets the number of connections connection_n.\nfree_connections,\nfree_connection_n — List and number of currently available\nconnections.\nIf no connections are available, an nginx worker refuses to accept new clients\nor connect to upstream servers.\nfiles, files_n — Array for mapping file\ndescriptors to nginx connections.\nThis mapping is used by the event modules, having the\nNGX_USE_FD_EVENT flag (currently, it's\npoll and devpoll).\nconf_ctx — Array of core module configurations.\nThe configurations are created and filled during reading of nginx configuration\nfiles.\nmodules, modules_n — Array of modules\nof type ngx_module_t, both static and dynamic, loaded by\nthe current configuration.\nlistening — Array of listening objects of type\nngx_listening_t.\nListening objects are normally added by the listen\ndirective of different modules which call the\nngx_create_listening() function.\nListen sockets are created based on the listening objects.\npaths — Array of paths of type ngx_path_t.\nPaths are added by calling the function ngx_add_path() from\nmodules which are going to operate on certain directories.\nThese directories are created by nginx after reading configuration, if missing.\nMoreover, two handlers can be added for each path:\n\nopen_files — List of open file objects of type\nngx_open_file_t, which are created by calling the function\nngx_conf_open_file().\nCurrently, nginx uses this kind of open files for logging.\nAfter reading the configuration, nginx opens all files in the\nopen_files list and stores each file descriptor in the\nobject's fd field.\nThe files are opened in append mode and are created if missing.\nThe files in the list are reopened by nginx workers upon receiving the\nreopen signal (most often USR1).\nIn this case the descriptor in the fd field is changed to a\nnew value.\nshared_memory — List of shared memory zones, each added by\ncalling the ngx_shared_memory_add() function.\nShared zones are mapped to the same address range in all nginx processes and\nare used to share common data, for example the HTTP cache in-memory tree.\n\n
\nFor input/output operations, nginx provides the buffer type\nngx_buf_t.\nNormally, it's used to hold data to be written to a destination or read from a\nsource.\nA buffer can reference data in memory or in a file and it's technically\npossible for a buffer to reference both at the same time.\nMemory for the buffer is allocated separately and is not related to the buffer\nstructure ngx_buf_t.\n
\nThe ngx_buf_t structure has the following fields:\n
\n
start, end — The boundaries of the memory\nblock allocated for the buffer.\npos, last — The boundaries of the memory\nbuffer; normally a subrange of start ..\nend.\nfile_pos, file_last — The boundaries of a\nfile buffer, expressed as offsets from the beginning of the file.\ntag — Unique value used to distinguish buffers; created by\ndifferent nginx modules, usually for the purpose of buffer reuse.\nfile — File object.\ntemporary — Flag indicating that the buffer references\nwritable memory.\nmemory — Flag indicating that the buffer references read-only\nmemory.\nin_file — Flag indicating that the buffer references data\nin a file.\nflush — Flag indicating that all data prior to the buffer\nneed to be flushed.\nrecycled — Flag indicating that the buffer can be reused and\nneeds to be consumed as soon as possible.\nsync — Flag indicating that the buffer carries no data or\nspecial signal like flush or last_buf.\nBy default nginx considers such buffers an error condition, but this flag tells\nnginx to skip the error check.\nlast_buf — Flag indicating that the buffer is the last in\noutput.\nlast_in_chain — Flag indicating that there are no more data\nbuffers in a request or subrequest.\nshadow — Reference to another (\"shadow\") buffer related to\nthe current buffer, usually in the sense that the buffer uses data from the\nshadow.\nWhen the buffer is consumed, the shadow buffer is normally also marked as\nconsumed.\nlast_shadow — Flag indicating that the buffer is the last\none that references a particular shadow buffer.\ntemp_file — Flag indicating that the buffer is in a temporary\nfile.\n\n
\nFor input and output operations buffers are linked in chains.\nA chain is a sequence of chain links of type ngx_chain_t,\ndefined as follows:\n
\ntypedef struct ngx_chain_s ngx_chain_t;\n\nstruct ngx_chain_s {\n ngx_buf_t *buf;\n ngx_chain_t *next;\n};\n\nEach chain link keeps a reference to its buffer and a reference to the next\nchain link.\n
\nAn example of using buffers and chains:\n
\nngx_chain_t *\nngx_get_my_chain(ngx_pool_t *pool)\n{\n ngx_buf_t *b;\n ngx_chain_t *out, *cl, **ll;\n\n /* first buf */\n cl = ngx_alloc_chain_link(pool);\n if (cl == NULL) { /* error */ }\n\n b = ngx_calloc_buf(pool);\n if (b == NULL) { /* error */ }\n\n b->start = (u_char *) \"foo\";\n b->pos = b->start;\n b->end = b->start + 3;\n b->last = b->end;\n b->memory = 1; /* read-only memory */\n\n cl->buf = b;\n out = cl;\n ll = &cl->next;\n\n /* second buf */\n cl = ngx_alloc_chain_link(pool);\n if (cl == NULL) { /* error */ }\n\n b = ngx_create_temp_buf(pool, 3);\n if (b == NULL) { /* error */ }\n\n b->last = ngx_cpymem(b->last, \"foo\", 3);\n\n cl->buf = b;\n cl->next = NULL;\n *ll = cl;\n\n return out;\n}\n\nThe connection type ngx_connection_t is a wrapper around a\nsocket descriptor.\nIt includes the following fields:\n
\n
fd — Socket descriptor\ndata — Arbitrary connection context.\nNormally, it is a pointer to a higher-level object built on top of the\nconnection, such as an HTTP request or a Stream session.\nread, write — Read and write events for\nthe connection.\nrecv, send,\nrecv_chain, send_chain — I/O operations\nfor the connection.\npool — Connection pool.\nlog — Connection log.\nsockaddr, socklen,\naddr_text — Remote socket address in binary and text forms.\nlocal_sockaddr, local_socklen — Local\nsocket address in binary form.\nInitially, these fields are empty.\nUse the ngx_connection_local_sockaddr() function to get the\nlocal socket address.\nproxy_protocol_addr, proxy_protocol_port\n- PROXY protocol client address and port, if the PROXY protocol is enabled for\nthe connection.\nssl — SSL context for the connection.\nreusable — Flag indicating the connection is in a state that\nmakes it eligible for reuse.\nclose — Flag indicating that the connection is being reused\nand needs to be closed.\n\n
\nAn nginx connection can transparently encapsulate the SSL layer.\nIn this case the connection's ssl field holds a pointer to an\nngx_ssl_connection_t structure, keeping all SSL-related data\nfor the connection, including SSL_CTX and\nSSL.\nThe recv, send,\nrecv_chain, and send_chain handlers are\nset to SSL-enabled functions as well.\n
\nThe worker_connections directive in the nginx configuration\nlimits the number of connections per nginx worker.\nAll connection structures are precreated when a worker starts and stored in\nthe connections field of the cycle object.\nTo retrieve a connection structure, use the\nngx_get_connection(s, log) function.\nIt takes as its s argument a socket descriptor, which needs\nto be wrapped in a connection structure.\n
\nBecause the number of connections per worker is limited, nginx provides a\nway to grab connections that are currently in use.\nTo enable or disable reuse of a connection, call the\nngx_reusable_connection(c, reusable) function.\nCalling ngx_reusable_connection(c, 1) sets the\nreuse flag in the connection structure and inserts the\nconnection into the reusable_connections_queue of the cycle.\nWhenever ngx_get_connection() finds out there are no\navailable connections in the cycle's free_connections list,\nit calls ngx_drain_connections() to release a\nspecific number of reusable connections.\nFor each such connection, the close flag is set and its read\nhandler is called which is supposed to free the connection by calling\nngx_close_connection(c) and make it available for reuse.\nTo exit the state when a connection can be reused\nngx_reusable_connection(c, 0) is called.\nHTTP client connections are an example of reusable connections in nginx; they\nare marked as reusable until the first request byte is received from the client.\n
\nEvent object ngx_event_t in nginx provides a mechanism\nfor notification that a specific event has occurred.\n
\nFields in ngx_event_t include:\n
\n
data — Arbitrary event context used in event handlers,\nusually as pointer to a connection related to the event.\nhandler — Callback function to be invoked when the event\nhappens.\nwrite — Flag indicating a write event.\nAbsence of the flag indicates a read event.\nactive — Flag indicating that the event is registered for\nreceiving I/O notifications, normally from notification mechanisms like\nepoll, kqueue, poll.\nready — Flag indicating that the event has received an\nI/O notification.\ndelayed — Flag indicating that I/O is delayed due to rate\nlimiting.\ntimer — Red-black tree node for inserting the event into\nthe timer tree.\ntimer_set — Flag indicating that the event timer is set and\nnot yet expired.\ntimedout — Flag indicating that the event timer has expired.\neof — Flag indicating that EOF occurred while reading data.\npending_eof — Flag indicating that EOF is pending on the\nsocket, even though there may be some data available before it.\nThe flag is delivered via the EPOLLRDHUP\nepoll event or\nEV_EOF kqueue flag.\nerror — Flag indicating that an error occurred during\nreading (for a read event) or writing (for a write event).\ncancelable — Timer event flag indicating that the event\nshould be ignored while shutting down the worker.\nGraceful worker shutdown is delayed until there are no non-cancelable timer\nevents scheduled.\nposted — Flag indicating that the event is posted to a queue.\nqueue — Queue node for posting the event to a queue.\n\n
\nEach connection obtained by calling the ngx_get_connection()\nfunction has two attached events, c->read and\nc->write, which are used for receiving notification that the\nsocket is ready for reading or writing.\nAll such events operate in Edge-Triggered mode, meaning that they only trigger\nnotifications when the state of the socket changes.\nFor example, doing a partial read on a socket does not make nginx deliver a\nrepeated read notification until more data arrives on the socket.\nEven when the underlying I/O notification mechanism is essentially\nLevel-Triggered (poll, select etc), nginx\nconverts the notifications to Edge-Triggered.\nTo make nginx event notifications consistent across all notifications systems\non different platforms, the functions\nngx_handle_read_event(rev, flags) and\nngx_handle_write_event(wev, lowat) must be called after\nhandling an I/O socket notification or calling any I/O functions on that socket.\nNormally, the functions are called once at the end of each read or write\nevent handler.\n
\nAn event can be set to send a notification when a timeout expires.\nThe timer used by events counts milliseconds since some unspecified point\nin the past truncated to ngx_msec_t type.\nIts current value can be obtained from the ngx_current_msec\nvariable.\n
\nThe function ngx_add_timer(ev, timer) sets a timeout for an\nevent, ngx_del_timer(ev) deletes a previously set timeout.\nThe global timeout red-black tree ngx_event_timer_rbtree\nstores all timeouts currently set.\nThe key in the tree is of type ngx_msec_t and is the time\nwhen the event occurs.\nThe tree structure enables fast insertion and deletion operations, as well as\naccess to the nearest timeouts, which nginx uses to find out how long to wait\nfor I/O events and for expiring timeout events.\n
\nAn event can be posted which means that its handler will be called at some\npoint later within the current event loop iteration.\nPosting events is a good practice for simplifying code and escaping stack\noverflows.\nPosted events are held in a post queue.\nThe ngx_post_event(ev, q) macro posts the event\nev to the post queue q.\nThe ngx_delete_posted_event(ev) macro deletes the event\nev from the queue it's currently posted in.\nNormally, events are posted to the ngx_posted_events queue,\nwhich is processed late in the event loop — after all I/O and timer\nevents are already handled.\nThe function ngx_event_process_posted() is called to process\nan event queue.\nIt calls event handlers until the queue is empty.\nThis means that a posted event handler can post more events to be processed\nwithin the current event loop iteration.\n
\nAn example:\n
\nvoid\nngx_my_connection_read(ngx_connection_t *c)\n{\n ngx_event_t *rev;\n\n rev = c->read;\n\n ngx_add_timer(rev, 1000);\n\n rev->handler = ngx_my_read_handler;\n\n ngx_my_read(rev);\n}\n\n\nvoid\nngx_my_read_handler(ngx_event_t *rev)\n{\n ssize_t n;\n ngx_connection_t *c;\n u_char buf[256];\n\n if (rev->timedout) { /* timeout expired */ }\n\n c = rev->data;\n\n while (rev->ready) {\n n = c->recv(c, buf, sizeof(buf));\n\n if (n == NGX_AGAIN) {\n break;\n }\n\n if (n == NGX_ERROR) { /* error */ }\n\n /* process buf */\n }\n\n if (ngx_handle_read_event(rev, 0) != NGX_OK) { /* error */ }\n}\n\nExcept for the nginx master process, all nginx processes do I/O and so have an\nevent loop.\n(The nginx master process instead spends most of its time in the\n sigsuspend() call waiting for signals to arrive.)\nThe nginx event loop is implemented in the\nngx_process_events_and_timers() function, which is called\nrepeatedly until the process exits.\n
\nThe event loop has the following stages:\n\n
ngx_event_find_timer().\nThis function finds the leftmost node in the timer tree and returns the\nnumber of milliseconds until the node expires.\nready\nflag is set and the event's handler is called.\nFor Linux, the ngx_epoll_process_events() handler\nis normally used, which calls epoll_wait() to wait for I/O\nevents.\nngx_event_expire_timers().\nThe timer tree is iterated from the leftmost element to the right until an\nunexpired timeout is found.\nFor each expired node the timedout event flag is set,\nthe timer_set flag is reset, and the event handler is called\nngx_event_process_posted().\nThe function repeatedly removes the first element from the posted events\nqueue and calls the element's handler, until the queue is empty.\n\n
\nAll nginx processes handle signals as well.\nSignal handlers only set global variables which are checked after the\nngx_process_events_and_timers() call.\n
\nThere are several types of processes in nginx.\nThe type of a process is kept in the ngx_process\nglobal variable, and is one of the following:\n
\nNGX_PROCESS_MASTER — The master process, which reads the\nNGINX configuration, creates cycles, and starts and controls child processes.\nIt does not perform any I/O and responds only to signals.\nIts cycle function is ngx_master_process_cycle().\n
\nNGX_PROCESS_WORKER — The worker process, which handles client\nconnections.\nIt is started by the master process and responds to its signals and channel\ncommands as well.\nIts cycle function is ngx_worker_process_cycle().\nThere can be multiple worker processes, as configured by the\nworker_processes directive.\n
\nNGX_PROCESS_SINGLE — The single process, which exists only in\nmaster_process off mode, and is the only process running in\nthat mode.\nIt creates cycles (like the master process does) and handles client connections\n(like the worker process does).\nIts cycle function is ngx_single_process_cycle().\n
\nNGX_PROCESS_HELPER — The helper process, of which currently\nthere are two types: cache manager and cache loader.\nThe cycle function for both is\nngx_cache_manager_process_cycle().\n
\nThe nginx processes handle the following signals:\n
\nNGX_SHUTDOWN_SIGNAL (SIGQUIT on most\nsystems) — Gracefully shutdown.\nUpon receiving this signal, the master process sends a shutdown signal to all\nchild processes.\nWhen no child processes are left, the master destroys the cycle pool and exits.\nWhen a worker process receives this signal, it closes all listening sockets and\nwaits until there are no non-cancelable events scheduled, then destroys the\ncycle pool and exits.\nWhen the cache manager or the cache loader process receives this signal, it\nexits immediately.\nThe ngx_quit variable is set to 1 when a\nprocess receives this signal, and is immediately reset after being processed.\nThe ngx_exiting variable is set to 1 while\na worker process is in the shutdown state.\n
\nNGX_TERMINATE_SIGNAL (SIGTERM on most\nsystems) — Terminate.\nUpon receiving this signal, the master process sends a terminate signal to all\nchild processes.\nIf a child process does not exit within 1 second, the master process sends the\nSIGKILL signal to kill it.\nWhen no child processes are left, the master process destroys the cycle pool and\nexits.\nWhen a worker process, the cache manager process or the cache loader process\nreceives this signal, it destroys the cycle pool and exits.\nThe variable ngx_terminate is set to 1\nwhen this signal is received.\n
\nNGX_NOACCEPT_SIGNAL (SIGWINCH on most\nsystems) - Shut down all worker and helper processes.\nUpon receiving this signal, the master process shuts down its child processes.\nIf a previously started new nginx binary exits, the child processes of the old\nmaster are started again.\nWhen a worker process receives this signal, it shuts down in debug mode\nset by the debug_points directive.\n
\nNGX_RECONFIGURE_SIGNAL (SIGHUP on most\nsystems) - Reconfigure.\nUpon receiving this signal, the master process re-reads the configuration and\ncreates a new cycle based on it.\nIf the new cycle is created successfully, the old cycle is deleted and new\nchild processes are started.\nMeanwhile, the old child processes receive the\nNGX_SHUTDOWN_SIGNAL signal.\nIn single-process mode, nginx creates a new cycle, but keeps the old one until\nthere are no longer clients with active connections tied to it.\nThe worker and helper processes ignore this signal.\n
\nNGX_REOPEN_SIGNAL (SIGUSR1 on most\nsystems) — Reopen files.\nThe master process sends this signal to workers, which reopen all\nopen_files related to the cycle.\n
\nNGX_CHANGEBIN_SIGNAL (SIGUSR2 on most\nsystems) — Change the nginx binary.\nThe master process starts a new nginx binary and passes in a list of all listen\nsockets.\nThe text-format list, passed in the “NGINX” environment\nvariable, consists of descriptor numbers separated with semicolons.\nThe new nginx binary reads the “NGINX” variable and adds the\nsockets to its init cycle.\nOther processes ignore this signal.\n
\nWhile all nginx worker processes are able to receive and properly handle POSIX\nsignals, the master process does not use the standard kill()\nsyscall to pass signals to workers and helpers.\nInstead, nginx uses inter-process socket pairs which allow sending messages\nbetween all nginx processes.\nCurrently, however, messages are only sent from the master to its children.\nThe messages carry the standard signals.\n
\nIt is possible to offload into a separate thread tasks that would otherwise\nblock the nginx worker process.\nFor example, nginx can be configured to use threads to perform\nfile I/O.\nAnother use case is a library that doesn't have asynchronous interface\nand thus cannot be normally used with nginx.\nKeep in mind that the threads interface is a helper for the existing\nasynchronous approach to processing client connections, and by no means\nintended as a replacement.\n
\nTo deal with synchronization, the following wrappers over\npthreads primitives are available:\n\n
typedef pthread_mutex_t ngx_thread_mutex_t;\n\nngx_int_t\nngx_thread_mutex_create(ngx_thread_mutex_t *mtx, ngx_log_t *log);\nngx_int_t\nngx_thread_mutex_destroy(ngx_thread_mutex_t *mtx, ngx_log_t *log);\nngx_int_t\nngx_thread_mutex_lock(ngx_thread_mutex_t *mtx, ngx_log_t *log);\nngx_int_t\nngx_thread_mutex_unlock(ngx_thread_mutex_t *mtx, ngx_log_t *log);\ntypedef pthread_cond_t ngx_thread_cond_t;\n\nngx_int_t\nngx_thread_cond_create(ngx_thread_cond_t *cond, ngx_log_t *log);\nngx_int_t\nngx_thread_cond_destroy(ngx_thread_cond_t *cond, ngx_log_t *log);\nngx_int_t\nngx_thread_cond_signal(ngx_thread_cond_t *cond, ngx_log_t *log);\nngx_int_t\nngx_thread_cond_wait(ngx_thread_cond_t *cond, ngx_thread_mutex_t *mtx,\nngx_log_t *log);\n\n\n
\nInstead of creating a new thread for each task, nginx implements\na thread_pool strategy.\nMultiple thread pools may be configured for different purposes\n(for example, performing I/O on different sets of disks).\nEach thread pool is created at startup and contains a limited number of threads\nthat process a queue of tasks.\nWhen a task is completed, a predefined completion handler is called.\n
\nThe src/core/ngx_thread_pool.h header file contains\nrelevant definitions:\n
\nstruct ngx_thread_task_s {\n ngx_thread_task_t *next;\n ngx_uint_t id;\n void *ctx;\n void (*handler)(void *data, ngx_log_t *log);\n ngx_event_t event;\n};\n\ntypedef struct ngx_thread_pool_s ngx_thread_pool_t;\n\nngx_thread_pool_t *ngx_thread_pool_add(ngx_conf_t *cf, ngx_str_t *name);\nngx_thread_pool_t *ngx_thread_pool_get(ngx_cycle_t *cycle, ngx_str_t *name);\n\nngx_thread_task_t *ngx_thread_task_alloc(ngx_pool_t *pool, size_t size);\nngx_int_t ngx_thread_task_post(ngx_thread_pool_t *tp, ngx_thread_task_t *task);\n\n \nAt configuration time, a module willing to use threads has to obtain a\nreference to a thread pool by calling\nngx_thread_pool_add(cf, name), which either creates a\nnew thread pool with the given name or returns a reference\nto the pool with that name if it already exists.\n
\nTo add a task into a queue of a specified thread pool\ntp at runtime, use the\nngx_thread_task_post(tp, task) function.\n\nTo execute a function in a thread, pass parameters and setup a completion\nhandler using the ngx_thread_task_t structure:\n
\ntypedef struct {\n int foo;\n} my_thread_ctx_t;\n\n\nstatic void\nmy_thread_func(void *data, ngx_log_t *log)\n{\n my_thread_ctx_t *ctx = data;\n\n /* this function is executed in a separate thread */\n}\n\n\nstatic void\nmy_thread_completion(ngx_event_t *ev)\n{\n my_thread_ctx_t *ctx = ev->data;\n\n /* executed in nginx event loop */\n}\n\n\nngx_int_t\nmy_task_offload(my_conf_t *conf)\n{\n my_thread_ctx_t *ctx;\n ngx_thread_task_t *task;\n\n task = ngx_thread_task_alloc(conf->pool, sizeof(my_thread_ctx_t));\n if (task == NULL) {\n return NGX_ERROR;\n }\n\n ctx = task->ctx;\n\n ctx->foo = 42;\n\n task->handler = my_thread_func;\n task->event.handler = my_thread_completion;\n task->event.data = ctx;\n\n if (ngx_thread_task_post(conf->thread_pool, task) != NGX_OK) {\n return NGX_ERROR;\n }\n\n return NGX_OK;\n}\n\n\n
\nEach standalone nginx module resides in a separate directory that contains\nat least two files:\nconfig and a file with the module source code.\nThe config file contains all information needed for nginx to\nintegrate the module, for example:\n
\nngx_module_type=CORE\nngx_module_name=ngx_foo_module\nngx_module_srcs=\"$ngx_addon_dir/ngx_foo_module.c\"\n\n. auto/module\n\nngx_addon_name=$ngx_module_name\n
\nThe config file is a POSIX shell script that can set\nand access the following variables:\n
ngx_module_type — Type of module to build.\nPossible values are CORE, HTTP,\nHTTP_FILTER, HTTP_INIT_FILTER,\nHTTP_AUX_FILTER, MAIL,\nSTREAM, or MISC.\nngx_module_name — Module names.\nTo build multiple modules from a set of source files, specify a\nwhitespace-separated list of names.\nThe first name indicates the name of the output binary for the dynamic module.\nThe names in the list must match the names used in the source code.\nngx_addon_name — Name of the module as it appears in output\non the console from the configure script.\nngx_module_srcs — Whitespace-separated list of source\nfiles used to compile the module.\nThe $ngx_addon_dir variable can be used to represent the path\nto the module directory.\nngx_module_incs — Include paths required to build the module\nngx_module_deps — Whitespace-separated list of the module's\ndependencies.\nUsually, it is the list of header files.\nngx_module_libs — Whitespace-separated list of libraries to\nlink with the module.\nFor example, use ngx_module_libs=-lpthread to link\nlibpthread library.\nThe following macros can be used to link against the same libraries as\nnginx:\nLIBXSLT, LIBGD, GEOIP,\nPCRE, OPENSSL, MD5,\nSHA1, ZLIB, and PERL.\nngx_module_link — Variable set by the build system to\nDYNAMIC for a dynamic module or ADDON\nfor a static module and used to determine different actions to perform\ndepending on linking type.\nngx_module_order — Load order for the module;\nuseful for the HTTP_FILTER and\nHTTP_AUX_FILTER module types.\nThe format for this option is a whitespace-separated list of modules.\nAll modules in the list following the current module's name end up after it in\nthe global list of modules, which sets up the order for modules initialization.\nFor filter modules later initialization means earlier execution.\n\n\nThe following modules are typically used as references.\nThe ngx_http_copy_filter_module reads the data for other\nfilter modules and is placed near the bottom of the list so that it is one of\nthe first to be executed.\nThe ngx_http_write_filter_module writes the data to the\nclient socket and is placed near the top of the list, and is the last to be\nexecuted.\n
\nBy default, filter modules are placed before the\nngx_http_copy_filter in the module list so that the filter\nhandler is executed after the copy filter handler.\nFor other module types the default is the empty string.\n
\n\nTo compile a module into nginx statically, use the\n--add-module=/path/to/module argument to the configure\nscript.\nTo compile a module for later dynamic loading into nginx, use the\n--add-dynamic-module=/path/to/module argument.\n
\nModules are the building blocks of nginx, and most of its functionality is\nimplemented as modules.\nThe module source file must contain a global variable of type\nngx_module_t, which is defined as follows:\n
\nstruct ngx_module_s {\n\n /* private part is omitted */\n\n void *ctx;\n ngx_command_t *commands;\n ngx_uint_t type;\n\n ngx_int_t (*init_master)(ngx_log_t *log);\n\n ngx_int_t (*init_module)(ngx_cycle_t *cycle);\n\n ngx_int_t (*init_process)(ngx_cycle_t *cycle);\n ngx_int_t (*init_thread)(ngx_cycle_t *cycle);\n void (*exit_thread)(ngx_cycle_t *cycle);\n void (*exit_process)(ngx_cycle_t *cycle);\n\n void (*exit_master)(ngx_cycle_t *cycle);\n\n /* stubs for future extensions are omitted */\n};\n \nThe omitted private part includes the module version and a signature and is\nfilled using the predefined macro NGX_MODULE_V1.\n
\nEach module keeps its private data in the ctx field,\nrecognizes the configuration directives, specified in the\ncommands array, and can be invoked at certain stages of\nnginx lifecycle.\nThe module lifecycle consists of the following events:\n\n
init_module\nhandler is called in the context of the master process.\nThe init_module handler is called in the master process each\ntime a configuration is loaded.\ninit_process handler is called in each of them.\nexit_process handler.\nexit_master handler before\nexiting.\n \n\nBecause threads are used in nginx only as a supplementary I/O facility with its\nown API, init_thread and exit_thread\nhandlers are not currently called.\nThere is also no init_master handler, because it would be\nunnecessary overhead.\n
\nThe module type defines exactly what is stored in the\nctx field.\nIts value is one of the following types:\n
NGX_CORE_MODULENGX_EVENT_MODULENGX_HTTP_MODULENGX_MAIL_MODULENGX_STREAM_MODULE \nThe NGX_CORE_MODULE is the most basic and thus the most\ngeneric and most low-level type of module.\nThe other module types are implemented on top of it and provide a more\nconvenient way to deal with corresponding domains, like handling events or HTTP\nrequests.\n
\nThe set of core modules includes ngx_core_module,\nngx_errlog_module, ngx_regex_module,\nngx_thread_pool_module and\nngx_openssl_module modules.\nThe HTTP module, the stream module, the mail module and event modules are core\nmodules too.\nThe context of a core module is defined as:\n
\ntypedef struct {\n ngx_str_t name;\n void *(*create_conf)(ngx_cycle_t *cycle);\n char *(*init_conf)(ngx_cycle_t *cycle, void *conf);\n} ngx_core_module_t;\n \nwhere the name is a module name string,\ncreate_conf and init_conf\nare pointers to functions that create and initialize module configuration\nrespectively.\nFor core modules, nginx calls create_conf before parsing\na new configuration and init_conf after all configuration\nis parsed successfully.\nThe typical create_conf function allocates memory for the\nconfiguration and sets default values.\n
\nFor example, a simplistic module called ngx_foo_module might\nlook like this:\n
\n/*\n * Copyright (C) Author.\n */\n\n\n#include <ngx_config.h>\n#include <ngx_core.h>\n\n\ntypedef struct {\n ngx_flag_t enable;\n} ngx_foo_conf_t;\n\n\nstatic void *ngx_foo_create_conf(ngx_cycle_t *cycle);\nstatic char *ngx_foo_init_conf(ngx_cycle_t *cycle, void *conf);\n\nstatic char *ngx_foo_enable(ngx_conf_t *cf, void *post, void *data);\nstatic ngx_conf_post_t ngx_foo_enable_post = { ngx_foo_enable };\n\n\nstatic ngx_command_t ngx_foo_commands[] = {\n\n { ngx_string(\"foo_enabled\"),\n NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_FLAG,\n ngx_conf_set_flag_slot,\n 0,\n offsetof(ngx_foo_conf_t, enable),\n &ngx_foo_enable_post },\n\n ngx_null_command\n};\n\n\nstatic ngx_core_module_t ngx_foo_module_ctx = {\n ngx_string(\"foo\"),\n ngx_foo_create_conf,\n ngx_foo_init_conf\n};\n\n\nngx_module_t ngx_foo_module = {\n NGX_MODULE_V1,\n &ngx_foo_module_ctx, /* module context */\n ngx_foo_commands, /* module directives */\n NGX_CORE_MODULE, /* module type */\n NULL, /* init master */\n NULL, /* init module */\n NULL, /* init process */\n NULL, /* init thread */\n NULL, /* exit thread */\n NULL, /* exit process */\n NULL, /* exit master */\n NGX_MODULE_V1_PADDING\n};\n\n\nstatic void *\nngx_foo_create_conf(ngx_cycle_t *cycle)\n{\n ngx_foo_conf_t *fcf;\n\n fcf = ngx_pcalloc(cycle->pool, sizeof(ngx_foo_conf_t));\n if (fcf == NULL) {\n return NULL;\n }\n\n fcf->enable = NGX_CONF_UNSET;\n\n return fcf;\n}\n\n\nstatic char *\nngx_foo_init_conf(ngx_cycle_t *cycle, void *conf)\n{\n ngx_foo_conf_t *fcf = conf;\n\n ngx_conf_init_value(fcf->enable, 0);\n\n return NGX_CONF_OK;\n}\n\n\nstatic char *\nngx_foo_enable(ngx_conf_t *cf, void *post, void *data)\n{\n ngx_flag_t *fp = data;\n\n if (*fp == 0) {\n return NGX_CONF_OK;\n }\n\n ngx_log_error(NGX_LOG_NOTICE, cf->log, 0, \"Foo Module is enabled\");\n\n return NGX_CONF_OK;\n}\n\n
\nThe ngx_command_t type defines a single configuration\ndirective.\nEach module that supports configuration provides an array of such structures\nthat describe how to process arguments and what handlers to call:\n
\ntypedef struct ngx_command_s ngx_command_t;\n\nstruct ngx_command_s {\n ngx_str_t name;\n ngx_uint_t type;\n char *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);\n ngx_uint_t conf;\n ngx_uint_t offset;\n void *post;\n};\n \nTerminate the array with the special value ngx_null_command.\nThe name is the name of a directive as it appears\nin the configuration file, for example \"worker_processes\" or \"listen\".\nThe type is a bit-field of flags that specify the number of\narguments the directive takes, its type, and the context in which it appears.\nThe flags are:\n\n
NGX_CONF_NOARGS — Directive takes no arguments.\nNGX_CONF_1MORE — Directive takes one or more arguments.\nNGX_CONF_2MORE — Directive takes two or more arguments.\nNGX_CONF_TAKE1..NGX_CONF_TAKE7 —\nDirective takes exactly the indicated number of arguments.\nNGX_CONF_TAKE12, NGX_CONF_TAKE13,\nNGX_CONF_TAKE23, NGX_CONF_TAKE123,\nNGX_CONF_TAKE1234 — Directive may take different number of\narguments.\nOptions are limited to the given numbers.\nFor example, NGX_CONF_TAKE12 means it takes one or two\narguments.\n\n\nThe flags for directive types are:\n\n
NGX_CONF_BLOCK — Directive is a block, that is, it can\ncontain other directives within its opening and closing braces, or even\nimplement its own parser to handle contents inside.\nNGX_CONF_FLAG — Directive takes a boolean value, either\non or off.\n\n\nA directive's context defines where it may appear in the configuration:\n\n
NGX_MAIN_CONF — In the top level context.\nNGX_HTTP_MAIN_CONF — In the http block.\nNGX_HTTP_SRV_CONF — In a server block\nwithin the http block.\nNGX_HTTP_LOC_CONF — In a location block\nwithin the http block.\nNGX_HTTP_UPS_CONF — In an upstream block\nwithin the http block.\nNGX_HTTP_SIF_CONF — In an if block within\na server block in the http block.\nNGX_HTTP_LIF_CONF — In an if block within\na location block in the http block.\nNGX_HTTP_LMT_CONF — In a limit_except\nblock within the http block.\nNGX_STREAM_MAIN_CONF — In the stream\nblock.\nNGX_STREAM_SRV_CONF — In a server block\nwithin the stream block.\nNGX_STREAM_UPS_CONF — In an upstream block\nwithin the stream block.\nNGX_MAIL_MAIN_CONF — In the mail block.\nNGX_MAIL_SRV_CONF — In a server block\nwithin the mail block.\nNGX_EVENT_CONF — In the event block.\nNGX_DIRECT_CONF — Used by modules that don't\ncreate a hierarchy of contexts and only have one global configuration.\nThis configuration is passed to the handler as the conf\nargument.\n\n\nThe configuration parser uses these flags to throw an error in case of\na misplaced directive and calls directive handlers supplied with a proper\nconfiguration pointer, so that the same directives in different locations can\nstore their values in distinct places.\n
\nThe set field defines a handler that processes a directive\nand stores parsed values into the corresponding configuration.\nThere's a number of functions that perform common conversions:\n\n
ngx_conf_set_flag_slot — Converts the literal strings\non and off into an\nngx_flag_t value with values 1 or 0, respectively.\nngx_conf_set_str_slot — Stores a string as a value of the\nngx_str_t type.\nngx_conf_set_str_array_slot — Appends a value to an array\nngx_array_t of strings ngx_str_t.\nThe array is created if does not already exist.\nngx_conf_set_keyval_slot — Appends a key-value pair to an\narray ngx_array_t of key-value pairs\nngx_keyval_t.\nThe first string becomes the key and the second the value.\nThe array is created if it does not already exist.\nngx_conf_set_num_slot — Converts a directive's argument\nto an ngx_int_t value.\nngx_conf_set_size_slot — Converts a\nsize to a size_t value\nexpressed in bytes.\nngx_conf_set_off_slot — Converts an\noffset to an off_t value\nexpressed in bytes.\nngx_conf_set_msec_slot — Converts a\ntime to an ngx_msec_t value\nexpressed in milliseconds.\nngx_conf_set_sec_slot — Converts a\ntime to a time_t value\nexpressed in in seconds.\nngx_conf_set_bufs_slot — Converts the two supplied arguments\ninto an ngx_bufs_t object that holds the number and\nsize of buffers.\nngx_conf_set_enum_slot — Converts the supplied argument\ninto an ngx_uint_t value.\nThe null-terminated array of ngx_conf_enum_t passed in the\npost field defines the acceptable strings and corresponding\ninteger values.\nngx_conf_set_bitmask_slot — Converts the supplied arguments\ninto an ngx_uint_t value.\nThe mask values for each argument are ORed producing the result.\nThe null-terminated array of ngx_conf_bitmask_t passed in the\npost field defines the acceptable strings and corresponding\nmask values.\nset_path_slot — Converts the supplied arguments to an\nngx_path_t value and performs all required initializations.\nFor details, see the documentation for the\n\nproxy_temp_path directive.\nset_access_slot — Converts the supplied arguments to a file\npermissions mask.\nFor details, see the documentation for the\n\nproxy_store_access directive.\n\n\n
\nThe conf field defines which configuration structure is\npassed to the directory handler.\nCore modules only have the global configuration and set\nNGX_DIRECT_CONF flag to access it.\nModules like HTTP, Stream or Mail create hierarchies of configurations.\nFor example, a module's configuration is created for server,\nlocation and if scopes.\n\n
NGX_HTTP_MAIN_CONF_OFFSET — Configuration for the\nhttp block.\nNGX_HTTP_SRV_CONF_OFFSET — Configuration for a\nserver block within the http block.\nNGX_HTTP_LOC_CONF_OFFSET — Configuration for a\nlocation block within the http.\nNGX_STREAM_MAIN_CONF_OFFSET — Configuration for the\nstream block.\nNGX_STREAM_SRV_CONF_OFFSET — Configuration for a\nserver block within the stream block.\nNGX_MAIL_MAIN_CONF_OFFSET — Configuration for the\nmail block.\nNGX_MAIL_SRV_CONF_OFFSET — Configuration for a\nserver block within the mail block.\n\n\n
\nThe offset defines the offset of a field in a module\nconfiguration structure that holds values for this particular directive.\nThe typical use is to employ the offsetof() macro.\n
\nThe post field has two purposes: it may be used to define\na handler to be called after the main handler has completed, or to pass\nadditional data to the main handler.\nIn the first case, the ngx_conf_post_t structure needs to\nbe initialized with a pointer to the handler, for example:\n
\nstatic char *ngx_do_foo(ngx_conf_t *cf, void *post, void *data);\nstatic ngx_conf_post_t ngx_foo_post = { ngx_do_foo };\n \nThe post argument is the ngx_conf_post_t\nobject itself, and the data is a pointer to the value,\nconverted from arguments by the main handler with the appropriate type.\n
\nEach HTTP client connection runs through the following stages:\n
ngx_event_accept() accepts a client TCP connection.\nThis handler is called in response to a read notification on a listen socket.\nA new ngx_connection_t object is created at this stage\nto wrap the newly accepted client socket.\nEach nginx listener provides a handler to pass the new connection object to.\nFor HTTP connections it's ngx_http_init_connection(c).\nngx_http_init_connection() performs early initialization of\nthe HTTP connection.\nAt this stage an ngx_http_connection_t object is created for\nthe connection and its reference is stored in the connection's\ndata field.\nLater it will be replaced by an HTTP request object.\nA PROXY protocol parser and the SSL handshake are started at\nthis stage as well.\nngx_http_wait_request_handler() read event handler\nis called when data is available on the client socket.\nAt this stage an HTTP request object ngx_http_request_t is\ncreated and set to the connection's data field.\nngx_http_process_request_line() read event handler\nreads client request line.\nThe handler is set by ngx_http_wait_request_handler().\nThe data is read into connection's buffer.\nThe size of the buffer is initially set by the directive\nclient_header_buffer_size.\nThe entire client header is supposed to fit in the buffer.\nIf the initial size is not sufficient, a bigger buffer is allocated,\nwith the capacity set by the large_client_header_buffers\ndirective.\nngx_http_process_request_headers() read event handler,\nis set after ngx_http_process_request_line() to read\nthe client request header.\nngx_http_core_run_phases() is called when the request header\nis completely read and parsed.\nThis function runs request phases from\nNGX_HTTP_POST_READ_PHASE to\nNGX_HTTP_CONTENT_PHASE.\nThe last phase is intended to generate a response and pass it along the filter\nchain.\nThe response is not necessarily sent to the client at this phase.\nIt might remain buffered and be sent at the finalization stage.\nngx_http_finalize_request() is usually called when the\nrequest has generated all the output or produced an error.\nIn the latter case an appropriate error page is looked up and used as the\nresponse.\nIf the response is not completely sent to the client by this point, an\nHTTP writer ngx_http_writer() is activated to finish\nsending outstanding data.\nngx_http_finalize_connection() is called when the complete\nresponse has been sent to the client and the request can be destroyed.\nIf the client connection keepalive feature is enabled,\nngx_http_set_keepalive() is called, which destroys the\ncurrent request and waits for the next request on the connection.\nOtherwise, ngx_http_close_request() destroys both the\nrequest and the connection.\n\nFor each client HTTP request the ngx_http_request_t object is\ncreated. Some of the fields of this object are:\n
\nconnection — Pointer to a ngx_connection_t\nclient connection object.\nSeveral requests can reference the same connection object at the same time -\none main request and its subrequests.\nAfter a request is deleted, a new request can be created on the same connection.\n
\nNote that for HTTP connections ngx_connection_t's\ndata field points back to the request.\nSuch requests are called active, as opposed to the other requests tied to the\nconnection.\nAn active request is used to handle client connection events and is allowed to\noutput its response to the client.\nNormally, each request becomes active at some point so that it can send its\noutput.\n
\nctx — Array of HTTP module contexts.\nEach module of type NGX_HTTP_MODULE can store any value\n(normally, a pointer to a structure) in the request.\nThe value is stored in the ctx array at the module's\nctx_index position.\nThe following macros provide a convenient way to get and set request contexts:\n
ngx_http_get_module_ctx(r, module) — Returns\nthe module's context\nngx_http_set_ctx(r, c, module) — Sets c\nas the module's context\nmain_conf, srv_conf,\nloc_conf — Arrays of current request\nconfigurations.\nConfigurations are stored at the module's ctx_index\npositions.\nread_event_handler, write_event_handler -\nRead and write event handlers for the request.\nNormally, both the read and write event handlers for an HTTP connection\nare set to ngx_http_request_handler().\nThis function calls the read_event_handler and\nwrite_event_handler handlers for the currently\nactive request.\ncache — Request cache object for caching the\nupstream response.\nupstream — Request upstream object for proxying.\npool — Request pool.\nThe request object itself is allocated in this pool, which is destroyed when\nthe request is deleted.\nFor allocations that need to be available throughout the client connection's\nlifetime, use ngx_connection_t's pool instead.\nheader_in — Buffer into which the client HTTP request\nheader is read.\nheaders_in, headers_out — Input and\noutput HTTP headers objects.\nBoth objects contain the headers field of type\nngx_list_t for keeping the raw list of headers.\nIn addition to that, specific headers are available for getting and setting as\nseparate fields, for example content_length_n,\nstatus etc.\nrequest_body — Client request body object.\nstart_sec, start_msec — Time point when\nthe request was created, used for tracking request duration.\nmethod, method_name — Numeric and text\nrepresentation of the client HTTP request method.\nNumeric values for methods are defined in\nsrc/http/ngx_http_request.h with the macros\nNGX_HTTP_GET, NGX_HTTP_HEAD,\nNGX_HTTP_POST, etc.\nhttp_protocol — Client HTTP protocol version in its\noriginal text form (“HTTP/1.0”, “HTTP/1.1” etc).\nhttp_version — Client HTTP protocol version in\nnumeric form (NGX_HTTP_VERSION_10,\nNGX_HTTP_VERSION_11, etc.).\nhttp_major, http_minor — Client HTTP\nprotocol version in numeric form split into major and minor parts.\nrequest_line, unparsed_uri — Request line\nand URI in the original client request.\nuri, args, exten —\nURI, arguments and file extension for the current request.\nThe URI value here might differ from the original URI sent by the client due to\nnormalization.\nThroughout request processing, these values can change as internal redirects\nare performed.\nmain — Pointer to a main request object.\nThis object is created to process a client HTTP request, as opposed to\nsubrequests, which are created to perform a specific subtask within the main\nrequest.\nparent — Pointer to the parent request of a subrequest.\npostponed — List of output buffers and subrequests, in the\norder in which they are sent and created.\nThe list is used by the postpone filter to provide consistent request output\nwhen parts of it are created by subrequests.\npost_subrequest — Pointer to a handler with the context\nto be called when a subrequest gets finalized.\nUnused for main requests.\n\nposted_requests — List of requests to be started or\nresumed, which is done by calling the request's\nwrite_event_handler.\nNormally, this handler holds the request main function, which at first runs\nrequest phases and then produces the output.\n
\nA request is usually posted by the\nngx_http_post_request(r, NULL) call.\nIt is always posted to the main request posted_requests list.\nThe function ngx_http_run_posted_requests(c) runs all\nrequests that are posted in the main request of the passed\nconnection's active request.\nAll event handlers call ngx_http_run_posted_requests,\nwhich can lead to new posted requests.\nNormally, it is called after invoking a request's read or write handler.\n
phase_handler — Index of current request phase.\nncaptures, captures,\ncaptures_data — Regex captures produced\nby the last regex match of the request.\nA regex match can occur at a number of places during request processing:\nmap lookup, server lookup by SNI or HTTP Host, rewrite, proxy_redirect, etc.\nCaptures produced by a lookup are stored in the above mentioned fields.\nThe field ncaptures holds the number of captures,\ncaptures holds captures boundaries and\ncaptures_data holds the string against which the regex was\nmatched and which is used to extract captures.\nAfter each new regex match, request captures are reset to hold new values.\ncount — Request reference counter.\nThe field only makes sense for the main request.\nIncreasing the counter is done by simple r->main->count++.\nTo decrease the counter, call\nngx_http_finalize_request(r, rc).\nCreating of a subrequest and running the request body read process both\nincrement the counter.\nsubrequests — Current subrequest nesting level.\nEach subrequest inherits its parent's nesting level, decreased by one.\nAn error is generated if the value reaches zero.\nThe value for the main request is defined by the\nNGX_HTTP_MAX_SUBREQUESTS constant.\nuri_changes — Number of URI changes remaining for\nthe request.\nThe total number of times a request can change its URI is limited by the\nNGX_HTTP_MAX_URI_CHANGES constant.\nWith each change the value is decremented until it reaches zero, at which time\nan error is generated.\nRewrites and internal redirects to normal or named locations are considered URI\nchanges.\nblocked — Counter of blocks held on the request.\nWhile this value is non-zero, the request cannot be terminated.\nCurrently, this value is increased by pending AIO operations (POSIX AIO and\nthread operations) and active cache lock.\nbuffered — Bitmask showing which modules have buffered the\noutput produced by the request.\nA number of filters can buffer output; for example, sub_filter can buffer data\nbecause of a partial string match, copy filter can buffer data because of the\nlack of free output buffers etc.\nAs long as this value is non-zero, the request is not finalized\npending the flush.\nheader_only — Flag indicating that the output does not\nrequire a body.\nFor example, this flag is used by HTTP HEAD requests.\n\nkeepalive — Flag indicating whether client connection\nkeepalive is supported.\nThe value is inferred from the HTTP version and the value of the\n“Connection” header.\n
header_sent — Flag indicating that the output header\nhas already been sent by the request.\ninternal — Flag indicating that the current request\nis internal.\nTo enter the internal state, a request must pass through an internal\nredirect or be a subrequest.\nInternal requests are allowed to enter internal locations.\nallow_ranges — Flag indicating that a partial response\ncan be sent to the client, as requested by the HTTP Range header.\nsubrequest_ranges — Flag indicating that a partial response\ncan be sent while a subrequest is being processed.\nsingle_range — Flag indicating that only a single continuous\nrange of output data can be sent to the client.\nThis flag is usually set when sending a stream of data, for example from a\nproxied server, and the entire response is not available in one buffer.\nmain_filter_need_in_memory,\nfilter_need_in_memory — Flags\nrequesting that the output produced in memory buffers rather than files.\nThis is a signal to the copy filter to read data from file buffers even if\nsendfile is enabled.\nThe difference between the two flags is the location of the filter modules that\nset them.\nFilters called before the postpone filter in the filter chain set\nfilter_need_in_memory, requesting that only the current\nrequest output come in memory buffers.\nFilters called later in the filter chain set\nmain_filter_need_in_memory, requesting that\nboth the main request and all subrequests read files in memory\nwhile sending output.\nfilter_need_temporary — Flag requesting that the request\noutput be produced in temporary buffers, but not in readonly memory buffers or\nfile buffers.\nThis is used by filters which may change output directly in the buffers where\nit's sent.\nEach HTTP module can have three types of configuration:\n
http block.\nFunctions as global settings for a module.\nserver block.\nFunctions as server-specific settings for a module.\nlocation,\nif or limit_except block.\nFunctions as location-specific settings for a module.\n\nConfiguration structures are created at the nginx configuration stage by\ncalling functions, which allocate the structures, initialize them\nand merge them.\nThe following example shows how to create a simple location\nconfiguration for a module.\nThe configuration has one setting, foo, of type\nunsigned integer.\n
\ntypedef struct {\n ngx_uint_t foo;\n} ngx_http_foo_loc_conf_t;\n\n\nstatic ngx_http_module_t ngx_http_foo_module_ctx = {\n NULL, /* preconfiguration */\n NULL, /* postconfiguration */\n\n NULL, /* create main configuration */\n NULL, /* init main configuration */\n\n NULL, /* create server configuration */\n NULL, /* merge server configuration */\n\n ngx_http_foo_create_loc_conf, /* create location configuration */\n ngx_http_foo_merge_loc_conf /* merge location configuration */\n};\n\n\nstatic void *\nngx_http_foo_create_loc_conf(ngx_conf_t *cf)\n{\n ngx_http_foo_loc_conf_t *conf;\n\n conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_foo_loc_conf_t));\n if (conf == NULL) {\n return NULL;\n }\n\n conf->foo = NGX_CONF_UNSET_UINT;\n\n return conf;\n}\n\n\nstatic char *\nngx_http_foo_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)\n{\n ngx_http_foo_loc_conf_t *prev = parent;\n ngx_http_foo_loc_conf_t *conf = child;\n\n ngx_conf_merge_uint_value(conf->foo, prev->foo, 1);\n}\n\nAs seen in the example, the ngx_http_foo_create_loc_conf()\nfunction creates a new configuration structure, and\nngx_http_foo_merge_loc_conf() merges a configuration with\nconfiguration from a higher level.\nIn fact, server and location configuration do not exist only at the server and\nlocation levels, but are also created for all levels above them.\nSpecifically, a server configuration is also created at the main level and\nlocation configurations are created at the main, server, and location levels.\nThese configurations make it possible to specify server- and location-specific\nsettings at any level of an nginx configuration file.\nEventually configurations are merged down.\nA number of macros like NGX_CONF_UNSET and\nNGX_CONF_UNSET_UINT are provided\nfor indicating a missing setting and ignoring it while merging.\nStandard nginx merge macros like ngx_conf_merge_value() and\nngx_conf_merge_uint_value() provide a convenient way to\nmerge a setting and set the default value if none of the configurations\nprovided an explicit value.\nFor complete list of macros for different types, see\nsrc/core/ngx_conf_file.h.\n
\nThe following macros are available.\nfor accessing configuration for HTTP modules at configuration time.\nThey all take ngx_conf_t reference as the first argument.\n
ngx_http_conf_get_module_main_conf(cf, module)\nngx_http_conf_get_module_srv_conf(cf, module)\nngx_http_conf_get_module_loc_conf(cf, module)\n\nThe following example gets a pointer to a location configuration of\nstandard nginx core module\nngx_http_core_module\nand replaces the location content handler kept\nin the handler field of the structure.\n
\nstatic ngx_int_t ngx_http_foo_handler(ngx_http_request_t *r);\n\n\nstatic ngx_command_t ngx_http_foo_commands[] = {\n\n { ngx_string(\"foo\"),\n NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,\n ngx_http_foo,\n 0,\n 0,\n NULL },\n\n ngx_null_command\n};\n\n\nstatic char *\nngx_http_foo(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)\n{\n ngx_http_core_loc_conf_t *clcf;\n\n clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);\n clcf->handler = ngx_http_bar_handler;\n\n return NGX_CONF_OK;\n}\n\nThe following macros are available for accessing configuration for HTTP\nmodules at runtime.\n
ngx_http_get_module_main_conf(r, module)\nngx_http_get_module_srv_conf(r, module)\nngx_http_get_module_loc_conf(r, module)\n\nThese macros receive a reference to an HTTP request\nngx_http_request_t.\nThe main configuration of a request never changes.\nServer configuration can change from the default after\nthe virtual server for the request is chosen.\nLocation configuration selected for processing a request can change multiple\ntimes as a result of a rewrite operation or internal redirect.\nThe following example shows how to access a module's HTTP configuration at\nruntime.\n
\nstatic ngx_int_t\nngx_http_foo_handler(ngx_http_request_t *r)\n{\n ngx_http_foo_loc_conf_t *flcf;\n\n flcf = ngx_http_get_module_loc_conf(r, ngx_http_foo_module);\n\n ...\n}\n\nEach HTTP request passes through a sequence of phases.\nIn each phase a distinct type of processing is performed on the request.\nModule-specific handlers can be registered in most phases,\nand many standard nginx modules register their phase handlers as a way\nto get called at a specific stage of request processing.\nPhases are processed successively and the phase handlers are called\nonce the request reaches the phase.\nFollowing is the list of nginx HTTP phases.\n
NGX_HTTP_POST_READ_PHASE — First phase.\nThe ngx_http_realip_module\nregisters its handler at this phase to enable\nsubstitution of client addresses before any other module is invoked.\nNGX_HTTP_SERVER_REWRITE_PHASE — Phase where\nrewrite directives defined in a server block\n(but outside a location block) are processed.\nThe\nngx_http_rewrite_module\ninstalls its handler at this phase.\nNGX_HTTP_FIND_CONFIG_PHASE — Special phase\nwhere a location is chosen based on the request URI.\nBefore this phase, the default location for the relevant virtual server\nis assigned to the request, and any module requesting a location configuration\nreceives the configuration for the default server location.\nThis phase assigns a new location to the request.\nNo additional handlers can be registered at this phase.\nNGX_HTTP_REWRITE_PHASE — Same as\nNGX_HTTP_SERVER_REWRITE_PHASE, but for\nrewrite rules defined in the location, chosen in the previous phase.\nNGX_HTTP_POST_REWRITE_PHASE — Special phase\nwhere the request is redirected to a new location if its URI changed\nduring a rewrite.\nThis is implemented by the request going through\nthe NGX_HTTP_FIND_CONFIG_PHASE again.\nNo additional handlers can be registered at this phase.\nNGX_HTTP_PREACCESS_PHASE — A common phase for different\ntypes of handlers, not associated with access control.\nThe standard nginx modules\nngx_http_limit_conn_module\n and\n\nngx_http_limit_req_module register their handlers at this phase.\nNGX_HTTP_ACCESS_PHASE — Phase where it is verified\nthat the client is authorized to make the request.\nStandard nginx modules such as\nngx_http_access_module and\nngx_http_auth_basic_module\n register their handlers at this phase.\nBy default the client must pass the authorization check of all handlers\nregistered at this phase for the request to continue to the next phase.\nThe satisfy directive,\ncan be used to permit processing to continue if any of the phase handlers\nauthorizes the client.\nNGX_HTTP_POST_ACCESS_PHASE — Special phase where the\nsatisfy any\ndirective is processed.\nIf some access phase handlers denied access and none explicitly allowed it, the\nrequest is finalized.\nNo additional handlers can be registered at this phase.\nNGX_HTTP_PRECONTENT_PHASE — Phase for handlers to be called\nprior to generating content.\nStandard modules such as\n\nngx_http_try_files_module and\nngx_http_mirror_module\nregister their handlers at this phase.\nNGX_HTTP_CONTENT_PHASE — Phase where the response\nis normally generated.\nMultiple nginx standard modules register their handlers at this phase,\nincluding\nngx_http_index_module or\nngx_http_static_module.\nThey are called sequentially until one of them produces\nthe output.\nIt's also possible to set content handlers on a per-location basis.\nIf the\nngx_http_core_module's\nlocation configuration has handler set, it is\ncalled as the content handler and the handlers installed at this phase\nare ignored.\nNGX_HTTP_LOG_PHASE — Phase where request logging\nis performed.\nCurrently, only the\nngx_http_log_module\nregisters its handler\nat this stage for access logging.\nLog phase handlers are called at the very end of request processing, right\nbefore freeing the request.\n\nFollowing is the example of a preaccess phase handler.\n
\nstatic ngx_http_module_t ngx_http_foo_module_ctx = {\n NULL, /* preconfiguration */\n ngx_http_foo_init, /* postconfiguration */\n\n NULL, /* create main configuration */\n NULL, /* init main configuration */\n\n NULL, /* create server configuration */\n NULL, /* merge server configuration */\n\n NULL, /* create location configuration */\n NULL /* merge location configuration */\n};\n\n\nstatic ngx_int_t\nngx_http_foo_handler(ngx_http_request_t *r)\n{\n ngx_table_elt_t *ua;\n\n ua = r->headers_in.user_agent;\n\n if (ua == NULL) {\n return NGX_DECLINED;\n }\n\n /* reject requests with \"User-Agent: foo\" */\n if (ua->value.len == 3 && ngx_strncmp(ua->value.data, \"foo\", 3) == 0) {\n return NGX_HTTP_FORBIDDEN;\n }\n\n return NGX_DECLINED;\n}\n\n\nstatic ngx_int_t\nngx_http_foo_init(ngx_conf_t *cf)\n{\n ngx_http_handler_pt *h;\n ngx_http_core_main_conf_t *cmcf;\n\n cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);\n\n h = ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers);\n if (h == NULL) {\n return NGX_ERROR;\n }\n\n *h = ngx_http_foo_handler;\n\n return NGX_OK;\n}\n\nPhase handlers are expected to return specific codes:\n
NGX_OK — Proceed to the next phase.\nNGX_DECLINED — Proceed to the next handler of the current\nphase.\nIf the current handler is the last in the current phase,\nmove to the next phase.\nNGX_AGAIN, NGX_DONE — Suspend\nphase handling until some future event which can be\nan asynchronous I/O operation or just a delay, for example.\nIt is assumed, that phase handling will be resumed later by calling\nngx_http_core_run_phases().\n\nFor some phases, return codes are treated in a slightly different way.\nAt the content phase, any return code other that\nNGX_DECLINED is considered a finalization code.\nAny return code from the location content handlers is considered a\nfinalization code.\nAt the access phase, in\nsatisfy any\nmode,\nany return code other than NGX_OK,\nNGX_DECLINED, NGX_AGAIN,\nNGX_DONE is considered a denial.\nIf no subsequent access handlers allow or deny access with a different\ncode, the denial code will become the finalization code.\n
\nVariables can be referenced by index (this is the most common method)\nor name (see below).\nThe index is created at configuration stage, when a variable is added\nto the configuration.\nTo obtain the variable index, use\nngx_http_get_variable_index():\n
\nngx_str_t name; /* ngx_string(\"foo\") */\nngx_int_t index;\n\nindex = ngx_http_get_variable_index(cf, &name);\n
\nHere, cf is a pointer to nginx configuration and\nname points to a string containing the variable name.\nThe function returns NGX_ERROR on error or a valid index\notherwise, which is typically stored somewhere in the module's\nconfiguration for future use.\n
\nAll HTTP variables are evaluated in the context of a given HTTP request,\nand results are specific to and cached in that HTTP request.\nAll functions that evaluate variables return the\nngx_http_variable_value_t type, representing\nthe variable value:\n
\ntypedef ngx_variable_value_t ngx_http_variable_value_t;\n\ntypedef struct {\n unsigned len:28;\n\n unsigned valid:1;\n unsigned no_cacheable:1;\n unsigned not_found:1;\n unsigned escape:1;\n\n u_char *data;\n} ngx_variable_value_t;\n\nwhere:\n
len — The length of the value\ndata — The value itself\nvalid — The value is valid\nnot_found — The variable was not found and thus\nthe data and len fields are irrelevant;\nthis can happen, for example, with variables like $arg_foo\nwhen a corresponding argument was not passed in a request\nno_cacheable — Do not cache result\nescape — Used internally by the logging module to mark\nvalues that require escaping on output.\n\n
\nThe ngx_http_get_flushed_variable()\nand ngx_http_get_indexed_variable() functions\nare used to obtain the value of a variable.\nThey have the same interface - accepting an HTTP request r\nas a context for evaluating the variable and an index\nthat identifies it.\nAn example of typical usage:\n
\nngx_http_variable_value_t *v;\n\nv = ngx_http_get_flushed_variable(r, index);\n\nif (v == NULL || v->not_found) {\n /* we failed to get value or there is no such variable, handle it */\n return NGX_ERROR;\n}\n\n/* some meaningful value is found */\n \nThe difference between functions is that the\nngx_http_get_indexed_variable() returns a cached value\nand ngx_http_get_flushed_variable() flushes the cache for\nnon-cacheable variables.\n
\nSome modules, such as SSI and Perl, need to deal with variables for which the\nname is not known at configuration time.\nAn index therefore cannot be used to access them, but the\nngx_http_get_variable(r, name, key) function\nis available.\nIt searches for a variable with a given\nname and its hash key derived\nfrom the name.\n
\nTo create a variable, use the ngx_http_add_variable()\nfunction.\nIt takes as arguments a configuration (where the variable is registered),\nthe variable name and flags that control the function's behaviour:\n\n
NGX_HTTP_VAR_CHANGEABLE — Enables redefinition of\nthe variable: there is no conflict if another module defines a variable with\nthe same name.\nThis allows the\nset directive\nto override variables.\nNGX_HTTP_VAR_NOCACHEABLE — Disables caching,\nwhich is useful for variables such as $time_local.\nNGX_HTTP_VAR_NOHASH — Indicates that\nthis variable is only accessible by index, not by name.\nThis is a small optimization for use when it is known that the\nvariable is not needed in modules like SSI or Perl.\nNGX_HTTP_VAR_PREFIX — The name of the\nvariable is a prefix.\nIn this case, a handler must implement additional logic to obtain the value\nof a specific variable.\nFor example, all “arg_” variables are processed by the\nsame handler, which performs lookup in request arguments and returns the value\nof a specific argument.\n \n\nThe function returns NULL in case of error or a pointer to\nngx_http_variable_t otherwise:\n
\nstruct ngx_http_variable_s {\n ngx_str_t name;\n ngx_http_set_variable_pt set_handler;\n ngx_http_get_variable_pt get_handler;\n uintptr_t data;\n ngx_uint_t flags;\n ngx_uint_t index;\n};\n \n\nThe get and set handlers\nare called to obtain or set the variable value,\ndata is passed to variable handlers, and\nindex holds assigned variable index used to reference\nthe variable.\n
\nUsually, a null-terminated static array of\nngx_http_variable_t structures is created\nby a module and processed at the preconfiguration stage to add variables\ninto the configuration, for example:\n
\nstatic ngx_http_variable_t ngx_http_foo_vars[] = {\n\n { ngx_string(\"foo_v1\"), NULL, ngx_http_foo_v1_variable, 0, 0, 0 },\n\n ngx_http_null_variable\n};\n\nstatic ngx_int_t\nngx_http_foo_add_variables(ngx_conf_t *cf)\n{\n ngx_http_variable_t *var, *v;\n\n for (v = ngx_http_foo_vars; v->name.len; v++) {\n var = ngx_http_add_variable(cf, &v->name, v->flags);\n if (var == NULL) {\n return NGX_ERROR;\n }\n\n var->get_handler = v->get_handler;\n var->data = v->data;\n }\n\n return NGX_OK;\n}\n \nThis function in the example is used to initialize\nthe preconfiguration\nfield of the HTTP module context and is called before the parsing of HTTP\nconfiguration, so that the parser can refer to these variables.\n
\nThe get handler is responsible for evaluating a variable\nin the context of a specific request, for example:\n
\nstatic ngx_int_t\nngx_http_variable_connection(ngx_http_request_t *r,\n ngx_http_variable_value_t *v, uintptr_t data)\n{\n u_char *p;\n\n p = ngx_pnalloc(r->pool, NGX_ATOMIC_T_LEN);\n if (p == NULL) {\n return NGX_ERROR;\n }\n\n v->len = ngx_sprintf(p, \"%uA\", r->connection->number) - p;\n v->valid = 1;\n v->no_cacheable = 0;\n v->not_found = 0;\n v->data = p;\n\n return NGX_OK;\n}\n \nIt returns NGX_ERROR in case of internal error\n(for example, failed memory allocation) or NGX_OK otherwise.\nTo learn the status of variable evaluation, inspect the flags\nin ngx_http_variable_value_t (see the description\nabove).\n
\nThe set handler allows setting the property\nreferenced by the variable.\nFor example, the set handler of the $limit_rate variable\nmodifies the request's limit_rate field:\n
\n...\n{ ngx_string(\"limit_rate\"), ngx_http_variable_request_set_size,\n ngx_http_variable_request_get_size,\n offsetof(ngx_http_request_t, limit_rate),\n NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE, 0 },\n...\n\nstatic void\nngx_http_variable_request_set_size(ngx_http_request_t *r,\n ngx_http_variable_value_t *v, uintptr_t data)\n{\n ssize_t s, *sp;\n ngx_str_t val;\n\n val.len = v->len;\n val.data = v->data;\n\n s = ngx_parse_size(&val);\n\n if (s == NGX_ERROR) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n \"invalid size \\\"%V\\\"\", &val);\n return;\n }\n\n sp = (ssize_t *) ((char *) r + data);\n\n *sp = s;\n\n return;\n}\n\n\n
\nA complex value, despite its name, provides an easy way to evaluate\nexpressions which can contain text, variables, and their combination.\n
\nThe complex value description in\nngx_http_compile_complex_value is compiled at the\nconfiguration stage into ngx_http_complex_value_t\nwhich is used at runtime to obtain results of expression evaluation.\n\n
\nngx_str_t *value;\nngx_http_complex_value_t cv;\nngx_http_compile_complex_value_t ccv;\n\nvalue = cf->args->elts; /* directive arguments */\n\nngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));\n\nccv.cf = cf;\nccv.value = &value[1];\nccv.complex_value = &cv;\nccv.zero = 1;\nccv.conf_prefix = 1;\n\nif (ngx_http_compile_complex_value(&ccv) != NGX_OK) {\n return NGX_CONF_ERROR;\n}\n \n\nHere, ccv holds all parameters that are required to\ninitialize the complex value cv:\n\n
cf — Configuration pointer\nvalue — String to be parsed (input)\ncomplex_value — Compiled value (output)\nzero — Flag that enables zero-terminating value\nconf_prefix — Prefixes the result with the\nconfiguration prefix (the directory where nginx is currently looking for\nconfiguration)\nroot_prefix — Prefixes the result with the root prefix\n(the normal nginx installation prefix)\n \nThe zero flag is useful when results are to be passed to\nlibraries that require zero-terminated strings, and prefixes are handy when\ndealing with filenames.\n
\nUpon successful compilation, cv.lengths\ncontains information about the presence of variables\nin the expression.\nThe NULL value means that the expression contained static text only,\nand so can be stored in a simple string rather than as a complex value.\n
\nThe ngx_http_set_complex_value_slot() is a convenient\nfunction used to initialize a complex value completely in the directive\ndeclaration itself.\n
\nAt runtime, a complex value can be calculated using the\nngx_http_complex_value() function:\n
\nngx_str_t res;\n\nif (ngx_http_complex_value(r, &cv, &res) != NGX_OK) {\n return NGX_ERROR;\n}\n \nGiven the request r and previously compiled\nvalue cv, the function evaluates the\nexpression and writes the result to res.\n
\nAn HTTP request is always connected to a location via the\nloc_conf field of the ngx_http_request_t\nstructure.\nThis means that at any point the location configuration of any module can be\nretrieved from the request by calling\nngx_http_get_module_loc_conf(r, module).\nRequest location can change several times during the request's lifetime.\nInitially, a default server location of the default server is assigned to a\nrequest.\nIf the request switches to a different server (chosen by the HTTP\n“Host” header or SSL SNI extension), the request switches to the\ndefault location of that server as well.\nThe next change of the location takes place at the\nNGX_HTTP_FIND_CONFIG_PHASE request phase.\nAt this phase a location is chosen by request URI among all non-named locations\nconfigured for the server.\nThe\nngx_http_rewrite_module\ncan change the request URI at the\nNGX_HTTP_REWRITE_PHASE request phase as a result of\nthe rewrite\ndirective and send the request back\nto the NGX_HTTP_FIND_CONFIG_PHASE phase for selection of a\nnew location based on the new URI.\n
\nIt is also possible to redirect a request to a new location at any point by\ncalling one of\nngx_http_internal_redirect(r, uri, args) or\nngx_http_named_location(r, name).\n
\nThe ngx_http_internal_redirect(r, uri, args) function changes\nthe request URI and returns the request to the\nNGX_HTTP_SERVER_REWRITE_PHASE phase.\nThe request proceeds with a server default location.\nLater at NGX_HTTP_FIND_CONFIG_PHASE a new location is chosen\nbased on the new request URI.\n
\nThe following example performs an internal redirect with the new request\narguments.\n
\nngx_int_t\nngx_http_foo_redirect(ngx_http_request_t *r)\n{\n ngx_str_t uri, args;\n\n ngx_str_set(&uri, \"/foo\");\n ngx_str_set(&args, \"bar=1\");\n\n return ngx_http_internal_redirect(r, &uri, &args);\n}\n\nThe function ngx_http_named_location(r, name) redirects\na request to a named location. The name of the location is passed as the\nargument.\nThe location is looked up among all named locations of the current\nserver, after which the requests switches to the\nNGX_HTTP_REWRITE_PHASE phase.\n
\nThe following example performs a redirect to a named location @foo.\n
\nngx_int_t\nngx_http_foo_named_redirect(ngx_http_request_t *r)\n{\n ngx_str_t name;\n\n ngx_str_set(&name, \"foo\");\n\n return ngx_http_named_location(r, &name);\n}\n\nBoth functions - ngx_http_internal_redirect(r, uri, args)\nand ngx_http_named_location(r, name) can be called when\nnginx modules have already stored some contexts in a request's\nctx field.\nIt's possible for these contexts to become inconsistent with the new\nlocation configuration.\nTo prevent inconsistency, all request contexts are\nerased by both redirect functions.\n
\nCalling ngx_http_internal_redirect(r, uri, args)\nor ngx_http_named_location(r, name) increases the request\ncount.\nFor consistent request reference counting, call\nngx_http_finalize_request(r, NGX_DONE) after redirecting the\nrequest.\nThis will finalize current request code path and decrease the counter.\n
\nRedirected and rewritten requests become internal and can access the\ninternal\nlocations.\nInternal requests have the internal flag set.\n
\nSubrequests are primarily used to insert output of one request into another,\npossibly mixed with other data.\nA subrequest looks like a normal request, but shares some data with its parent.\nIn particular, all fields related to client input are shared\nbecause a subrequest does not receive any other input from the client.\nThe request field parent for a subrequest contains a link\nto its parent request and is NULL for the main request.\nThe field main contains a link to the main request in\na group of requests.\n
\nA subrequest starts in the NGX_HTTP_SERVER_REWRITE_PHASE\nphase.\nIt passes through the same subsequent phases as a normal request and is\nassigned a location based on its own URI.\n
\nThe output header in a subrequest is always ignored.\nThe ngx_http_postpone_filter places the subrequest's\noutput body in the right position relative to other data produced\nby the parent request.\n
\nSubrequests are related to the concept of active requests.\nA request r is considered active if\nc->data == r, where c is the client\nconnection object.\nAt any given point, only the active request in a request group is allowed\nto output its buffers to the client.\nAn inactive request can still send its output to the filter chain, but it\ndoes not pass beyond the ngx_http_postpone_filter and\nremains buffered by that filter until the request becomes active.\nHere are some rules of request activation:\n
ngx_http_postpone_filter activates the next request\nin the active request's subrequest list, once all data prior to that request\nare sent.\n\nCreate a subrequest by calling the function\nngx_http_subrequest(r, uri, args, psr, ps, flags), where\nr is the parent request, uri and\nargs are the URI and arguments of the\nsubrequest, psr is the output parameter, which receives the\nnewly created subrequest reference, ps is a callback object\nfor notifying the parent request that the subrequest is being finalized, and\nflags is bitmask of flags.\nThe following flags are available:\n
NGX_HTTP_SUBREQUEST_IN_MEMORY - Output is not\nsent to the client, but rather stored in memory.\nThe flag only affects subrequests which are processed by one of the proxying\nmodules.\nAfter a subrequest is finalized its output is available in\nr->out of type ngx_buf_t.\nNGX_HTTP_SUBREQUEST_WAITED - The subrequest's\ndone flag is set even if the subrequest is not active when\nit is finalized.\nThis subrequest flag is used by the SSI filter.\nNGX_HTTP_SUBREQUEST_CLONE - The subrequest is created as a\nclone of its parent.\nIt is started at the same location and proceeds from the same phase as the\nparent request.\n\nThe following example creates a subrequest with the URI\nof /foo.\n
\nngx_int_t rc;\nngx_str_t uri;\nngx_http_request_t *sr;\n\n...\n\nngx_str_set(&uri, \"/foo\");\n\nrc = ngx_http_subrequest(r, &uri, NULL, &sr, NULL, 0);\nif (rc == NGX_ERROR) {\n /* error */\n}\n\nThis example clones the current request and sets a finalization callback for the\nsubrequest.\n
\nngx_int_t\nngx_http_foo_clone(ngx_http_request_t *r)\n{\n ngx_http_request_t *sr;\n ngx_http_post_subrequest_t *ps;\n\n ps = ngx_palloc(r->pool, sizeof(ngx_http_post_subrequest_t));\n if (ps == NULL) {\n return NGX_ERROR;\n }\n\n ps->handler = ngx_http_foo_subrequest_done;\n ps->data = \"foo\";\n\n return ngx_http_subrequest(r, &r->uri, &r->args, &sr, ps,\n NGX_HTTP_SUBREQUEST_CLONE);\n}\n\n\nngx_int_t\nngx_http_foo_subrequest_done(ngx_http_request_t *r, void *data, ngx_int_t rc)\n{\n char *msg = (char *) data;\n\n ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,\n \"done subrequest r:%p msg:%s rc:%i\", r, msg, rc);\n\n return rc;\n}\n\nSubrequests are normally created in a body filter, in which case their output\ncan be treated like the output from any explicit request.\nThis means that eventually the output of a subrequest is sent to the client,\nafter all explicit buffers that are passed before subrequest creation and\nbefore any buffers that are passed after creation.\nThis ordering is preserved even for large hierarchies of subrequests.\nThe following example inserts output from a subrequest after all request data\nbuffers, but before the final buffer with the last_buf flag.\n
\nngx_int_t\nngx_http_foo_body_filter(ngx_http_request_t *r, ngx_chain_t *in)\n{\n ngx_int_t rc;\n ngx_buf_t *b;\n ngx_uint_t last;\n ngx_chain_t *cl, out;\n ngx_http_request_t *sr;\n ngx_http_foo_filter_ctx_t *ctx;\n\n ctx = ngx_http_get_module_ctx(r, ngx_http_foo_filter_module);\n if (ctx == NULL) {\n return ngx_http_next_body_filter(r, in);\n }\n\n last = 0;\n\n for (cl = in; cl; cl = cl->next) {\n if (cl->buf->last_buf) {\n cl->buf->last_buf = 0;\n cl->buf->last_in_chain = 1;\n cl->buf->sync = 1;\n last = 1;\n }\n }\n\n /* Output explicit output buffers */\n\n rc = ngx_http_next_body_filter(r, in);\n\n if (rc == NGX_ERROR || !last) {\n return rc;\n }\n\n /*\n * Create the subrequest. The output of the subrequest\n * will automatically be sent after all preceding buffers,\n * but before the last_buf buffer passed later in this function.\n */\n\n if (ngx_http_subrequest(r, ctx->uri, NULL, &sr, NULL, 0) != NGX_OK) {\n return NGX_ERROR;\n }\n\n ngx_http_set_ctx(r, NULL, ngx_http_foo_filter_module);\n\n /* Output the final buffer with the last_buf flag */\n\n b = ngx_calloc_buf(r->pool);\n if (b == NULL) {\n return NGX_ERROR;\n }\n\n b->last_buf = 1;\n\n out.buf = b;\n out.next = NULL;\n\n return ngx_http_output_filter(r, &out);\n}\n\nA subrequest can also be created for other purposes than data output.\nFor example, the \nngx_http_auth_request_module module\ncreates a subrequest at the NGX_HTTP_ACCESS_PHASE phase.\nTo disable output at this point, the\nheader_only flag is set on the subrequest.\nThis prevents the subrequest body from being sent to the client.\nNote that the subrequest's header is never sent to the client.\nThe result of the subrequest can be analyzed in the callback handler.\n
\nAn HTTP request is finalized by calling the function\nngx_http_finalize_request(r, rc).\nIt is usually finalized by the content handler after all output buffers\nare sent to the filter chain.\nAt this point all of the output might not be sent to the client,\nwith some of it remaining buffered somewhere along the filter chain.\nIf it is, the ngx_http_finalize_request(r, rc) function\nautomatically installs a special handler ngx_http_writer(r)\nto finish sending the output.\nA request is also finalized in case of an error or if a standard HTTP response\ncode needs to be returned to the client.\n
\nThe function ngx_http_finalize_request(r, rc) expects the\nfollowing rc values:\n
NGX_DONE - Fast finalization.\nDecrement the request count and destroy the request if it\nreaches zero.\nThe client connection can be used for more requests after the current request\nis destroyed.\nNGX_ERROR, NGX_HTTP_REQUEST_TIME_OUT\n(408), NGX_HTTP_CLIENT_CLOSED_REQUEST\n(499) - Error finalization.\nTerminate the request as soon as possible and close the client connection.\nNGX_HTTP_CREATED (201),\nNGX_HTTP_NO_CONTENT (204), codes greater\nthan or equal to NGX_HTTP_SPECIAL_RESPONSE\n(300) - Special response finalization.\nFor these values nginx either sends to the client a default response page for\nthe code or performs the internal redirect to an\nerror_page location if that\nis configured for the code.\ncount\nis decremented.\nIf it reaches zero, the request is destroyed, but the client connection can\nstill be used for other requests.\nIf count is positive, there are unfinished activities\nwithin the request, which will be finalized at a later point.\n\nFor dealing with the body of a client request, nginx provides the\nngx_http_read_client_request_body(r, post_handler) and\nngx_http_discard_request_body(r) functions.\nThe first function reads the request body and makes it available via the\nrequest_body request field.\nThe second function instructs nginx to discard (read and ignore) the request\nbody.\nOne of these functions must be called for every request.\nNormally, the content handler makes the call.\n
\nReading or discarding the client request body from a subrequest is not allowed.\nIt must always be done in the main request.\nWhen a subrequest is created, it inherits the parent's\nrequest_body object which can be used by the subrequest if\nthe main request has previously read the request body.\n
\nThe function\nngx_http_read_client_request_body(r, post_handler) starts\nthe process of reading the request body.\nWhen the body is completely read, the post_handler callback\nis called to continue processing the request.\nIf the request body is missing or has already been read, the callback is called\nimmediately.\nIn unbuffered mode, the callback can be called before the whole body is read.\nThe function\nngx_http_read_client_request_body(r, post_handler)\nallocates the request_body request field of type\nngx_http_request_body_t.\nThe field bufs of this object keeps the result as a buffer\nchain.\nThe body can be saved in memory buffers or file buffers, if the capacity\nspecified by the\nclient_body_buffer_size\ndirective is not enough to fit the entire body in memory.\n
\nThe following example reads a client request body and returns its size.\n
\nngx_int_t\nngx_http_foo_content_handler(ngx_http_request_t *r)\n{\n ngx_int_t rc;\n\n rc = ngx_http_read_client_request_body(r, ngx_http_foo_init);\n\n if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {\n /* error */\n return rc;\n }\n\n return NGX_DONE;\n}\n\n\nvoid\nngx_http_foo_init(ngx_http_request_t *r)\n{\n off_t len;\n ngx_buf_t *b;\n ngx_int_t rc;\n ngx_chain_t *in, out;\n\n if (r->request_body == NULL) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n\n len = 0;\n\n for (in = r->request_body->bufs; in; in = in->next) {\n len += ngx_buf_size(in->buf);\n }\n\n b = ngx_create_temp_buf(r->pool, NGX_OFF_T_LEN);\n if (b == NULL) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n\n b->last = ngx_sprintf(b->pos, \"%O\", len);\n b->last_buf = (r == r->main) ? 1 : 0;\n b->last_in_chain = 1;\n\n r->headers_out.status = NGX_HTTP_OK;\n r->headers_out.content_length_n = b->last - b->pos;\n\n rc = ngx_http_send_header(r);\n\n if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {\n ngx_http_finalize_request(r, rc);\n return;\n }\n\n out.buf = b;\n out.next = NULL;\n\n rc = ngx_http_output_filter(r, &out);\n\n ngx_http_finalize_request(r, rc);\n}\n\nThe following fields of the request determine how the request body is read:\n
request_body_in_single_buf - Read the body to a single memory\nbuffer.\nrequest_body_in_file_only - Always read the body to a file,\neven if fits in the memory buffer.\nrequest_body_in_persistent_file - Do not unlink the file\nimmediately after creation.\nA file with this flag can be moved to another directory.\nrequest_body_in_clean_file - Unlink the file when the\nrequest is finalized.\nThis can be useful when a file was supposed to be moved to another directory\nbut was not moved for some reason.\nrequest_body_file_group_access - Enable group access to the\nfile by replacing the default 0600 access mask with 0660.\nrequest_body_file_log_level - Severity level at which to\nlog file errors.\nrequest_body_no_buffering - Read the request body without\nbuffering.\n\nThe request_body_no_buffering flag enables the\nunbuffered mode of reading a request body.\nIn this mode, after calling\nngx_http_read_client_request_body(), the\nbufs chain might keep only a part of the body.\nThe request flag reading_body indicates that the request body\nreading is still in progress.\nTo read the next part, call the\nngx_http_read_unbuffered_request_body(r) function.\nThe return value NGX_AGAIN indicates that more body data\nor buffer space is needed.\nIf bufs is NULL after calling this function, no body data is\navailable at the moment.\nThe request callback read_event_handler will be called when\nmore client body data is available.\n
\nAfter a request body part is read, it's passed to the request\nbody filter chain by calling the first body filter handler stored in\nthe ngx_http_top_request_body_filter variable.\nIt's assumed that every body handler calls the next handler in the chain until\nthe final handler ngx_http_request_body_save_filter(r, cl)\nis called.\nThis handler collects the buffers in\nr->request_body->bufs\nand writes them to a file if necessary.\nThe last request body buffer has nonzero last_buf flag.\n
\nIf a filter is planning to delay data buffers, it should set the flag\nr->request_body->filter_need_buffering to\n1 when called for the first time.\n
\nFollowing is an example of a simple request body filter that delays request\nbody by one second.\n
\n#include <ngx_config.h>\n#include <ngx_core.h>\n#include <ngx_http.h>\n\n\n#define NGX_HTTP_DELAY_BODY 1000\n\n\ntypedef struct {\n ngx_event_t event;\n ngx_chain_t *out;\n} ngx_http_delay_body_ctx_t;\n\n\nstatic ngx_int_t ngx_http_delay_body_filter(ngx_http_request_t *r,\n ngx_chain_t *in);\nstatic void ngx_http_delay_body_cleanup(void *data);\nstatic void ngx_http_delay_body_event_handler(ngx_event_t *ev);\nstatic ngx_int_t ngx_http_delay_body_init(ngx_conf_t *cf);\n\n\nstatic ngx_http_module_t ngx_http_delay_body_module_ctx = {\n NULL, /* preconfiguration */\n ngx_http_delay_body_init, /* postconfiguration */\n\n NULL, /* create main configuration */\n NULL, /* init main configuration */\n\n NULL, /* create server configuration */\n NULL, /* merge server configuration */\n\n NULL, /* create location configuration */\n NULL /* merge location configuration */\n};\n\n\nngx_module_t ngx_http_delay_body_filter_module = {\n NGX_MODULE_V1,\n &ngx_http_delay_body_module_ctx, /* module context */\n NULL, /* module directives */\n NGX_HTTP_MODULE, /* module type */\n NULL, /* init master */\n NULL, /* init module */\n NULL, /* init process */\n NULL, /* init thread */\n NULL, /* exit thread */\n NULL, /* exit process */\n NULL, /* exit master */\n NGX_MODULE_V1_PADDING\n};\n\n\nstatic ngx_http_request_body_filter_pt ngx_http_next_request_body_filter;\n\n\nstatic ngx_int_t\nngx_http_delay_body_filter(ngx_http_request_t *r, ngx_chain_t *in)\n{\n ngx_int_t rc;\n ngx_chain_t *cl, *ln;\n ngx_http_cleanup_t *cln;\n ngx_http_delay_body_ctx_t *ctx;\n\n ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n \"delay request body filter\");\n\n ctx = ngx_http_get_module_ctx(r, ngx_http_delay_body_filter_module);\n\n if (ctx == NULL) {\n ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_delay_body_ctx_t));\n if (ctx == NULL) {\n return NGX_HTTP_INTERNAL_SERVER_ERROR;\n }\n\n ngx_http_set_ctx(r, ctx, ngx_http_delay_body_filter_module);\n\n r->request_body->filter_need_buffering = 1;\n }\n\n if (ngx_chain_add_copy(r->pool, &ctx->out, in) != NGX_OK) {\n return NGX_HTTP_INTERNAL_SERVER_ERROR;\n }\n\n if (!ctx->event.timedout) {\n if (!ctx->event.timer_set) {\n\n /* cleanup to remove the timer in case of abnormal termination */\n\n cln = ngx_http_cleanup_add(r, 0);\n if (cln == NULL) {\n return NGX_HTTP_INTERNAL_SERVER_ERROR;\n }\n\n cln->handler = ngx_http_delay_body_cleanup;\n cln->data = ctx;\n\n /* add timer */\n\n ctx->event.handler = ngx_http_delay_body_event_handler;\n ctx->event.data = r;\n ctx->event.log = r->connection->log;\n\n ngx_add_timer(&ctx->event, NGX_HTTP_DELAY_BODY);\n }\n\n return ngx_http_next_request_body_filter(r, NULL);\n }\n\n rc = ngx_http_next_request_body_filter(r, ctx->out);\n\n for (cl = ctx->out; cl; /* void */) {\n ln = cl;\n cl = cl->next;\n ngx_free_chain(r->pool, ln);\n }\n\n ctx->out = NULL;\n\n return rc;\n}\n\n\nstatic void\nngx_http_delay_body_cleanup(void *data)\n{\n ngx_http_delay_body_ctx_t *ctx = data;\n\n if (ctx->event.timer_set) {\n ngx_del_timer(&ctx->event);\n }\n}\n\n\nstatic void\nngx_http_delay_body_event_handler(ngx_event_t *ev)\n{\n ngx_connection_t *c;\n ngx_http_request_t *r;\n\n r = ev->data;\n c = r->connection;\n\n ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,\n \"delay request body event\");\n\n ngx_post_event(c->read, &ngx_posted_events);\n}\n\n\nstatic ngx_int_t\nngx_http_delay_body_init(ngx_conf_t *cf)\n{\n ngx_http_next_request_body_filter = ngx_http_top_request_body_filter;\n ngx_http_top_request_body_filter = ngx_http_delay_body_filter;\n\n return NGX_OK;\n}\n\nIn nginx an HTTP response is produced by sending the response header followed by\nthe optional response body.\nBoth header and body are passed through a chain of filters and eventually get\nwritten to the client socket.\nAn nginx module can install its handler into the header or body filter chain\nand process the output coming from the previous handler.\n
\nThe ngx_http_send_header(r)\nfunction sends the output header.\nDo not call this function until r->headers_out\ncontains all of the data required to produce the HTTP response header.\nThe status field in r->headers_out\nmust always be set.\nIf the response status indicates that a response body follows the header,\ncontent_length_n can be set as well.\nThe default value for this field is -1,\nwhich means that the body size is unknown.\nIn this case, chunked transfer encoding is used.\nTo output an arbitrary header, append the headers list.\n
\nstatic ngx_int_t\nngx_http_foo_content_handler(ngx_http_request_t *r)\n{\n ngx_int_t rc;\n ngx_table_elt_t *h;\n\n /* send header */\n\n r->headers_out.status = NGX_HTTP_OK;\n r->headers_out.content_length_n = 3;\n\n /* X-Foo: foo */\n\n h = ngx_list_push(&r->headers_out.headers);\n if (h == NULL) {\n return NGX_ERROR;\n }\n\n h->hash = 1;\n ngx_str_set(&h->key, \"X-Foo\");\n ngx_str_set(&h->value, \"foo\");\n\n rc = ngx_http_send_header(r);\n\n if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {\n return rc;\n }\n\n /* send body */\n\n ...\n}\n\nThe ngx_http_send_header(r) function invokes the header\nfilter chain by calling the first header filter handler stored in\nthe ngx_http_top_header_filter variable.\nIt's assumed that every header handler calls the next handler in the chain\nuntil the final handler ngx_http_header_filter(r) is called.\nThe final header handler constructs the HTTP response based on\nr->headers_out and passes it to the\nngx_http_writer_filter for output.\n
\nTo add a handler to the header filter chain, store its address in\nthe global variable ngx_http_top_header_filter\nat configuration time.\nThe previous handler address is normally stored in a static variable in a module\nand is called by the newly added handler before exiting.\n
\nThe following example of a header filter module adds the HTTP header\n\"X-Foo: foo\" to every response with status\n200.\n
\n#include <ngx_config.h>\n#include <ngx_core.h>\n#include <ngx_http.h>\n\n\nstatic ngx_int_t ngx_http_foo_header_filter(ngx_http_request_t *r);\nstatic ngx_int_t ngx_http_foo_header_filter_init(ngx_conf_t *cf);\n\n\nstatic ngx_http_module_t ngx_http_foo_header_filter_module_ctx = {\n NULL, /* preconfiguration */\n ngx_http_foo_header_filter_init, /* postconfiguration */\n\n NULL, /* create main configuration */\n NULL, /* init main configuration */\n\n NULL, /* create server configuration */\n NULL, /* merge server configuration */\n\n NULL, /* create location configuration */\n NULL /* merge location configuration */\n};\n\n\nngx_module_t ngx_http_foo_header_filter_module = {\n NGX_MODULE_V1,\n &ngx_http_foo_header_filter_module_ctx, /* module context */\n NULL, /* module directives */\n NGX_HTTP_MODULE, /* module type */\n NULL, /* init master */\n NULL, /* init module */\n NULL, /* init process */\n NULL, /* init thread */\n NULL, /* exit thread */\n NULL, /* exit process */\n NULL, /* exit master */\n NGX_MODULE_V1_PADDING\n};\n\n\nstatic ngx_http_output_header_filter_pt ngx_http_next_header_filter;\n\n\nstatic ngx_int_t\nngx_http_foo_header_filter(ngx_http_request_t *r)\n{\n ngx_table_elt_t *h;\n\n /*\n * The filter handler adds \"X-Foo: foo\" header\n * to every HTTP 200 response\n */\n\n if (r->headers_out.status != NGX_HTTP_OK) {\n return ngx_http_next_header_filter(r);\n }\n\n h = ngx_list_push(&r->headers_out.headers);\n if (h == NULL) {\n return NGX_ERROR;\n }\n\n h->hash = 1;\n ngx_str_set(&h->key, \"X-Foo\");\n ngx_str_set(&h->value, \"foo\");\n\n return ngx_http_next_header_filter(r);\n}\n\n\nstatic ngx_int_t\nngx_http_foo_header_filter_init(ngx_conf_t *cf)\n{\n ngx_http_next_header_filter = ngx_http_top_header_filter;\n ngx_http_top_header_filter = ngx_http_foo_header_filter;\n\n return NGX_OK;\n}\n\nTo send the response body, call the\nngx_http_output_filter(r, cl) function.\nThe function can be called multiple times.\nEach time, it sends a part of the response body in the form of a buffer chain.\nSet the last_buf flag in the last body buffer.\n
\nThe following example produces a complete HTTP response with \"foo\" as its body.\nFor the example to work as subrequest as well as a main request,\nthe last_in_chain flag is set in the last buffer\nof the output.\nThe last_buf flag is set only for the main request because\nthe last buffer for a subrequest does not end the entire output.\n
\nstatic ngx_int_t\nngx_http_bar_content_handler(ngx_http_request_t *r)\n{\n ngx_int_t rc;\n ngx_buf_t *b;\n ngx_chain_t out;\n\n /* send header */\n\n r->headers_out.status = NGX_HTTP_OK;\n r->headers_out.content_length_n = 3;\n\n rc = ngx_http_send_header(r);\n\n if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {\n return rc;\n }\n\n /* send body */\n\n b = ngx_calloc_buf(r->pool);\n if (b == NULL) {\n return NGX_ERROR;\n }\n\n b->last_buf = (r == r->main) ? 1 : 0;\n b->last_in_chain = 1;\n\n b->memory = 1;\n\n b->pos = (u_char *) \"foo\";\n b->last = b->pos + 3;\n\n out.buf = b;\n out.next = NULL;\n\n return ngx_http_output_filter(r, &out);\n}\n\nThe function ngx_http_output_filter(r, cl) invokes the\nbody filter chain by calling the first body filter handler stored in\nthe ngx_http_top_body_filter variable.\nIt's assumed that every body handler calls the next handler in the chain until\nthe final handler ngx_http_write_filter(r, cl) is called.\n
\nA body filter handler receives a chain of buffers.\nThe handler is supposed to process the buffers and pass a possibly new chain to\nthe next handler.\nIt's worth noting that the chain links ngx_chain_t of the\nincoming chain belong to the caller, and must not be reused or changed.\nRight after the handler completes, the caller can use its output chain links\nto keep track of the buffers it has sent.\nTo save the buffer chain or to substitute some buffers before passing to the\nnext filter, a handler needs to allocate its own chain links.\n
\nFollowing is an example of a simple body filter that counts the number of\nbytes in the body.\nThe result is available as the $counter variable which can be\nused in the access log.\n
\n#include <ngx_config.h>\n#include <ngx_core.h>\n#include <ngx_http.h>\n\n\ntypedef struct {\n off_t count;\n} ngx_http_counter_filter_ctx_t;\n\n\nstatic ngx_int_t ngx_http_counter_body_filter(ngx_http_request_t *r,\n ngx_chain_t *in);\nstatic ngx_int_t ngx_http_counter_variable(ngx_http_request_t *r,\n ngx_http_variable_value_t *v, uintptr_t data);\nstatic ngx_int_t ngx_http_counter_add_variables(ngx_conf_t *cf);\nstatic ngx_int_t ngx_http_counter_filter_init(ngx_conf_t *cf);\n\n\nstatic ngx_http_module_t ngx_http_counter_filter_module_ctx = {\n ngx_http_counter_add_variables, /* preconfiguration */\n ngx_http_counter_filter_init, /* postconfiguration */\n\n NULL, /* create main configuration */\n NULL, /* init main configuration */\n\n NULL, /* create server configuration */\n NULL, /* merge server configuration */\n\n NULL, /* create location configuration */\n NULL /* merge location configuration */\n};\n\n\nngx_module_t ngx_http_counter_filter_module = {\n NGX_MODULE_V1,\n &ngx_http_counter_filter_module_ctx, /* module context */\n NULL, /* module directives */\n NGX_HTTP_MODULE, /* module type */\n NULL, /* init master */\n NULL, /* init module */\n NULL, /* init process */\n NULL, /* init thread */\n NULL, /* exit thread */\n NULL, /* exit process */\n NULL, /* exit master */\n NGX_MODULE_V1_PADDING\n};\n\n\nstatic ngx_http_output_body_filter_pt ngx_http_next_body_filter;\n\nstatic ngx_str_t ngx_http_counter_name = ngx_string(\"counter\");\n\n\nstatic ngx_int_t\nngx_http_counter_body_filter(ngx_http_request_t *r, ngx_chain_t *in)\n{\n ngx_chain_t *cl;\n ngx_http_counter_filter_ctx_t *ctx;\n\n ctx = ngx_http_get_module_ctx(r, ngx_http_counter_filter_module);\n if (ctx == NULL) {\n ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_counter_filter_ctx_t));\n if (ctx == NULL) {\n return NGX_ERROR;\n }\n\n ngx_http_set_ctx(r, ctx, ngx_http_counter_filter_module);\n }\n\n for (cl = in; cl; cl = cl->next) {\n ctx->count += ngx_buf_size(cl->buf);\n }\n\n return ngx_http_next_body_filter(r, in);\n}\n\n\nstatic ngx_int_t\nngx_http_counter_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,\n uintptr_t data)\n{\n u_char *p;\n ngx_http_counter_filter_ctx_t *ctx;\n\n ctx = ngx_http_get_module_ctx(r, ngx_http_counter_filter_module);\n if (ctx == NULL) {\n v->not_found = 1;\n return NGX_OK;\n }\n\n p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN);\n if (p == NULL) {\n return NGX_ERROR;\n }\n\n v->data = p;\n v->len = ngx_sprintf(p, \"%O\", ctx->count) - p;\n v->valid = 1;\n v->no_cacheable = 0;\n v->not_found = 0;\n\n return NGX_OK;\n}\n\n\nstatic ngx_int_t\nngx_http_counter_add_variables(ngx_conf_t *cf)\n{\n ngx_http_variable_t *var;\n\n var = ngx_http_add_variable(cf, &ngx_http_counter_name, 0);\n if (var == NULL) {\n return NGX_ERROR;\n }\n\n var->get_handler = ngx_http_counter_variable;\n\n return NGX_OK;\n}\n\n\nstatic ngx_int_t\nngx_http_counter_filter_init(ngx_conf_t *cf)\n{\n ngx_http_next_body_filter = ngx_http_top_body_filter;\n ngx_http_top_body_filter = ngx_http_counter_body_filter;\n\n return NGX_OK;\n}\n\nWhen writing a body or header filter, pay special attention to the filter's\nposition in the filter order.\nThere's a number of header and body filters registered by nginx standard\nmodules.\nThe nginx standard modules register a number of head and body filters and it's\nimportant to register a new filter module in the right place with respect to\nthem.\nNormally, modules register filters in their postconfiguration handlers.\nThe order in which filters are called during processing is obviously the\nreverse of the order in which they are registered.\n
\nFor third-party filter modules nginx provides a special slot\nHTTP_AUX_FILTER_MODULES.\nTo register a filter module in this slot, set\nthe ngx_module_type variable to\nHTTP_AUX_FILTER in the module's configuration.\n
\nThe following example shows a filter module config file assuming\nfor a module with just\none source file, ngx_http_foo_filter_module.c.\n
\nngx_module_type=HTTP_AUX_FILTER\nngx_module_name=ngx_http_foo_filter_module\nngx_module_srcs=\"$ngx_addon_dir/ngx_http_foo_filter_module.c\"\n\n. auto/module\n
\nWhen issuing or altering a stream of buffers, it's often desirable to reuse the\nallocated buffers.\nA standard and widely adopted approach in nginx code is to keep\ntwo buffer chains for this purpose:\nfree and busy.\nThe free chain keeps all free buffers,\nwhich can be reused.\nThe busy chain keeps all buffers sent by the current\nmodule that are still in use by some other filter handler.\nA buffer is considered in use if its size is greater than zero.\nNormally, when a buffer is consumed by a filter, its pos\n(or file_pos for a file buffer) is moved towards\nlast (file_last for a file buffer).\nOnce a buffer is completely consumed, it's ready to be reused.\nTo add newly freed buffers to the free chain\nit's enough to iterate over the busy chain and move the zero\nsize buffers at the head of it to free.\nThis operation is so common that there is a special function for it,\nngx_chain_update_chains(free, busy, out, tag).\nThe function appends the output chain out to\nbusy and moves free buffers from the top of\nbusy to free.\nOnly the buffers with the specified tag are reused.\nThis lets a module reuse only the buffers that it allocated itself.\n
\nThe following example is a body filter that inserts the string “foo” before each\nincoming buffer.\nThe new buffers allocated by the module are reused if possible.\nNote that for this example to work properly, setting up a\nheader filter\nand resetting content_length_n to -1\nis also required, but the relevant code is not provided here.\n
\ntypedef struct {\n ngx_chain_t *free;\n ngx_chain_t *busy;\n} ngx_http_foo_filter_ctx_t;\n\n\nngx_int_t\nngx_http_foo_body_filter(ngx_http_request_t *r, ngx_chain_t *in)\n{\n ngx_int_t rc;\n ngx_buf_t *b;\n ngx_chain_t *cl, *tl, *out, **ll;\n ngx_http_foo_filter_ctx_t *ctx;\n\n ctx = ngx_http_get_module_ctx(r, ngx_http_foo_filter_module);\n if (ctx == NULL) {\n ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_foo_filter_ctx_t));\n if (ctx == NULL) {\n return NGX_ERROR;\n }\n\n ngx_http_set_ctx(r, ctx, ngx_http_foo_filter_module);\n }\n\n /* create a new chain \"out\" from \"in\" with all the changes */\n\n ll = &out;\n\n for (cl = in; cl; cl = cl->next) {\n\n /* append \"foo\" in a reused buffer if possible */\n\n tl = ngx_chain_get_free_buf(r->pool, &ctx->free);\n if (tl == NULL) {\n return NGX_ERROR;\n }\n\n b = tl->buf;\n b->tag = (ngx_buf_tag_t) &ngx_http_foo_filter_module;\n b->memory = 1;\n b->pos = (u_char *) \"foo\";\n b->last = b->pos + 3;\n\n *ll = tl;\n ll = &tl->next;\n\n /* append the next incoming buffer */\n\n tl = ngx_alloc_chain_link(r->pool);\n if (tl == NULL) {\n return NGX_ERROR;\n }\n\n tl->buf = cl->buf;\n *ll = tl;\n ll = &tl->next;\n }\n\n *ll = NULL;\n\n /* send the new chain */\n\n rc = ngx_http_next_body_filter(r, out);\n\n /* update \"busy\" and \"free\" chains for reuse */\n\n ngx_chain_update_chains(r->pool, &ctx->free, &ctx->busy, &out,\n (ngx_buf_tag_t) &ngx_http_foo_filter_module);\n\n return rc;\n}\n\nThe\nngx_http_upstream_module\nprovides the basic functionality needed to pass requests to remote servers.\nModules that implement specific protocols, such as HTTP or FastCGI, use\nthis functionality.\nThe module also provides an interface for creating custom\nload-balancing modules and implements a default round-robin method.\n
\nThe least_conn\nand hash\nmodules implement alternative load-balancing methods, but\nare actually implemented as extensions of the upstream round-robin\nmodule and share a lot of code with it, such as the representation\nof a server group.\nThe keepalive module\nis an independent module that extends upstream functionality.\n
\nThe\nngx_http_upstream_module\ncan be configured explicitly by placing the corresponding\nupstream block into\nthe configuration file, or implicitly by using directives\nsuch as proxy_pass\nthat accept a URL that gets evaluated at some point into a list of servers.\nThe alternative load-balancing methods are available only with an explicit\nupstream configuration.\nThe upstream module configuration has its own directive context\nNGX_HTTP_UPS_CONF.\nThe structure is defined as follows:\n
\nstruct ngx_http_upstream_srv_conf_s {\n ngx_http_upstream_peer_t peer;\n void **srv_conf;\n\n ngx_array_t *servers; /* ngx_http_upstream_server_t */\n\n ngx_uint_t flags;\n ngx_str_t host;\n u_char *file_name;\n ngx_uint_t line;\n in_port_t port;\n ngx_uint_t no_port; /* unsigned no_port:1 */\n\n#if (NGX_HTTP_UPSTREAM_ZONE)\n ngx_shm_zone_t *shm_zone;\n#endif\n};\n\n\n
srv_conf — Configuration context of upstream modules.\nservers — Array of\nngx_http_upstream_server_t, the result of parsing a set of\nserver directives\nin the upstream block.\nflags — Flags that mostly mark which features\nare supported by the load-balancing method.\nThe features are configured as parameters of\nthe server directive:\n\n\nNGX_HTTP_UPSTREAM_CREATE — Distinguishes explicitly\ndefined upstreams from those that are automatically created by the\nproxy_pass directive\nand “friends”\n(FastCGI, SCGI, etc.)\nNGX_HTTP_UPSTREAM_WEIGHT — The “weight”\nparameter is supported\nNGX_HTTP_UPSTREAM_MAX_FAILS — The\n“max_fails” parameter is supported\nNGX_HTTP_UPSTREAM_FAIL_TIMEOUT —\nThe “fail_timeout” parameter is supported\nNGX_HTTP_UPSTREAM_DOWN — The “down”\nparameter is supported\nNGX_HTTP_UPSTREAM_BACKUP — The “backup”\nparameter is supported\nNGX_HTTP_UPSTREAM_MAX_CONNS — The\n“max_conns” parameter is supported\nhost — Name of the upstream.\nfile_name, line — Name of the configuration file\nand the line where the upstream block is located.\nport and no_port — Not used for\nexplicitly defined upstream groups.\nshm_zone — Shared memory zone used by this upstream group,\nif any.\npeer — object that holds generic methods for\ninitializing upstream configuration:\n\n\ntypedef struct {\n ngx_http_upstream_init_pt init_upstream;\n ngx_http_upstream_init_peer_pt init;\n void *data;\n} ngx_http_upstream_peer_t;\n\nA module that implements a load-balancing algorithm must set these\nmethods and initialize private data.\nIf init_upstream was not initialized during configuration\nparsing, ngx_http_upstream_module sets it to the default\nngx_http_upstream_init_round_robin algorithm.\n\ninit_upstream(cf, us) — Configuration-time\nmethod responsible for initializing a group of servers and\ninitializing the init() method in case of success.\nA typical load-balancing module uses a list of servers in the\nupstream block\nto create an efficient data structure that it uses and saves its own\nconfiguration to the data field.\ninit(r, us) — Initializes a per-request\nngx_http_upstream_peer_t.peer structure that is used for\nload balancing (not to be confused with the\nngx_http_upstream_srv_conf_t.peer described above which\nis per-upstream).\nIt is passed as the data argument to all callbacks that\ndeal with server selection.\n\n
\nWhen nginx has to pass a request to another host for processing, it uses\nthe configured load-balancing method to obtain an address to connect to.\nThe method is obtained from the\nngx_http_upstream_t.peer object\nof type ngx_peer_connection_t:\n
\nstruct ngx_peer_connection_s {\n ...\n\n struct sockaddr *sockaddr;\n socklen_t socklen;\n ngx_str_t *name;\n\n ngx_uint_t tries;\n\n ngx_event_get_peer_pt get;\n ngx_event_free_peer_pt free;\n ngx_event_notify_peer_pt notify;\n void *data;\n\n#if (NGX_SSL || NGX_COMPAT)\n ngx_event_set_peer_session_pt set_session;\n ngx_event_save_peer_session_pt save_session;\n#endif\n\n ...\n};\n\n\nThe structure has the following fields:\n\n
sockaddr, socklen,\nname — Address of the upstream server to connect to;\nthis is the output parameter of a load-balancing method.\ndata — The per-request data of a load-balancing method;\nkeeps the state of the selection algorithm and usually includes the link\nto the upstream configuration.\nIt is passed as an argument to all methods that deal with server selection\n(see below).\ntries — Allowed\nnumber\nof attempts to connect to an upstream server.\nget, free, notify,\nset_session, and save_session\n- Methods of the load-balancing module, described below.\n\n\n
\nAll methods accept at least two arguments: a peer connection object\npc and the data created by\nngx_http_upstream_srv_conf_t.peer.init().\nNote that it might differ from pc.data due\nto “chaining” of load-balancing modules.\n
\n\n
get(pc, data) — The method called when the upstream\nmodule is ready to pass a request to an upstream server and needs to know\nits address.\nThe method has to fill the sockaddr,\nsocklen, and name fields of\nngx_peer_connection_t structure.\nThe return is one of:\n\nNGX_OK — Server was selected.\nNGX_ERROR — Internal error occurred.\nNGX_BUSY — no servers are currently available.\nThis can happen due to many reasons, including: the dynamic server group is\nempty, all servers in the group are in the failed state, or\nall servers in the group are already\nhandling the maximum number of connections.\nNGX_DONE — the underlying connection was reused and there\nis no need to create a new connection to the upstream server.\nThis value is set by the keepalive module.\nfree(pc, data, state) — The method called when an\nupstream module has finished work with a particular server.\nThe state argument is the completion status of the upstream\nconnection, a bitmask with the following possible values:\n\nNGX_PEER_FAILED — Attempt was\nunsuccessful\nNGX_PEER_NEXT — A special case when upstream server\nreturns codes 403 or 404,\nwhich are not considered a\nfailure.\nNGX_PEER_KEEPALIVE — Currently unused\ntries counter.\n\nnotify(pc, data, type) — Currently unused\nin the OSS version.\nset_session(pc, data) and\nsave_session(pc, data)\n— SSL-specific methods that enable caching sessions to upstream\nservers.\nThe implementation is provided by the round-robin balancing method.\n\n\n
\nThe\nnginx-dev-examples\nrepository provides nginx module examples.\n\n
\n
ngx_ or more specific prefix such as\nngx_http_ and ngx_mail_\n\n\n
\nsize_t\nngx_utf8_length(u_char *p, size_t n)\n{\n u_char c, *last;\n size_t len;\n\n last = p + n;\n\n for (len = 0; p < last; len++) {\n\n c = *p;\n\n if (c < 0x80) {\n p++;\n continue;\n }\n\n if (ngx_utf8_decode(&p, last - p) > 0x10ffff) {\n /* invalid UTF-8 */\n return n;\n }\n }\n\n return len;\n}\n\n\n
\nA typical source file may contain the following sections separated by\ntwo empty lines:\n\n
\n
\nCopyright statements look like this:\n
\n/*\n * Copyright (C) Author Name\n * Copyright (C) Organization, Inc.\n */\n
\nIf the file is modified significantly, the list of authors should be updated,\nthe new author is added to the top.\n
\nThe ngx_config.h and ngx_core.h files\nare always included first, followed by one of\nngx_http.h, ngx_stream.h,\nor ngx_mail.h.\nThen follow optional external header files:\n
\n#include <ngx_config.h>\n#include <ngx_core.h>\n#include <ngx_http.h>\n\n#include <libxml/parser.h>\n#include <libxml/tree.h>\n#include <libxslt/xslt.h>\n\n#if (NGX_HAVE_EXSLT)\n#include <libexslt/exslt.h>\n#endif\n
\n\n
\nHeader files should include the so called \"header protection\":\n
\n#ifndef _NGX_PROCESS_CYCLE_H_INCLUDED_\n#define _NGX_PROCESS_CYCLE_H_INCLUDED_\n...\n#endif /* _NGX_PROCESS_CYCLE_H_INCLUDED_ */\n
\n
\n
//” comments are not used\n\n\n/*\n * The red-black tree code is based on the algorithm described in\n * the \"Introduction to Algorithms\" by Cormen, Leiserson and Rivest.\n */\n
\n\n/* find the server configuration for the address:port */\n
\n
\nMacro names start from ngx_ or NGX_\n(or more specific) prefix.\nMacro names for constants are uppercase.\nParameterized macros and macros for initializers are lowercase.\nThe macro name and value are separated by at least two spaces:\n
\n#define NGX_CONF_BUFFER 4096\n\n#define ngx_buf_in_memory(b) (b->temporary || b->memory || b->mmap)\n\n#define ngx_buf_size(b) \\\n (ngx_buf_in_memory(b) ? (off_t) (b->last - b->pos): \\\n (b->file_last - b->file_pos))\n\n#define ngx_null_string { 0, NULL }\n\nConditions are inside parentheses, negation is outside:\n
\n#if (NGX_HAVE_KQUEUE)\n...\n#elif ((NGX_HAVE_DEVPOLL && !(NGX_TEST_BUILD_DEVPOLL)) \\\n || (NGX_HAVE_EVENTPORT && !(NGX_TEST_BUILD_EVENTPORT)))\n...\n#elif (NGX_HAVE_EPOLL && !(NGX_TEST_BUILD_EPOLL))\n...\n#elif (NGX_HAVE_POLL)\n...\n#else /* select */\n...\n#endif /* NGX_HAVE_KQUEUE */\n
\n
\nType names end with the “_t” suffix.\nA defined type name is separated by at least two spaces:\n
\ntypedef ngx_uint_t ngx_rbtree_key_t;\n
\n
\nStructure types are defined using typedef.\nInside structures, member types and names are aligned:\n
\ntypedef struct {\n size_t len;\n u_char *data;\n} ngx_str_t;\n \nKeep alignment identical among different structures in the file.\nA structure that points to itself has the name, ending with\n“_s”.\nAdjacent structure definitions are separated with two empty lines:\n
\ntypedef struct ngx_list_part_s ngx_list_part_t;\n\nstruct ngx_list_part_s {\n void *elts;\n ngx_uint_t nelts;\n ngx_list_part_t *next;\n};\n\n\ntypedef struct {\n ngx_list_part_t *last;\n ngx_list_part_t part;\n size_t size;\n ngx_uint_t nalloc;\n ngx_pool_t *pool;\n} ngx_list_t;\n\nEach structure member is declared on its own line:\n
\ntypedef struct {\n ngx_uint_t hash;\n ngx_str_t key;\n ngx_str_t value;\n u_char *lowcase_key;\n} ngx_table_elt_t;\n\n
\nFunction pointers inside structures have defined types ending\nwith “_pt”:\n
\ntypedef ssize_t (*ngx_recv_pt)(ngx_connection_t *c, u_char *buf, size_t size);\ntypedef ssize_t (*ngx_recv_chain_pt)(ngx_connection_t *c, ngx_chain_t *in,\n off_t limit);\ntypedef ssize_t (*ngx_send_pt)(ngx_connection_t *c, u_char *buf, size_t size);\ntypedef ngx_chain_t *(*ngx_send_chain_pt)(ngx_connection_t *c, ngx_chain_t *in,\n off_t limit);\n\ntypedef struct {\n ngx_recv_pt recv;\n ngx_recv_chain_pt recv_chain;\n ngx_recv_pt udp_recv;\n ngx_send_pt send;\n ngx_send_pt udp_send;\n ngx_send_chain_pt udp_send_chain;\n ngx_send_chain_pt send_chain;\n ngx_uint_t flags;\n} ngx_os_io_t;\n\n
\nEnumerations have types ending with “_e”:\n
\ntypedef enum {\n ngx_http_fastcgi_st_version = 0,\n ngx_http_fastcgi_st_type,\n ...\n ngx_http_fastcgi_st_padding\n} ngx_http_fastcgi_state_e;\n\n
\nVariables are declared sorted by length of a base type, then alphabetically.\nType names and variable names are aligned.\nThe type and name “columns” are separated with two spaces.\nLarge arrays are put at the end of a declaration block:\n
\nu_char | | *rv, *p;\nngx_conf_t | | *cf;\nngx_uint_t | | i, j, k;\nunsigned int | | len;\nstruct sockaddr | | *sa;\nconst unsigned char | | *data;\nngx_peer_connection_t | | *pc;\nngx_http_core_srv_conf_t | |**cscfp;\nngx_http_upstream_srv_conf_t| | *us, *uscf;\nu_char | | text[NGX_SOCKADDR_STRLEN];\n
\n
\nStatic and global variables may be initialized on declaration:\n
\nstatic ngx_str_t ngx_http_memcached_key = ngx_string(\"memcached_key\");\n
\n\n
\nstatic ngx_uint_t mday[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n\n\n
\nstatic uint32_t ngx_crc32_table16[] = {\n 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,\n ...\n 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c\n};\n\n
\nThere is a bunch of commonly used type/name combinations:\n
\nu_char *rv;\nngx_int_t rc;\nngx_conf_t *cf;\nngx_connection_t *c;\nngx_http_request_t *r;\nngx_peer_connection_t *pc;\nngx_http_upstream_srv_conf_t *us, *uscf;\n
\n
\nAll functions (even static ones) should have prototypes.\nPrototypes include argument names.\nLong prototypes are wrapped with a single indentation on continuation lines:\n
\nstatic char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);\nstatic ngx_int_t ngx_http_init_phases(ngx_conf_t *cf,\n ngx_http_core_main_conf_t *cmcf);\n\nstatic char *ngx_http_merge_servers(ngx_conf_t *cf,\n ngx_http_core_main_conf_t *cmcf, ngx_http_module_t *module,\n ngx_uint_t ctx_index);\n
\nThe function name in a definition starts with a new line.\nThe function body opening and closing braces are on separate lines.\nThe body of a function is indented.\nThere are two empty lines between functions:\n
\nstatic ngx_int_t\nngx_http_find_virtual_server(ngx_http_request_t *r, u_char *host, size_t len)\n{\n ...\n}\n\n\nstatic ngx_int_t\nngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,\n ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt)\n{\n ...\n}\n\nThere is no space after the function name and opening parenthesis.\nLong function calls are wrapped such that continuation lines start\nfrom the position of the first function argument.\nIf this is impossible, format the first continuation line such that it\nends at position 79:\n
\nngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n \"http header: \\\"%V: %V\\\"\",\n &h->key, &h->value);\n\nhc->busy = ngx_palloc(r->connection->pool,\n cscf->large_client_header_buffers.num * sizeof(ngx_buf_t *));\n
\nThe ngx_inline macro should be used instead of\ninline:\n
\nstatic ngx_inline void ngx_cpuid(uint32_t i, uint32_t *buf);\n
\n
\nBinary operators except “.” and “−>”\nshould be separated from their operands by one space.\nUnary operators and subscripts are not separated from their operands by spaces:\n
\nwidth = width * 10 + (*fmt++ - '0');\n
\n
\nch = (u_char) ((decoded << 4) + (ch - '0'));\n
\n
\nr->exten.data = &r->uri.data[i + 1];\n
\n
\nType casts are separated by one space from casted expressions.\nAn asterisk inside type cast is separated with space from type name:\n
\nlen = ngx_sock_ntop((struct sockaddr *) sin6, p, len, 1);\n
\n
\nIf an expression does not fit into single line, it is wrapped.\nThe preferred point to break a line is a binary operator.\nThe continuation line is lined up with the start of expression:\n
\nif (status == NGX_HTTP_MOVED_PERMANENTLY\n || status == NGX_HTTP_MOVED_TEMPORARILY\n || status == NGX_HTTP_SEE_OTHER\n || status == NGX_HTTP_TEMPORARY_REDIRECT\n || status == NGX_HTTP_PERMANENT_REDIRECT)\n{\n ...\n}\n\n
\np->temp_file->warn = \"an upstream response is buffered \"\n \"to a temporary file\";\n
\nAs a last resort, it is possible to wrap an expression so that the\ncontinuation line ends at position 79:\n
\nhinit->hash = ngx_pcalloc(hinit->pool, sizeof(ngx_hash_wildcard_t)\n + size * sizeof(ngx_hash_elt_t *));\n
\nThe above rules also apply to sub-expressions,\nwhere each sub-expression has its own indentation level:\n
\nif (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING)\n || c->stale_updating) && !r->background\n && u->conf->cache_background_update)\n{\n ...\n}\n\nSometimes, it is convenient to wrap an expression after a cast.\nIn this case, the continuation line is indented:\n
\nnode = (ngx_rbtree_node_t *)\n ((u_char *) lr - offsetof(ngx_rbtree_node_t, color));\n
\n
\nPointers are explicitly compared to\nNULL (not 0):\n\n
\nif (ptr != NULL) {\n ...\n}\n\n
\nThe “if” keyword is separated from the condition by\none space.\nOpening brace is located on the same line, or on a\ndedicated line if the condition takes several lines.\nClosing brace is located on a dedicated line, optionally followed\nby “else if / else”.\nUsually, there is an empty line before the\n“else if / else” part:\n
\nif (node->left == sentinel) {\n temp = node->right;\n subst = node;\n\n} else if (node->right == sentinel) {\n temp = node->left;\n subst = node;\n\n} else {\n subst = ngx_rbtree_min(node->right, sentinel);\n\n if (subst->left != sentinel) {\n temp = subst->left;\n\n } else {\n temp = subst->right;\n }\n}\n\n
\nSimilar formatting rules are applied to “do”\nand “while” loops:\n
\nwhile (p < last && *p == ' ') {\n p++;\n}\n\n\n
\ndo {\n ctx->node = rn;\n ctx = ctx->next;\n} while (ctx);\n\n
\nThe “switch” keyword is separated from the condition by\none space.\nOpening brace is located on the same line.\nClosing brace is located on a dedicated line.\nThe “case” keywords are lined up with\n“switch”:\n
\nswitch (ch) {\ncase '!':\n looked = 2;\n state = ssi_comment0_state;\n break;\n\ncase '<':\n copy_end = p;\n break;\n\ndefault:\n copy_end = p;\n looked = 0;\n state = ssi_start_state;\n break;\n}\n\n
\nMost “for” loops are formatted like this:\n
\nfor (i = 0; i < ccf->env.nelts; i++) {\n ...\n}\n\n
\nfor (q = ngx_queue_head(locations);\n q != ngx_queue_sentinel(locations);\n q = ngx_queue_next(q))\n{\n ...\n}\n \nIf some part of the “for” statement is omitted,\nthis is indicated by the “/* void */” comment:\n
\nfor (i = 0; /* void */ ; i++) {\n ...\n}\n \nA loop with an empty body is also indicated by the\n“/* void */” comment which may be put on the same line:\n
\nfor (cl = *busy; cl->next; cl = cl->next) { /* void */ }\n\nAn endless loop looks like this:\n
\nfor ( ;; ) {\n ...\n}\n\n
\nLabels are surrounded with empty lines and are indented at the previous level:\n
\n if (i == 0) {\n u->err = \"host not found\";\n goto failed;\n }\n\n u->addrs = ngx_pcalloc(pool, i * sizeof(ngx_addr_t));\n if (u->addrs == NULL) {\n goto failed;\n }\n\n u->naddrs = i;\n\n ...\n\n return NGX_OK;\n\nfailed:\n\n freeaddrinfo(res);\n return NGX_ERROR;\n\n
\nTo debug memory issues such as buffer overruns or use-after-free errors, you\ncan use the \nAddressSanitizer (ASan) supported by some modern compilers.\nTo enable ASan with gcc and clang,\nuse the -fsanitize=address compiler and linker option.\nWhen building nginx, this can be done by adding the option to\n--with-cc-opt and --with-ld-opt\nparameters of the configure script.\n
\nSince most allocations in nginx are made from nginx internal\npool, enabling ASan may not always be enough to debug\nmemory issues.\nThe internal pool allocates a big chunk of memory from the system and cuts\nsmaller allocations from it.\nHowever, this mechanism can be disabled by setting the\nNGX_DEBUG_PALLOC macro to 1.\nIn this case, allocations are passed directly to the system allocator giving it\nfull control over the buffers boundaries.\n
\nThe following configuration line summarizes the information provided above.\nIt is recommended while developing third-party modules and testing nginx on\ndifferent platforms.\n
\nauto/configure --with-cc-opt='-fsanitize=address -DNGX_DEBUG_PALLOC=1'\n --with-ld-opt=-fsanitize=address\n
\nThe most common pitfall is an attempt to write a full-fledged C module\nwhen it can be avoided.\nIn most cases your task can be accomplished by creating a proper configuration.\nIf writing a module is inevitable, try to make it\nas small and simple as possible.\nFor example, a module can only export some\nvariables.\n
\nBefore starting a module, consider the following questions:\n\n
\n\n
\nThe most used string type in nginx,\nngx_str_t is not a C-Style\nzero-terminated string.\nYou cannot pass the data to standard C library functions\nsuch as strlen() or strstr().\nInstead, nginx counterparts\nthat accept either ngx_str_t should be used\nor pointer to data and a length.\nHowever, there is a case when ngx_str_t holds\na pointer to a zero-terminated string: strings that come as a result of\nconfiguration file parsing are zero-terminated.\n
\nAvoid using global variables in your modules.\nMost likely this is an error to have a global variable.\nAny global data should be tied to a configuration cycle\nand be allocated from the corresponding memory pool.\nThis allows nginx to perform graceful configuration reloads.\nAn attempt to use global variables will likely break this feature,\nbecause it will be impossible to have two configurations at\nthe same time and get rid of them.\nSometimes global variables are required.\nIn this case, special attention is needed to manage reconfiguration\nproperly.\nAlso, check if libraries used by your code have implicit\nglobal state that may be broken on reload.\n
\nInstead of dealing with malloc/free approach which is error prone,\nlearn how to use nginx pools.\nA pool is created and tied to an object -\nconfiguration,\ncycle,\nconnection,\nor HTTP request.\nWhen the object is destroyed, the associated pool is destroyed too.\nSo when working with an object, it is possible to allocate the amount\nneeded from the corresponding pool and don't care about freeing memory\neven in case of errors.\n
\nIt is recommended to avoid using threads in nginx because it will\ndefinitely break things: most nginx functions are not thread-safe.\nIt is expected that a thread will be executing only system calls and\nthread-safe library functions.\nIf you need to run some code that is not related to client request processing,\nthe proper way is to schedule a timer in the init_process\nmodule handler and perform required actions in timer handler.\nInternally nginx makes use of threads to\nboost IO-related operations, but this is a special case with a lot\nof limitations.\n
\nA common mistake is to use libraries that are blocking internally.\nMost libraries out there are synchronous and blocking by nature.\nIn other words, they perform one operation at a time and waste\ntime waiting for response from other peer.\nAs a result, when a request is processed with such library, whole\nnginx worker is blocked, thus destroying performance.\nUse only libraries that provide asynchronous interface and don't\nblock whole process.\n
\nOften modules need to perform an HTTP call to some external service.\nA common mistake is to use some external library, such as libcurl,\nto perform the HTTP request.\nIt is absolutely unnecessary to bring a huge amount of external\n(probably blocking!) code\nfor the task which can be accomplished by nginx itself.\n
\nThere are two basic usage scenarios when an external request is needed:\n\n
\n\n
\nIn the first case, the best is to use\nsubrequests API.\nInstead of directly accessing external service, you declare a location\nin nginx configuration and direct your subrequest to this location.\nThis location is not limited to\nproxying\nrequests, but may contain other nginx directives.\nAn example of such approach is the\nauth_request\ndirective implemented in\nngx_http_auth_request module.\n
\nFor the second case, it is possible to use basic HTTP client functionality\navailable in nginx.\nFor example,\nOCSP module\nimplements simple HTTP client.\n
\nQ:\nWhat does the following error mean in the log file: \"accept() failed (53:\nSoftware caused connection abort) while accepting new\nconnection on 0.0.0.0:80\"?\n
\n \n
\nA:\nSuch errors stem from the connections that the clients managed\nto close before nginx was able to process them. For instance, this can\nhappen in a situation when the user didn’t wait for a page\nheavily populated with images to load fully, and clicked on a\ndifferent link. In this case user’s browser would close all of\nthe prior connections which aren’t longer necessary.\nIt is a non-critical error.\n
\nQ:\nMy backend server appears to send HTTP/1.0 responses using\nchunked encoding but nginx doesn’t handle it correctly.\nFor instance, I’m using nginx as a frontend to my node.js\napplication and instead of pure JSON from backend, nginx\nreturns something framed in decimal numbers like\n\n
\n47\n{\"error\":\"query error\",\"message\":\"Parameter(s) missing: user,password\"}\n0\n\n\n
\n \n
\nA:\nYour backend violates HTTP specification (see\nRFC 2616,\n\"3.6 Transfer Codings\").\nThe \"chunked\" transfer-codings must not be used with HTTP/1.0.\nYou’d need to either fix your backend application or upgrade\nto nginx version 1.1.4 and newer, where an additional code\nwas introduced to handle such erratic backend behavior.\n
\nQ:\nCan I run nginx with \"daemon off\" or \"master_process off\" settings\nin a production environment?\n
\n \n
\nA:\nFirst of all, both \"daemon on|off\" and \"master_process on|off\" directives were\nintended to be used primarily for nginx code development.\n
\nWhile many people use \"daemon off\" in production it wasn’t really meant for\nthat. Since version 1.0.9 it is now quite safe to run nginx in production\nwith \"daemon off\", though. Bear in mind that non-stop upgrade is not an\noption with \"daemon off\".\n
\nIn a development environment, using \"master_process off\", nginx can run in\nthe foreground without the master process and can be terminated simply\nwith ^C (SIGINT). This is somewhat similar to running Apache with\nan 'X' command-line option. However you should NEVER run nginx in production\nwith \"master_process off\".\n
\nQ:\nI’d like to use nginx distribution as part of my proprietary\nsoftware package. How can nginx copyright be acknowledged\nwhen using nginx as part of a proprietary software distribution?\n
\n \n
\nA:\nThe text below should be added to your license conditions,\nfollowed by the text of the applicable 2-clause BSD license described\nhere.\n\n
\nThis product contains software provided by Nginx, Inc. and its contributors.\n
\n\n
\nAlso, if your build of nginx includes any of the following 3rd party\nproducts: zlib, PCRE, OpenSSL — it’s worth including their\ncopyright acknowledgements and disclaimers as well.\n
\nQ:\nIs there a proper way to use nginx variables to make sections of\nthe configuration shorter, using them as macros for making\nparts of configuration work as templates?\n
\n \n
\nA:\nVariables should not be used as template macros. Variables are\nevaluated in the run-time during the processing of each\nrequest, so they are rather costly compared to plain static\nconfiguration. Using variables to store static strings is also\na bad idea. Instead, a macro expansion and \"include\" directives\nshould be used to generate configs more easily and it can be\ndone with the external tools, e.g. sed + make or any other\ncommon template mechanism.\n
| HTTPS server optimization SSL certificate chains A single HTTP/HTTPS server Name-based HTTPS servers An SSL certificate with several names Server Name Indication Compatibility |
\nTo configure an HTTPS server, the ssl parameter\nmust be enabled on\nlistening sockets\nin the server block,\nand the locations of the\nserver certificate\nand\nprivate key\nfiles should be specified:\n\n
\nserver {\n listen 443 ssl;\n server_name www.example.com;\n ssl_certificate www.example.com.crt;\n ssl_certificate_key www.example.com.key;\n ssl_protocols TLSv1.2 TLSv1.3;\n ssl_ciphers HIGH:!aNULL:!MD5;\n ...\n}\n\n\nThe server certificate is a public entity.\nIt is sent to every client that connects to the server.\nThe private key is a secure entity and should be stored in a file with\nrestricted access, however, it must be readable by nginx’s master process.\nThe private key may alternately be stored in the same file as the certificate:\n\n
\n ssl_certificate www.example.com.cert;\n ssl_certificate_key www.example.com.cert;\n
\n\nin which case the file access rights should also be restricted.\nAlthough the certificate and the key are stored in one file,\nonly the certificate is sent to a client.\n
\nThe directives ssl_protocols and\nssl_ciphers\ncan be used to limit connections\nto include only the strong versions and ciphers of SSL/TLS.\nBy default nginx uses\n“ssl_protocols TLSv1.2 TLSv1.3”\nand “ssl_ciphers HIGH:!aNULL:!MD5”,\nso configuring them explicitly is generally not needed.\nNote that default values of these directives were\nchanged several times.\n
\nSSL operations consume extra CPU resources.\nOn multi-processor systems several\nworker processes\nshould be run,\nno less than the number of available CPU cores.\nThe most CPU-intensive operation is the SSL handshake.\nThere are two ways to minimize the number of these operations per client:\nthe first is by enabling\nkeepalive\nconnections to send several\nrequests via one connection and the second is to reuse SSL session\nparameters to avoid SSL handshakes for parallel and subsequent connections.\nThe sessions are stored in an SSL session cache shared between workers\nand configured by the\nssl_session_cache\ndirective.\nOne megabyte of the cache contains about 4000 sessions.\nThe default cache timeout is 5 minutes.\nIt can be increased by using the\nssl_session_timeout\ndirective.\nHere is a sample configuration optimized for a multi-core system\nwith 10 megabyte shared session cache:\n\n
\nworker_processes auto;\n\nhttp {\n ssl_session_cache shared:SSL:10m;\n ssl_session_timeout 10m;\n\n server {\n listen 443 ssl;\n server_name www.example.com;\n keepalive_timeout 70;\n\n ssl_certificate www.example.com.crt;\n ssl_certificate_key www.example.com.key;\n ssl_protocols TLSv1.2 TLSv1.3;\n ssl_ciphers HIGH:!aNULL:!MD5;\n ...\n\n
\nSome browsers may complain about a certificate signed by a well-known\ncertificate authority, while other browsers may accept the certificate\nwithout issues.\nThis occurs because the issuing authority has signed the server certificate\nusing an intermediate certificate that is not present in the certificate\nbase of well-known trusted certificate authorities which is distributed\nwith a particular browser.\nIn this case the authority provides a bundle of chained certificates\nwhich should be concatenated to the signed server certificate.\nThe server certificate must appear before the chained certificates\nin the combined file:\n\n
\n$ cat www.example.com.crt bundle.crt > www.example.com.chained.crt\n
\n\nThe resulting file should be used in the\nssl_certificate directive:\n\n
\nserver {\n listen 443 ssl;\n server_name www.example.com;\n ssl_certificate www.example.com.chained.crt;\n ssl_certificate_key www.example.com.key;\n ...\n}\n\n\nIf the server certificate and the bundle have been concatenated in the wrong\norder, nginx will fail to start and will display the error message:\n\n
\nSSL_CTX_use_PrivateKey_file(\" ... /www.example.com.key\") failed\n (SSL: error:05800074:x509 certificate routines::key values mismatch)\n
\n\nbecause nginx has tried to use the private key with the bundle’s\nfirst certificate instead of the server certificate.\n
\nBrowsers usually store intermediate certificates which they receive\nand which are signed by trusted authorities, so actively used browsers\nmay already have the required intermediate certificates and\nmay not complain about a certificate sent without a chained bundle.\nTo ensure the server sends the complete certificate chain,\nthe openssl command-line utility may be used, for example:\n\n
\n$ openssl s_client -connect www.godaddy.com:443\n...\nCertificate chain\n 0 s:/C=US/ST=Arizona/L=Scottsdale/1.3.6.1.4.1.311.60.2.1.3=US\n /1.3.6.1.4.1.311.60.2.1.2=AZ/O=GoDaddy.com, Inc\n /OU=MIS Department/CN=www.GoDaddy.com\n /serialNumber=0796928-7/2.5.4.15=V1.0, Clause 5.(b)\n i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc.\n /OU=http://certificates.godaddy.com/repository\n /CN=Go Daddy Secure Certification Authority\n /serialNumber=07969287\n 1 s:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc.\n /OU=http://certificates.godaddy.com/repository\n /CN=Go Daddy Secure Certification Authority\n /serialNumber=07969287\n i:/C=US/O=The Go Daddy Group, Inc.\n /OU=Go Daddy Class 2 Certification Authority\n 2 s:/C=US/O=The Go Daddy Group, Inc.\n /OU=Go Daddy Class 2 Certification Authority\n i:/L=ValiCert Validation Network/O=ValiCert, Inc.\n /OU=ValiCert Class 2 Policy Validation Authority\n /CN=http://www.valicert.com//emailAddress=info@valicert.com\n...\n
\n\nIn this example the subject (“s”) of the\nwww.GoDaddy.com server certificate #0 is signed by an issuer\n(“i”) which itself is the subject of the certificate #1,\nwhich is signed by an issuer which itself is the subject of the certificate #2,\nwhich signed by the well-known issuer ValiCert, Inc.\nwhose certificate is stored in the browsers’ built-in\ncertificate base (that lay in the house that Jack built).\n
\nIf a certificate bundle has not been added, only the server certificate #0\nwill be shown.\n
\nIt is possible to configure a single server that handles both HTTP\nand HTTPS requests:\n\n
\nserver {\n listen 80;\n listen 443 ssl;\n server_name www.example.com;\n ssl_certificate www.example.com.crt;\n ssl_certificate_key www.example.com.key;\n ...\n}\n\n\n
\nPrior to 0.7.14 SSL could not be enabled selectively for\nindividual listening sockets, as shown above.\nSSL could only be enabled for the entire server using the\nssl directive,\nmaking it impossible to set up a single HTTP/HTTPS server.\nThe ssl parameter of the\nlisten directive\nwas added to solve this issue.\nThe use of the\nssl directive\nin modern versions is thus discouraged;\nit was removed in 1.25.1.\n\n
\nA common issue arises when configuring two or more HTTPS servers\nlistening on a single IP address:\n\n
\nserver {\n listen 443 ssl;\n server_name www.example.com;\n ssl_certificate www.example.com.crt;\n ...\n}\n\nserver {\n listen 443 ssl;\n server_name www.example.org;\n ssl_certificate www.example.org.crt;\n ...\n}\n \n\nWith this configuration a browser receives the default server’s certificate,\ni.e. www.example.com regardless of the requested server name.\nThis is caused by SSL protocol behaviour.\nThe SSL connection is established before the browser sends an HTTP request\nand nginx does not know the name of the requested server.\nTherefore, it may only offer the default server’s certificate.\n
\nThe oldest and most robust method to resolve the issue\nis to assign a separate IP address for every HTTPS server:\n\n
\nserver {\n listen 192.168.1.1:443 ssl;\n server_name www.example.com;\n ssl_certificate www.example.com.crt;\n ...\n}\n\nserver {\n listen 192.168.1.2:443 ssl;\n server_name www.example.org;\n ssl_certificate www.example.org.crt;\n ...\n}\n\n
\nThere are other ways that allow sharing a single IP address\nbetween several HTTPS servers.\nHowever, all of them have their drawbacks.\nOne way is to use a certificate with several names in\nthe SubjectAltName certificate field, for example,\nwww.example.com and www.example.org.\nHowever, the SubjectAltName field length is limited.\n
\nAnother way is to use a certificate with a wildcard name, for example,\n*.example.org.\nA wildcard certificate secures all subdomains of the specified domain,\nbut only on one level.\nThis certificate matches www.example.org, but does not match\nexample.org and www.sub.example.org.\nThese two methods can also be combined.\nA certificate may contain exact and wildcard names in the\nSubjectAltName field, for example,\nexample.org and *.example.org.\n
\nIt is better to place a certificate file with several names and\nits private key file at the http level of configuration\nto inherit their single memory copy in all servers:\n\n
\nssl_certificate common.crt;\nssl_certificate_key common.key;\n\nserver {\n listen 443 ssl;\n server_name www.example.com;\n ...\n}\n\nserver {\n listen 443 ssl;\n server_name www.example.org;\n ...\n}\n\n
\nA more generic solution for running several HTTPS servers on a single\nIP address is\nTLS\nServer Name Indication extension (SNI, RFC 6066),\nwhich allows a browser to pass a requested server name during the SSL handshake\nand, therefore, the server will know which certificate it should use\nfor the connection.\nSNI is currently\nsupported\nby most modern browsers\nand is a mandatory-to-implement extension in TLSv1.3,\nthough may not be used by some old or special clients.\n
\nOnly domain names can be passed in SNI,\nhowever some browsers may erroneously pass an IP address of the server\nas its name if a request includes literal IP address.\nOne should not rely on this.\n
\n
\nIn order to use SNI in nginx, it must be supported in both the\nOpenSSL library with which the nginx binary has been built as well as\nthe library to which it is being dynamically linked at run time.\nOpenSSL supports SNI since 0.9.8f version if it was built with config option\n
\n$ nginx -V\n...\nTLS SNI support enabled\n...\n
\n\nHowever, if the SNI-enabled nginx is linked dynamically to\nan OpenSSL library without SNI support, nginx displays the warning:\n\n
\nnginx was built with SNI support, however, now it is linked\ndynamically to an OpenSSL library which has no tlsext support,\ntherefore SNI is not available\n
\n
\n
ssl parameter of the\nlisten\ndirective has been supported since 0.7.14.\nPrior to 0.8.21 it could only be specified along with the\ndefault parameter.\n\n
\n
\n
\n
HIGH:!aNULL:!MD5”.\nHIGH:!ADH:!MD5”.\nALL:!ADH:RC4+RSA:+HIGH:+MEDIUM”.\nALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP”.\n\n
| written by Igor Sysoev edited by Brian Mercer |
| Converting Mongrel rules |
\nPeople who during their shared hosting life used to configure\neverything using only Apache’s .htaccess files,\nusually translate the following rules:\n\n
\nRewriteCond %{HTTP_HOST} example.org\nRewriteRule (.*) http://www.example.org$1\n\n\nto something like this:\n\n
\nserver {\n listen 80;\n server_name www.example.org example.org;\n if ($http_host = example.org) {\n rewrite (.*) http://www.example.org$1;\n }\n ...\n}\n\n
\nThis is a wrong, cumbersome, and ineffective way.\nThe right way is to define a separate server for example.org:\n\n
\nserver {\n listen 80;\n server_name example.org;\n return 301 http://www.example.org$request_uri;\n}\n\nserver {\n listen 80;\n server_name www.example.org;\n ...\n}\n\n\n
\nOn versions prior to 0.9.1, redirects can be made with:\n\n\n rewrite ^ http://www.example.org$request_uri?;\n
\n\n
\nAnother example.\nInstead of the “upside-down” logic “all that is not\nexample.com and is not www.example.com”:\n\n
\nRewriteCond %{HTTP_HOST} !example.com\nRewriteCond %{HTTP_HOST} !www.example.com\nRewriteRule (.*) http://www.example.com$1\n \n\none should simply define example.com, www.example.com,\nand “everything else”:\n\n
\nserver {\n listen 80;\n server_name example.com www.example.com;\n ...\n}\n\nserver {\n listen 80 default_server;\n server_name _;\n return 301 http://example.com$request_uri;\n}\n\n\n
\nOn versions prior to 0.9.1, redirects can be made with:\n\n\n rewrite ^ http://example.com$request_uri?;\n
\n\n
\nTypical Mongrel rules:\n\n
\nDocumentRoot /var/www/myapp.com/current/public\n\nRewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f\nRewriteCond %{SCRIPT_FILENAME} !maintenance.html\nRewriteRule ^.*$ %{DOCUMENT_ROOT}/system/maintenance.html [L]\n\nRewriteCond %{REQUEST_FILENAME} -f\nRewriteRule ^(.*)$ $1 [QSA,L]\n\nRewriteCond %{REQUEST_FILENAME}/index.html -f\nRewriteRule ^(.*)$ $1/index.html [QSA,L]\n\nRewriteCond %{REQUEST_FILENAME}.html -f\nRewriteRule ^(.*)$ $1.html [QSA,L]\n\nRewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]\n\n\nshould be converted to\n\n
\nlocation / {\n root /var/www/myapp.com/current/public;\n\n try_files /system/maintenance.html\n $uri $uri/index.html $uri.html\n @mongrel;\n}\n\nlocation @mongrel {\n proxy_pass http://mongrel;\n}\n\n
| Load balancing methods Default load balancing configuration Least connected load balancing Least time load balancing Session persistence Weighted load balancing Health checks Further reading |
\nLoad balancing across multiple application instances is a commonly used\ntechnique for optimizing resource utilization, maximizing throughput,\nreducing latency, and ensuring fault-tolerant configurations.\n
\nIt is possible to use nginx as a very efficient HTTP load balancer to\ndistribute traffic to several application servers and to improve\nperformance, scalability and reliability of web applications with nginx.\n
\nThe following load balancing mechanisms (or methods) are supported in\nnginx:\n
\n
\nThe simplest configuration for load balancing with nginx may look\nlike the following:\n
\nhttp {\n upstream myapp1 {\n server srv1.example.com;\n server srv2.example.com;\n server srv3.example.com;\n }\n\n server {\n listen 80;\n\n location / {\n proxy_pass http://myapp1;\n }\n }\n}\n\n
\nIn the example above, there are 3 instances of the same application\nrunning on srv1-srv3.\nWhen the load balancing method is not specifically configured,\nit defaults to round-robin.\nAll requests are\n\nproxied to the server group myapp1, and nginx applies HTTP load\nbalancing to distribute the requests.\n
\nReverse proxy implementation in nginx includes load balancing for HTTP,\nHTTPS, FastCGI, uwsgi, SCGI, memcached, and gRPC.\n
\nTo configure load balancing for HTTPS instead of HTTP, just use “https”\nas the protocol.\n
\nWhen setting up load balancing for FastCGI, uwsgi, SCGI, memcached, or gRPC, use\nfastcgi_pass,\nuwsgi_pass,\nscgi_pass,\nmemcached_pass, and\ngrpc_pass\ndirectives respectively.\n
\nAnother load balancing discipline is least-connected.\nLeast-connected allows controlling the load on application\ninstances more fairly in a situation when some of the requests\ntake longer to complete.\n
\nWith the least-connected load balancing, nginx will try not to overload a\nbusy application server with excessive requests, distributing the new\nrequests to a less busy server instead.\n
\nLeast-connected load balancing in nginx is activated when the\n\nleast_conn directive is used as part of the server group configuration:\n
\n upstream myapp1 {\n least_conn;\n server srv1.example.com;\n server srv2.example.com;\n server srv3.example.com;\n }\n\n
\nAnother load balancing discipline is least-time.\nLeast-time selects the server with the lowest average response time\nand the lowest number of active connections, taking into account\ninflight requests.\n
\nWith the least-time load balancing, nginx selects the server based on\nwhich of the following parameters is specified in the\n\nleast_time directive:\n
header — time to receive the first byte from the server,\nlast_byte — time to receive the full response from the server,\nlast_byte inflight — time to receive the full response from\nthe server, taking into account incomplete requests.\n\n
\nLeast-time load balancing in nginx is activated when the\n\nleast_time directive is used as part of the server group configuration:\n
\n upstream myapp1 {\n least_time header;\n server srv1.example.com;\n server srv2.example.com;\n server srv3.example.com;\n }\n\n
\nPlease note that with round-robin or least-connected load\nbalancing, each subsequent client’s request can be potentially\ndistributed to a different server.\nThere is no guarantee that the same client will be always\ndirected to the same server.\n
\nIf there is the need to tie a client to a particular application server —\nin other words, make the client’s session “sticky” or “persistent” in\nterms of always trying to select a particular server — the ip-hash load\nbalancing mechanism can be used.\n
\nWith ip-hash, the client’s IP address is used as a hashing key to\ndetermine what server in a server group should be selected for the\nclient’s requests.\nThis method ensures that the requests from the same client\nwill always be directed to the same server\nexcept when this server is unavailable.\n
\nTo configure ip-hash load balancing, just add the\nip_hash\ndirective to the server (upstream) group configuration:\n
\nupstream myapp1 {\n ip_hash;\n server srv1.example.com;\n server srv2.example.com;\n server srv3.example.com;\n}\n\n
\nIt is also possible to influence nginx load balancing algorithms even\nfurther by using server weights.\n
\nIn the examples above, the server weights are not configured which means\nthat all specified servers are treated as equally qualified for a\nparticular load balancing method.\n
\nWith the round-robin in particular it also means a more or less equal\ndistribution of requests across the servers — provided there are enough\nrequests, and when the requests are processed in a uniform manner and\ncompleted fast enough.\n
\nWhen the\nweight\nparameter is specified for a server, the weight is accounted as part\nof the load balancing decision.\n
\n upstream myapp1 {\n server srv1.example.com weight=3;\n server srv2.example.com;\n server srv3.example.com;\n }\n\n
\nWith this configuration, every 5 new requests will be distributed across\nthe application instances as the following: 3 requests will be directed\nto srv1, one request will go to srv2, and another one — to srv3.\n
\nIt is similarly possible to use weights with the least-connected and\nip-hash load balancing in the recent versions of nginx.\n
\nReverse proxy implementation in nginx includes in-band (or passive)\nserver health checks.\nIf the response from a particular server fails with an error,\nnginx will mark this server as failed, and will try to\navoid selecting this server for subsequent inbound requests for a while.\n
\nThe\nmax_fails\ndirective sets the number of consecutive unsuccessful attempts to\ncommunicate with the server that should happen during\nfail_timeout.\nBy default,\nmax_fails\nis set to 1.\nWhen it is set to 0, health checks are disabled for this server.\nThe\nfail_timeout\nparameter also defines how long the server will be marked as failed.\nAfter\nfail_timeout\ninterval following the server failure, nginx will start to gracefully\nprobe the server with the live client’s requests.\nIf the probes have been successful, the server is marked as a live one.\n
\nIn addition, there are more directives and parameters that control server\nload balancing in nginx, e.g.\nproxy_next_upstream,\nbackup,\ndown, and\nkeepalive.\nFor more information please check our\nreference documentation.\n
\nLast but not least,\napplication load balancing,\napplication health checks,\nactivity monitoring and\non-the-fly reconfiguration of server groups are available\nas part of our paid NGINX Plus subscriptions.\n
| Example Configuration Directives allow deny |
\nThe ngx_http_access_module module allows\nlimiting access to certain client addresses.\n
\nAccess can also be limited by\npassword, by the\nresult of subrequest,\nor by JWT.\nSimultaneous limitation of access by address and by password is controlled\nby the satisfy directive.\n
\n\n\n\n
\nlocation / {\n deny 192.168.1.1;\n allow 192.168.1.0/24;\n allow 10.1.1.0/16;\n allow 2001:0db8::/32;\n deny all;\n}\n\n
\nThe rules are checked in sequence until the first match is found.\nIn this example, access is allowed only for IPv4 networks\n10.1.1.0/16 and 192.168.1.0/24\nexcluding the address 192.168.1.1,\nand for IPv6 network 2001:0db8::/32.\nIn case of a lot of rules, the use of the\nngx_http_geo_module\nmodule variables is preferable.\n
| \n Syntax:\n | \n\n allow \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location, limit_except\n | \n
\nAllows access for the specified network or address.\nIf the special value unix: is specified (1.5.1),\nallows access for all UNIX-domain sockets.\n
\nSeveral allow directives can be specified on the same level.\nThese directives are inherited from the previous configuration level\nif and only if there are no allow and\ndeny directives defined on the current level.\n
| \n Syntax:\n | \n\n deny \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location, limit_except\n | \n
\nDenies access for the specified network or address.\nIf the special value unix: is specified (1.5.1),\ndenies access for all UNIX-domain sockets.\n
\nSeveral deny directives can be specified on the same level.\nThese directives are inherited from the previous configuration level\nif and only if there are no allow and\ndeny directives defined on the current level.\n
\nThe ngx_http_acme_module module implements\nthe automatic certificate management\n(ACMEv2)\nprotocol.\n
\nThe source code of the module is available\nhere.\nDownload and install instructions are available\nhere.\n
\nThe module is also available in a prebuilt\nnginx-module-acme\npackage\nand in nginx-plus-module-acme package\nas part of our\ncommercial subscription since 1.29.0.\n
\n
\nresolver 127.0.0.1:53;\n\nacme_issuer example {\n uri https://acme.example.com/directory;\n contact admin@example.test;\n state_path /var/cache/nginx/acme-example;\n accept_terms_of_service;\n}\n\nacme_shared_zone zone=ngx_acme_shared:1M;\n\nserver {\n listen 443 ssl;\n server_name .example.test;\n\n acme_certificate example;\n\n ssl_certificate $acme_certificate;\n ssl_certificate_key $acme_certificate_key;\n\n # do not parse the certificate on each request\n ssl_certificate_cache max=2;\n}\n\nserver {\n # listener on port 80 is required to process ACME HTTP-01 challenges\n listen 80;\n\n location / {\n return 404;\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n acme_issuer \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nDefines an ACME certificate issuer object.\n
| \n Syntax:\n | \n\n uri \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n acme_issuer\n | \n
\nThe\ndirectory URL\nof the ACME server.\nThis directive is mandatory.\n
| \n Syntax:\n | \n\n account_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n acme_issuer\n | \n
\nThe account's private key used for request authentication.\n
\nAccepted values:\n
ecdsa:256/384/521\nfor ES256, ES384, or ES512 JSON Web Signature algorithms\nrsa:2048/3072/4096\nfor RS256.\n\n
\nThe generated account keys are preserved across reloads,\nbut will be lost on restart unless state_path is configured.\n
| \n Syntax:\n | \n\n challenge \n | \n
|---|---|
| \n Default:\n | \n\n challenge http-01;\n | \n
| \n Context:\n | \n\n acme_issuer\n | \n
This directive appeared in version 0.2.0.\n
\nSpecifies the ACME challenge type to be used for the issuer.\n
\nAccepted values:\n
http-01 (http)\ntls-alpn-01 (tls-alpn)\n\n
\n
\nACME challenges are versioned.\nIf an unversioned name is specified,\nthe module automatically selects the latest implemented version.\n
\n
| \n Syntax:\n | \n\n common_name_in_csr \n | \n
|---|---|
| \n Default:\n | \n\n common_name_in_csr off;\n | \n
| \n Context:\n | \n\n acme_issuer\n | \n
This directive appeared in version 0.4.0.\n
\nIf enabled, sets the Subject Common Name in the certificate request\nto the first DNS name or the first IP address provided.\n
\n
\nEnabling this option may result in rejected certificate requests.\n
\n
\nPrior to version 0.4.0, the Subject Common Name was always set.\n
\n
| \n Syntax:\n | \n\n contact \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n acme_issuer\n | \n
\nSets an array of URLs that the ACME server can use\nto contact the client regarding account issues.\nThe mailto: scheme will be used\nunless specified explicitly.\n
| \n Syntax:\n | \n\n external_account_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n acme_issuer\n | \n
This directive appeared in version 0.2.0.\n
\nSpecifies a key identifier kid and a file\nwith the MAC key for\n\nexternal account authorization.\n
\nThe value data:key can be specified\ninstead of the file, which loads a key directly from\nthe configuration without using intermediate files.\n
\nIn both cases, the key is expected to be encoded in\n\nbase64url.\n
| \n Syntax:\n | \n\n preferred_chain \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n acme_issuer\n | \n
This directive appeared in version 0.3.0.\n
\nSpecifies the preferred certificate chain.\n
\nIf the ACME server offers multiple certificate chains,\nprefer the chain with the topmost certificate issued from the\nSubject Common Name name.\nIf there are no matches, the default chain will be used.\n
| \n Syntax:\n | \n\n profile \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n acme_issuer\n | \n
This directive appeared in version 0.3.0.\n
\nRequests the\n\ncertificate profile name from the ACME server.\n
\nThe require parameter will cause certificate renewals\nto fail if the server does not support the specified profile.\n
| \n Syntax:\n | \n\n ssl_trusted_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n acme_issuer\n | \n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to verify the certificate\nof the ACME server.\n
| \n Syntax:\n | \n\n ssl_verify \n \n | \n
|---|---|
| \n Default:\n | \n\n ssl_verify on;\n | \n
| \n Context:\n | \n\n acme_issuer\n | \n
\nEnables or disables verification of the ACME server certificate.\n
| \n Syntax:\n | \n\n state_path \n | \n
|---|---|
| \n Default:\n | \n\n state_path acme_<issuer>;\n | \n
| \n Context:\n | \n\n acme_issuer\n | \n
\nDefines a directory for storing the module data\nthat can be persisted across restarts.\nThis can improve the load time by skipping some requests on startup,\nand avoid hitting request rate limits on the ACME server.\n
\nThe directory contains sensitive content, such as\nthe account key, issued certificates, and private keys.\n
\nThe off parameter (0.2.0) disables storing the account\ninformation and issued certificates on disk.\n
\n
\nPrior to version 0.2.0, the state directory was not created by default.\n
\n
| \n Syntax:\n | \n\n accept_terms_of_service;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n acme_issuer\n | \n
\nAgrees to the terms of service under which the ACME server will be used.\nSome servers require accepting the terms of service\nbefore account registration.\nThe terms are usually available on the ACME server's website,\nand the URL will be printed to the error log if necessary.\n
| \n Syntax:\n | \n\n acme_shared_zone \n \n | \n
|---|---|
| \n Default:\n | \n\n acme_shared_zone zone=ngx_acme_shared:256k;\n | \n
| \n Context:\n | \n\n http\n | \n
\nAllows increasing the size of in-memory storage of the module.\nThe shared memory zone will be used to store the issued certificates,\nkeys and challenge data for all the configured certificate issuers.\n
\nThe default zone size is sufficient to hold approximately\n50 ECDSA prime256v1 keys or 35 RSA 2048 keys.\n
| \n Syntax:\n | \n\n acme_certificate \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server\n | \n
\nDefines a certificate with the list of identifiers\nrequested from issuer issuer.\n
\nThe explicit list of identifiers can be omitted.\nIn this case, the identifiers will be taken from the\nserver_name directive\nin the same server block.\nNot all values accepted in the server_name\nare valid certificate identifiers:\nregular expressions and wildcards are not supported.\n
\nThe key parameter sets the type of a generated private key.\nSupported key algorithms and sizes:\necdsa:256 (default),\necdsa:384,\necdsa:521,\nrsa:2048,\nrsa:3072,\nrsa:4096.\n
\nThe ngx_http_acme_module module supports embedded variables,\nvalid in the\nserver block with the\nacme_certificate directive:\n
\n
$acme_certificate$acme_certificate_key\n
\n\n| Example Configuration Directives add_before_body add_after_body addition_types |
\nThe ngx_http_addition_module module is a filter\nthat adds text before and after a response.\nThis module is not built by default, it should be enabled with the\n--with-http_addition_module\nconfiguration parameter.\n
\n
\nlocation / {\n add_before_body /before_action;\n add_after_body /after_action;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n add_before_body \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nAdds the text returned as a result of processing a given subrequest\nbefore the response body.\nAn empty string (\"\") as a parameter cancels addition\ninherited from the previous configuration level.\n
| \n Syntax:\n | \n\n add_after_body \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nAdds the text returned as a result of processing a given subrequest\nafter the response body.\nAn empty string (\"\") as a parameter cancels addition\ninherited from the previous configuration level.\n
| \n Syntax:\n | \n\n addition_types \n | \n
|---|---|
| \n Default:\n | \n\n addition_types text/html;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.9.\n
\nAllows adding text in responses with the specified MIME types,\nin addition to “text/html”.\nThe special value “*” matches any MIME type (0.8.29).\n
\nThe ngx_http_api_module module (1.13.3) provides REST API\nfor accessing various status information,\nconfiguring upstream server groups on-the-fly, and managing\nkey-value pairs\nwithout the need of reconfiguring nginx.\n
\n
\nThe module supersedes the\nngx_http_status_module and\nngx_http_upstream_conf_module\nmodules.\n
\n
\nWhen using the PATCH or POST methods,\nmake sure that the payload does not exceed the\nbuffer size\nfor reading the client request body, otherwise, the\n413 (Request Entity Too Large)\nerror may be returned.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nhttp {\n upstream backend {\n zone http_backend 64k;\n\n server backend1.example.com weight=5;\n server backend2.example.com;\n }\n\n proxy_cache_path /data/nginx/cache_backend keys_zone=cache_backend:10m;\n\n server {\n server_name backend.example.com;\n\n location / {\n proxy_pass http://backend;\n proxy_cache cache_backend;\n\n health_check;\n }\n\n status_zone server_backend;\n }\n\n keyval_zone zone=one:32k state=one.keyval;\n keyval $arg_text $text zone=one;\n\n server {\n listen 127.0.0.1;\n\n location /api {\n api write=on;\n allow 127.0.0.1;\n deny all;\n }\n }\n}\n\nstream {\n upstream backend {\n zone stream_backend 64k;\n\n server backend1.example.com:12345 weight=5;\n server backend2.example.com:12345;\n }\n\n server {\n listen 127.0.0.1:12345;\n proxy_pass backend;\n status_zone server_backend;\n health_check;\n }\n}\n\nAll API requests include\na supported API version in the URI.\nExamples of API requests with this configuration:\n
\nhttp://127.0.0.1/api/9/\nhttp://127.0.0.1/api/9/nginx\nhttp://127.0.0.1/api/9/connections\nhttp://127.0.0.1/api/9/workers\nhttp://127.0.0.1/api/9/http/requests\nhttp://127.0.0.1/api/9/http/server_zones/server_backend\nhttp://127.0.0.1/api/9/http/caches/cache_backend\nhttp://127.0.0.1/api/9/http/upstreams/backend\nhttp://127.0.0.1/api/9/http/upstreams/backend/servers/\nhttp://127.0.0.1/api/9/http/upstreams/backend/servers/1\nhttp://127.0.0.1/api/9/http/keyvals/one?key=arg1\nhttp://127.0.0.1/api/9/stream/\nhttp://127.0.0.1/api/9/stream/server_zones/server_backend\nhttp://127.0.0.1/api/9/stream/upstreams/\nhttp://127.0.0.1/api/9/stream/upstreams/backend\nhttp://127.0.0.1/api/9/stream/upstreams/backend/servers/1\n
\n
\n\n\n| \n Syntax:\n | \n\n api \n[\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nTurns on the REST API interface in the surrounding location.\nAccess to this location should be\nlimited.\n
\nThe write parameter determines whether the API\nis read-only or read-write.\nBy default, the API is read-only.\n
\nAll API requests should contain a supported API version in the URI.\nIf the request URI equals the location prefix,\nthe list of supported API versions is returned.\nThe current API version is “9”.\n
\nThe optional “fields” argument in the request line\nspecifies which fields of the requested objects will be output:\n
\nhttp://127.0.0.1/api/9/nginx?fields=version,build\n
\n
| \n Syntax:\n | \n\n status_zone \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server, location, if in location\n | \n
This directive appeared in version 1.13.12.\n
\nEnables collection of virtual\nhttp\nor\nstream\nserver status information in the specified zone.\nSeveral servers may share the same zone.\n
\nStarting from 1.17.0, status information can be collected\nper location.\nThe special value off disables statistics collection\nin nested location blocks.\nNote that the statistics is collected\nin the context of a location where processing ends.\nIt may be different from the original location, if an\ninternal\nredirect happens during request processing.\n
\n
response_time_hist” data\nfor each HTTP\nupstream\nwere added in version 9 (1.29.8).\nuuid” field was added\nto the /license data\nin version 9 (1.29.0).\nssl data\nfor each HTTP\nupstream,\nserver zone,\nand stream\nupstream,\nserver zone,\nwere added in version 8 (1.21.6).\ncodes data\nin responses for each HTTP\nupstream,\nserver zone, and\nlocation zone\nwere added in version 7.\nexpire” parameter of a\nkey-value pair can be\nset or\nchanged\nsince version 5.\npath and method fields of\nnginx error object\nwere removed in version 4.\nThese fields continue to exist in earlier api versions,\nbut show an empty value.\n\n
\n\n\n
/\nSupported methods:
\nGET - Return list of root endpoints\nReturns a list of root endpoints.
\n\nPossible responses:\n
\nUnknownVersion), returns Error/nginx\nSupported methods:
\nGET - Return status of nginx running instance\nReturns nginx version, build name, address, number of configuration reloads, IDs of master and worker processes.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\n\n/processes\nSupported methods:
\nGET - Return nginx processes status\nReturns the number of abnormally terminated and respawned child processes.
\n\nPossible responses:\n
\n\nDELETE - Reset nginx processes statistics\nResets counters of abnormally terminated and respawned child processes.
\n\nPossible responses:\n
\n\n/connections\nSupported methods:
\nGET - Return client connections statistics\nReturns statistics of client connections.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nUnknownVersion), returns ErrorDELETE - Reset client connections statistics\nResets statistics of accepted and dropped client connections.
\n\nPossible responses:\n
\n\n/slabs/\nSupported methods:
\nGET - Return status of all slabs\nReturns status of slabs for each shared memory zone with slab allocator.
\n\nRequest parameters:\n
fields\n(string, optional)fields” value is empty, then only zone names will be output.\n
\n\nPossible responses:\n
\nUnknownVersion), returns Error/slabs/{slabZoneName}\nslabZoneName\n(string, required)Supported methods:
\nGET - Return status of a slab\nReturns status of slabs for a particular shared memory zone with slab allocator.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nSlabNotFound),\nunknown version (UnknownVersion), returns ErrorDELETE - Reset slab statistics\nResets the “reqs” and “fails” metrics for each memory slot.
\nPossible responses:\n
\n\n/http/\nSupported methods:
\nGET - Return list of HTTP-related endpoints\nReturns a list of first level HTTP endpoints.
\n\nPossible responses:\n
\nUnknownVersion), returns Error/http/requests\nSupported methods:
\nGET - Return HTTP requests statistics\nReturns status of client HTTP requests.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nUnknownVersion), returns ErrorDELETE - Reset HTTP requests statistics\nResets the number of total client HTTP requests.
\n\nPossible responses:\n
\n\n/http/server_zones/\nSupported methods:
\nGET - Return status of all HTTP server zones\nReturns status information for each HTTP server zone.
\n\nRequest parameters:\n
fields\n(string, optional)fields” value is empty, then only server zone names will be output.\n
\n\nPossible responses:\n
\nUnknownVersion), returns Error/http/server_zones/{httpServerZoneName}\nhttpServerZoneName\n(string, required)Supported methods:
\nGET - Return status of an HTTP server zone\nReturns status of a particular HTTP server zone.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nServerZoneNotFound),\nunknown version (UnknownVersion), returns ErrorDELETE - Reset statistics for an HTTP server zone\nResets statistics of accepted and discarded requests, responses, received and sent bytes, counters of SSL handshakes and session reuses in a particular HTTP server zone.
\n\nPossible responses:\n
\n\n/http/location_zones/\nSupported methods:
\nGET - Return status of all HTTP location zones\nReturns status information for each HTTP location zone.
\n\nRequest parameters:\n
fields\n(string, optional)fields” value is empty, then only zone names will be output.\n
\n\nPossible responses:\n
\nUnknownVersion), returns Error/http/location_zones/{httpLocationZoneName}\nhttpLocationZoneName\n(string, required)Supported methods:
\nGET - Return status of an HTTP location zone\nReturns status of a particular HTTP location zone.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nLocationZoneNotFound),\nunknown version (UnknownVersion), returns ErrorDELETE - Reset statistics for a location zone.\nResets statistics of accepted and discarded requests, responses, received and sent bytes in a particular location zone.
\n\nPossible responses:\n
\n\n/http/caches/\nSupported methods:
\nGET - Return status of all caches\nReturns status of each cache configured by proxy_cache_path and other “*_cache_path” directives.
\nRequest parameters:\n
fields\n(string, optional)fields” value is empty, then only names of cache zones will be output.\n
\n\nPossible responses:\n
\nUnknownVersion), returns Error/http/caches/{httpCacheZoneName}\nhttpCacheZoneName\n(string, required)Supported methods:
\nGET - Return status of a cache\nReturns status of a particular cache.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nCacheNotFound),\nunknown version (UnknownVersion), returns ErrorDELETE - Reset cache statistics\nResets statistics of cache hits/misses in a particular cache zone.
\n\nPossible responses:\n
\n\n/http/limit_conns/\nSupported methods:
\nGET - Return status of all HTTP limit_conn zones\nReturns status information for each HTTP limit_conn zone.
\n\nRequest parameters:\n
fields\n(string, optional)fields” value is empty, then only zone names will be output.\n
\n\nPossible responses:\n
\nUnknownVersion), returns Error/http/limit_conns/{httpLimitConnZoneName}\nhttpLimitConnZoneName\n(string, required)Supported methods:
\nGET - Return status of an HTTP limit_conn zone\nReturns status of a particular HTTP limit_conn zone.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nLimitConnNotFound),\nunknown version (UnknownVersion), returns ErrorDELETE - Reset statistics for an HTTP limit_conn zone\nResets the connection limiting statistics.
\n\nPossible responses:\n
\n\n/http/limit_reqs/\nSupported methods:
\nGET - Return status of all HTTP limit_req zones\nReturns status information for each HTTP limit_req zone.
\n\nRequest parameters:\n
fields\n(string, optional)fields” value is empty, then only zone names will be output.\n
\n\nPossible responses:\n
\nUnknownVersion), returns Error/http/limit_reqs/{httpLimitReqZoneName}\nhttpLimitReqZoneName\n(string, required)Supported methods:
\nGET - Return status of an HTTP limit_req zone\nReturns status of a particular HTTP limit_req zone.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nLimitReqNotFound),\nunknown version (UnknownVersion), returns ErrorDELETE - Reset statistics for an HTTP limit_req zone\nResets the requests limiting statistics.
\n\nPossible responses:\n
\n\n/http/upstreams/\nSupported methods:
\nGET - Return status of all HTTP upstream server groups\nReturns status of each HTTP upstream server group and its servers.
\n\nRequest parameters:\n
fields\n(string, optional)fields” value is empty, only names of upstreams will be output.\n
\n\nPossible responses:\n
\nUnknownVersion), returns Error/http/upstreams/{httpUpstreamName}/\nhttpUpstreamName\n(string, required)Supported methods:
\nGET - Return status of an HTTP upstream server group\nReturns status of a particular HTTP upstream server group and its servers.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nUpstreamStatic), returns ErrorUnknownVersion),\nupstream not found (UpstreamNotFound), returns ErrorDELETE - Reset statistics of an HTTP upstream server group\nResets the statistics for each upstream server in an upstream server group and queue statistics.
\n\nPossible responses:\n
\n\n/http/upstreams/{httpUpstreamName}/servers/\nhttpUpstreamName\n(string, required)Supported methods:
\nGET - Return configuration of all servers in an HTTP upstream server group\nReturns configuration of each server in a particular HTTP upstream server group.
\n\nPossible responses:\n
\nUpstreamStatic), returns ErrorUnknownVersion),\nupstream not found (UpstreamNotFound), returns ErrorPOST - Add a server to an HTTP upstream server group\nAdds a new server to an HTTP upstream server group. Server parameters are specified in the JSON format.
\n\nRequest parameters:\n
postHttpUpstreamServer\n(HTTP Upstream Server, required)ID”, “backup”, and “service” parameters cannot be changed.\n
\n\nPossible responses:\n
\nUpstreamStatic),\ninvalid “parameter” value (UpstreamConfFormatError),\nmissing “server” argument (UpstreamConfFormatError),\nunknown parameter “name” (UpstreamConfFormatError),\nnested object or list (UpstreamConfFormatError),\n“error” while parsing (UpstreamBadAddress),\nservice upstream “host” may not have port (UpstreamBadAddress),\nservice upstream “host” requires domain name (UpstreamBadAddress),\ninvalid “weight” (UpstreamBadWeight),\ninvalid “max_conns” (UpstreamBadMaxConns),\ninvalid “max_fails” (UpstreamBadMaxFails),\ninvalid “fail_timeout” (UpstreamBadFailTimeout),\ninvalid “slow_start” (UpstreamBadSlowStart),\nreading request body failed BodyReadError),\nroute is too long (UpstreamBadRoute),\n“service” is empty (UpstreamBadService),\nno resolver defined to resolve (UpstreamConfNoResolver),\nupstream “name” has no backup (UpstreamNoBackup),\nupstream “name” memory exhausted (UpstreamOutOfMemory), returns ErrorUnknownVersion),\nupstream not found (UpstreamNotFound), returns ErrorMethodDisabled), returns ErrorEntryExists), returns ErrorJsonError), returns Error/http/upstreams/{httpUpstreamName}/servers/{httpUpstreamServerId}\nhttpUpstreamName\n(string, required)httpUpstreamServerId\n(string, required)Supported methods:
\nGET - Return configuration of a server in an HTTP upstream server group\nReturns configuration of a particular server in the HTTP upstream server group.
\n\nPossible responses:\n
\nUpstreamStatic),\ninvalid server ID (UpstreamBadServerId), returns Errorid” does not exist (UpstreamServerNotFound),\nunknown version (UnknownVersion),\nupstream not found (UpstreamNotFound), returns ErrorPATCH - Modify a server in an HTTP upstream server group\nModifies settings of a particular server in an HTTP upstream server group. Server parameters are specified in the JSON format.
\n\nRequest parameters:\n
patchHttpUpstreamServer\n(HTTP Upstream Server, required)ID”, “backup”, and “service” parameters cannot be changed.\n
\n\nPossible responses:\n
\nUpstreamStatic),\ninvalid “parameter” value (UpstreamConfFormatError),\nunknown parameter “name” (UpstreamConfFormatError),\nnested object or list (UpstreamConfFormatError),\n“error” while parsing (UpstreamBadAddress),\ninvalid “server” argument (UpstreamBadAddress),\ninvalid server ID (UpstreamBadServerId),\ninvalid “weight” (UpstreamBadWeight),\ninvalid “max_conns” (UpstreamBadMaxConns),\ninvalid “max_fails” (UpstreamBadMaxFails),\ninvalid “fail_timeout” (UpstreamBadFailTimeout),\ninvalid “slow_start” (UpstreamBadSlowStart),\nreading request body failed BodyReadError),\nroute is too long (UpstreamBadRoute),\n“service” is empty (UpstreamBadService),\nserver “ID” address is immutable (UpstreamServerImmutable),\nserver “ID” weight is immutable (UpstreamServerWeightImmutable),\nupstream “name” memory exhausted (UpstreamOutOfMemory), returns Errorid” does not exist (UpstreamServerNotFound),\nunknown version (UnknownVersion),\nupstream not found (UpstreamNotFound), returns ErrorMethodDisabled), returns ErrorJsonError), returns ErrorDELETE - Remove a server from an HTTP upstream server group\nRemoves a server from an HTTP upstream server group.
\n\nPossible responses:\n
\nUpstreamStatic),\ninvalid server ID (UpstreamBadServerId),\nserver “id” not removable (UpstreamServerImmutable), returns Errorid” does not exist (UpstreamServerNotFound),\nunknown version (UnknownVersion),\nupstream not found (UpstreamNotFound), returns ErrorMethodDisabled), returns Error/http/keyvals/\nSupported methods:
\nGET - Return key-value pairs from all HTTP keyval zones\nReturns key-value pairs for each HTTP keyval shared memory zone.
\n\nRequest parameters:\n
fields\n(string, optional)fields” value is empty, then only HTTP keyval zone names will be output.\n
\n\nPossible responses:\n
\nUnknownVersion), returns Error/http/keyvals/{httpKeyvalZoneName}\nhttpKeyvalZoneName\n(string, required)Supported methods:
\nGET - Return key-value pairs from an HTTP keyval zone\nReturns key-value pairs stored in a particular HTTP keyval shared memory zone.
\n\nRequest parameters:\n
key\n(string, optional)\n
\n\nPossible responses:\n
\nKeyvalNotFound),\nkeyval key not found (KeyvalKeyNotFound),\nunknown version (UnknownVersion), returns ErrorPOST - Add a key-value pair to the HTTP keyval zone\nAdds a new key-value pair to the HTTP keyval shared memory zone. Several key-value pairs can be entered if the HTTP keyval shared memory zone is empty.
\n\nRequest parameters:\n
Key-value\n(HTTP Keyval Shared Memory Zone, required)expire parameter which overrides the timeout parameter of the keyval_zone directive.\n
\n\nPossible responses:\n
\nKeyvalFormatError),\ninvalid key format (KeyvalFormatError),\nkey required (KeyvalFormatError),\nkeyval timeout is not enabled (KeyvalFormatError),\nonly one key can be added (KeyvalFormatError),\nreading request body failed BodyReadError), returns ErrorKeyvalNotFound),\nunknown version (UnknownVersion), returns ErrorMethodDisabled), returns ErrorEntryExists),\nkey already exists (KeyvalKeyExists), returns ErrorJsonError), returns ErrorPATCH - Modify a key-value or delete a key\nChanges the value of the selected key in the key-value pair, deletes a key by setting the key value to null, changes expiration time of a key-value pair. If synchronization of keyval zones in a cluster is enabled, deletes a key only on a target cluster node. Expiration time in milliseconds can be specified for a key-value pair with the expire parameter which overrides the timeout parameter of the keyval_zone directive.
\nRequest parameters:\n
httpKeyvalZoneKeyValue\n(HTTP Keyval Shared Memory Zone, required)\n
\n\nPossible responses:\n
\nKeyvalFormatError),\nkey required (KeyvalFormatError),\nkeyval timeout is not enabled (KeyvalFormatError),\nonly one key can be updated (KeyvalFormatError),\nreading request body failed BodyReadError), returns ErrorKeyvalNotFound),\nkeyval key not found (KeyvalKeyNotFound),\nunknown version (UnknownVersion), returns ErrorMethodDisabled), returns ErrorJsonError), returns ErrorDELETE - Empty the HTTP keyval zone\nDeletes all key-value pairs from the HTTP keyval shared memory zone. If synchronization of keyval zones in a cluster is enabled, empties the keyval zone only on a target cluster node.
\n\nPossible responses:\n
\n\n/stream/\nSupported methods:
\nGET - Return list of stream-related endpoints\nReturns a list of first level stream endpoints.
\n\nPossible responses:\n
\nUnknownVersion), returns Error/stream/server_zones/\nSupported methods:
\nGET - Return status of all stream server zones\nReturns status information for each stream server zone.
\n\nRequest parameters:\n
fields\n(string, optional)fields” value is empty, then only server zone names will be output.\n
\n\nPossible responses:\n
\nUnknownVersion), returns Error/stream/server_zones/{streamServerZoneName}\nstreamServerZoneName\n(string, required)Supported methods:
\nGET - Return status of a stream server zone\nReturns status of a particular stream server zone.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nServerZoneNotFound),\nunknown version (UnknownVersion), returns ErrorDELETE - Reset statistics for a stream server zone\nResets statistics of accepted and discarded connections, sessions, received and sent bytes, counters of SSL handshakes and session reuses in a particular stream server zone.
\n\nPossible responses:\n
\n\n/stream/limit_conns/\nSupported methods:
\nGET - Return status of all stream limit_conn zones\nReturns status information for each stream limit_conn zone.
\n\nRequest parameters:\n
fields\n(string, optional)fields” value is empty, then only zone names will be output.\n
\n\nPossible responses:\n
\nUnknownVersion), returns Error/stream/limit_conns/{streamLimitConnZoneName}\nstreamLimitConnZoneName\n(string, required)Supported methods:
\nGET - Return status of an stream limit_conn zone\nReturns status of a particular stream limit_conn zone.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nLimitConnNotFound),\nunknown version (UnknownVersion), returns ErrorDELETE - Reset statistics for a stream limit_conn zone\nResets the connection limiting statistics.
\n\nPossible responses:\n
\n\n/stream/upstreams/\nSupported methods:
\nGET - Return status of all stream upstream server groups\nReturns status of each stream upstream server group and its servers.
\n\nRequest parameters:\n
fields\n(string, optional)fields” value is empty, only names of upstreams will be output.\n
\n\nPossible responses:\n
\nUnknownVersion), returns Error/stream/upstreams/{streamUpstreamName}/\nstreamUpstreamName\n(string, required)Supported methods:
\nGET - Return status of a stream upstream server group\nReturns status of a particular stream upstream server group and its servers.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nUpstreamStatic), returns ErrorUnknownVersion),\nupstream not found (UpstreamNotFound), returns ErrorDELETE - Reset statistics of a stream upstream server group\nResets the statistics for each upstream server in an upstream server group.
\n\nPossible responses:\n
\n\n/stream/upstreams/{streamUpstreamName}/servers/\nstreamUpstreamName\n(string, required)Supported methods:
\nGET - Return configuration of all servers in a stream upstream server group\nReturns configuration of each server in a particular stream upstream server group.
\n\nPossible responses:\n
\nUpstreamStatic), returns ErrorUnknownVersion),\nupstream not found (UpstreamNotFound), returns ErrorPOST - Add a server to a stream upstream server group\nAdds a new server to a stream upstream server group. Server parameters are specified in the JSON format.
\n\nRequest parameters:\n
postStreamUpstreamServer\n(Stream Upstream Server, required)ID”, “backup”, and “service” parameters cannot be changed.\n
\n\nPossible responses:\n
\nUpstreamStatic),\ninvalid “parameter” value (UpstreamConfFormatError),\nmissing “server” argument (UpstreamConfFormatError),\nunknown parameter “name” (UpstreamConfFormatError),\nnested object or list (UpstreamConfFormatError),\n“error” while parsing (UpstreamBadAddress),\nno port in server “host” (UpstreamBadAddress),\nservice upstream “host” may not have port (UpstreamBadAddress),\nservice upstream “host” requires domain name (UpstreamBadAddress),\ninvalid “weight” (UpstreamBadWeight),\ninvalid “max_conns” (UpstreamBadMaxConns),\ninvalid “max_fails” (UpstreamBadMaxFails),\ninvalid “fail_timeout” (UpstreamBadFailTimeout),\ninvalid “slow_start” (UpstreamBadSlowStart),\n“service” is empty (UpstreamBadService),\nno resolver defined to resolve (UpstreamConfNoResolver),\nupstream “name” has no backup (UpstreamNoBackup),\nupstream “name” memory exhausted (UpstreamOutOfMemory),\nreading request body failed BodyReadError), returns ErrorUnknownVersion),\nupstream not found (UpstreamNotFound), returns ErrorMethodDisabled), returns ErrorEntryExists), returns ErrorJsonError), returns Error/stream/upstreams/{streamUpstreamName}/servers/{streamUpstreamServerId}\nstreamUpstreamName\n(string, required)streamUpstreamServerId\n(string, required)Supported methods:
\nGET - Return configuration of a server in a stream upstream server group\nReturns configuration of a particular server in the stream upstream server group.
\n\nPossible responses:\n
\nUpstreamStatic),\ninvalid server ID (UpstreamBadServerId), returns ErrorUnknownVersion),\nupstream not found (UpstreamNotFound),\nserver with ID “id” does not exist (UpstreamServerNotFound), returns ErrorPATCH - Modify a server in a stream upstream server group\nModifies settings of a particular server in a stream upstream server group. Server parameters are specified in the JSON format.
\n\nRequest parameters:\n
patchStreamUpstreamServer\n(Stream Upstream Server, required)ID”, “backup”, and “service” parameters cannot be changed.\n
\n\nPossible responses:\n
\nUpstreamStatic),\ninvalid “parameter” value (UpstreamConfFormatError),\nunknown parameter “name” (UpstreamConfFormatError),\nnested object or list (UpstreamConfFormatError),\n“error” while parsing (UpstreamBadAddress),\ninvalid “server” argument (UpstreamBadAddress),\nno port in server “host” (UpstreamBadAddress),\ninvalid server ID (UpstreamBadServerId),\ninvalid “weight” (UpstreamBadWeight),\ninvalid “max_conns” (UpstreamBadMaxConns),\ninvalid “max_fails” (UpstreamBadMaxFails),\ninvalid “fail_timeout” (UpstreamBadFailTimeout),\ninvalid “slow_start” (UpstreamBadSlowStart),\nreading request body failed BodyReadError),\n“service” is empty (UpstreamBadService),\nserver “ID” address is immutable (UpstreamServerImmutable),\nserver “ID” weight is immutable (UpstreamServerWeightImmutable),\nupstream “name” memory exhausted (UpstreamOutOfMemory), returns Errorid” does not exist (UpstreamServerNotFound),\nunknown version (UnknownVersion),\nupstream not found (UpstreamNotFound), returns ErrorMethodDisabled), returns ErrorJsonError), returns ErrorDELETE - Remove a server from a stream upstream server group\nRemoves a server from a stream server group.
\n\nPossible responses:\n
\nUpstreamStatic),\ninvalid server ID (UpstreamBadServerId),\nserver “id” not removable (UpstreamServerImmutable), returns Errorid” does not exist (UpstreamServerNotFound),\nunknown version (UnknownVersion),\nupstream not found (UpstreamNotFound), returns ErrorMethodDisabled), returns Error/stream/keyvals/\nSupported methods:
\nGET - Return key-value pairs from all stream keyval zones\nReturns key-value pairs for each stream keyval shared memory zone.
\n\nRequest parameters:\n
fields\n(string, optional)fields” value is empty, then only stream keyval zone names will be output.\n
\n\nPossible responses:\n
\nUnknownVersion), returns Error/stream/keyvals/{streamKeyvalZoneName}\nstreamKeyvalZoneName\n(string, required)Supported methods:
\nGET - Return key-value pairs from a stream keyval zone\nReturns key-value pairs stored in a particular stream keyval shared memory zone.
\n\nRequest parameters:\n
key\n(string, optional)\n
\n\nPossible responses:\n
\nKeyvalNotFound),\nkeyval key not found (KeyvalKeyNotFound),\nunknown version (UnknownVersion), returns ErrorPOST - Add a key-value pair to the stream keyval zone\nAdds a new key-value pair to the stream keyval shared memory zone. Several key-value pairs can be entered if the stream keyval shared memory zone is empty.
\n\nRequest parameters:\n
Key-value\n(Stream Keyval Shared Memory Zone, required)expire parameter which overrides the timeout parameter of the keyval_zone directive.\n
\n\nPossible responses:\n
\nKeyvalFormatError),\ninvalid key format (KeyvalFormatError),\nkey required (KeyvalFormatError),\nkeyval timeout is not enabled (KeyvalFormatError),\nonly one key can be added (KeyvalFormatError),\nreading request body failed BodyReadError), returns ErrorKeyvalNotFound),\nunknown version (UnknownVersion), returns ErrorMethodDisabled), returns ErrorEntryExists),\nkey already exists (KeyvalKeyExists), returns ErrorJsonError), returns ErrorPATCH - Modify a key-value or delete a key\nChanges the value of the selected key in the key-value pair, deletes a key by setting the key value to null, changes expiration time of a key-value pair. If synchronization of keyval zones in a cluster is enabled, deletes a key only on a target cluster node. Expiration time is specified in milliseconds with the expire parameter which overrides the timeout parameter of the keyval_zone directive.
\nRequest parameters:\n
streamKeyvalZoneKeyValue\n(Stream Keyval Shared Memory Zone, required)\n
\n\nPossible responses:\n
\nKeyvalFormatError),\nkey required (KeyvalFormatError),\nkeyval timeout is not enabled (KeyvalFormatError),\nonly one key can be updated (KeyvalFormatError),\nreading request body failed BodyReadError), returns ErrorKeyvalNotFound),\nkeyval key not found (KeyvalKeyNotFound),\nunknown version (UnknownVersion), returns ErrorMethodDisabled), returns ErrorJsonError), returns ErrorDELETE - Empty the stream keyval zone\nDeletes all key-value pairs from the stream keyval shared memory zone. If synchronization of keyval zones in a cluster is enabled, empties the keyval zone only on a target cluster node.
\n\nPossible responses:\n
\n\n/stream/zone_sync/\nSupported methods:
\nGET - Return sync status of a node\nReturns synchronization status of a cluster node.
\n\nPossible responses:\n
\nUnknownVersion), returns Error/resolvers/\nSupported methods:
\nGET - Return status for all resolver zones\nReturns status information for each resolver zone.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nUnknownVersion), returns Error/resolvers/{resolverZoneName}\nresolverZoneName\n(string, required)Supported methods:
\nGET - Return statistics of a resolver zone\nReturns statistics stored in a particular resolver zone.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nResolverZoneNotFound),\nunknown version (UnknownVersion), returns ErrorDELETE - Reset statistics for a resolver zone.\nResets statistics in a particular resolver zone.
\n\nPossible responses:\n
\n\n/ssl\nSupported methods:
\nGET - Return SSL statistics\nReturns SSL statistics.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\n\nDELETE - Reset SSL statistics\nResets counters of SSL handshakes and session reuses.
\n\nPossible responses:\n
\n\n/license\nSupported methods:
\n\n/workers/\nSupported methods:
\nGET - Return statistics for all worker processes\nReturns statistics for all worker processes such as accepted, dropped, active, idle connections, total and current requests.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nWorkerNotFound),\nunknown version (UnknownVersion), returns ErrorDELETE - Reset statistics for all worker processes.\nResets statistics for all worker processes such as\naccepted, dropped, active, idle connections, total and current requests.
\n\nPossible responses:\n
\n\n/workers/{workerId}\nworkerId\n(string, required)Supported methods:
\nGET - Return status of a worker process\nReturns status of a particular worker process.
\n\nRequest parameters:\n
fields\n(string, optional)\n
\n\nPossible responses:\n
\nWorkerNotFound),\nunknown version (UnknownVersion), returns ErrorDELETE - Reset statistics for a worker process.\nResets statistics of accepted, dropped, active, idle connections,\nas well as total and current requests.
\n\nPossible responses:\n
\n\n\n
\n\n
nginx:
\nGeneral information about nginx:version (string)\nbuild (string)\naddress (string)\ngeneration (integer)\nload_timestamp (string)\ntimestamp (string)\npid (integer)\nppid (integer)\nExample:
\n\n{\n \"nginx\" : {\n \"version\" : \"1.21.6\",\n \"build\" : \"nginx-plus-r27\",\n \"address\" : \"206.251.255.64\",\n \"generation\" : 6,\n \"load_timestamp\" : \"2022-06-28T11:15:44.467Z\",\n \"timestamp\" : \"2022-06-28T09:26:07.305Z\",\n \"pid\" : 32212,\n \"ppid\" : 32210\n }\n}\nProcesses:
\nrespawned (integer)\nExample:
\n\n{\n \"respawned\" : 0\n}\nConnections:
\nThe number of accepted, dropped, active, and idle connections.accepted (integer)\ndropped (integer)\nactive (integer)\nidle (integer)\nExample:
\n\n{\n \"accepted\" : 4968119,\n \"dropped\" : 0,\n \"active\" : 5,\n \"idle\" : 117\n}\nSSL:
\nhandshakes (integer)\nhandshakes_failed (integer)\nsession_reuses (integer)\nno_common_protocol (integer)\nno_common_cipher (integer)\nhandshake_timeout (integer)\npeer_rejected_cert (integer)\nverify_failuresno_cert (integer)\nexpired_cert (integer)\nrevoked_cert (integer)\nhostname_mismatch (integer)\nother (integer)\nExample:
\n\n{\n \"handshakes\" : 79572,\n \"handshakes_failed\" : 21025,\n \"session_reuses\" : 15762,\n \"no_common_protocol\" : 4,\n \"no_common_cipher\" : 2,\n \"handshake_timeout\" : 0,\n \"peer_rejected_cert\" : 0,\n \"verify_failures\" : {\n \"no_cert\" : 0,\n \"expired_cert\" : 2,\n \"revoked_cert\" : 1,\n \"hostname_mismatch\" : 2,\n \"other\" : 1\n }\n}\nShared memory zone with slab allocator:
\nShared memory zone with slab allocatorpagesused (integer)\nfree (integer)\nslotsStatus data for memory slots (8, 16, 32, 64, 128, etc.)
A collection of \"Memory Slot\" objects
\nExample:
\n\n{\n \"pages\" : {\n \"used\" : 1143,\n \"free\" : 2928\n },\n \"slots\" : {\n \"8\" : {\n \"used\" : 0,\n \"free\" : 0,\n \"reqs\" : 0,\n \"fails\" : 0\n },\n \"16\" : {\n \"used\" : 0,\n \"free\" : 0,\n \"reqs\" : 0,\n \"fails\" : 0\n },\n \"32\" : {\n \"used\" : 0,\n \"free\" : 0,\n \"reqs\" : 0,\n \"fails\" : 0\n },\n \"64\" : {\n \"used\" : 1,\n \"free\" : 63,\n \"reqs\" : 1,\n \"fails\" : 0\n },\n \"128\" : {\n \"used\" : 0,\n \"free\" : 0,\n \"reqs\" : 0,\n \"fails\" : 0\n },\n \"256\" : {\n \"used\" : 18078,\n \"free\" : 178,\n \"reqs\" : 1635736,\n \"fails\" : 0\n }\n }\n}\nMemory Slot:
\nused (integer)\nfree (integer)\nreqs (integer)\nfails (integer)\nHTTP Requests:
\ntotal (integer)\ncurrent (integer)\nExample:
\n\n{\n \"total\" : 10624511,\n \"current\" : 4\n}\nHTTP Server Zone:
\nprocessing (integer)\nrequests (integer)\nresponses1xx”, “2xx”, “3xx”, “4xx”, and “5xx”, and the number of responses per each status code.1xx (integer)\n1xx” status codes.\n2xx (integer)\n2xx” status codes.\n3xx (integer)\n3xx” status codes.\n4xx (integer)\n4xx” status codes.\n5xx (integer)\n5xx” status codes.\ncodescodeNumber (integer)\ntotal (integer)\ndiscarded (integer)\nreceived (integer)\nsent (integer)\nsslhandshakes (integer)\nhandshakes_failed (integer)\nsession_reuses (integer)\nno_common_protocol (integer)\nno_common_cipher (integer)\nhandshake_timeout (integer)\npeer_rejected_cert (integer)\nverify_failuresno_cert (integer)\nexpired_cert (integer)\nrevoked_cert (integer)\nother (integer)\nExample:
\n\n{\n \"processing\" : 1,\n \"requests\" : 706690,\n \"responses\" : {\n \"1xx\" : 0,\n \"2xx\" : 699482,\n \"3xx\" : 4522,\n \"4xx\" : 907,\n \"5xx\" : 266,\n \"codes\" : {\n \"200\" : 699482,\n \"301\" : 4522,\n \"404\" : 907,\n \"503\" : 266\n },\n \"total\" : 705177\n },\n \"discarded\" : 1513,\n \"received\" : 172711587,\n \"sent\" : 19415530115,\n \"ssl\" : {\n \"handshakes\" : 104303,\n \"handshakes_failed\" : 1421,\n \"session_reuses\" : 54645,\n \"no_common_protocol\" : 4,\n \"no_common_cipher\" : 2,\n \"handshake_timeout\" : 0,\n \"peer_rejected_cert\" : 0,\n \"verify_failures\" : {\n \"no_cert\" : 0,\n \"expired_cert\" : 2,\n \"revoked_cert\" : 1,\n \"other\" : 1\n }\n }\n}\nHTTP Location Zone:
\nrequests (integer)\nresponses1xx”, “2xx”, “3xx”, “4xx”, and “5xx”, and the number of responses per each status code.1xx (integer)\n1xx” status codes.\n2xx (integer)\n2xx” status codes.\n3xx (integer)\n3xx” status codes.\n4xx (integer)\n4xx” status codes.\n5xx (integer)\n5xx” status codes.\ncodescodeNumber (integer)\ntotal (integer)\ndiscarded (integer)\nreceived (integer)\nsent (integer)\nExample:
\n\n{\n \"requests\" : 706690,\n \"responses\" : {\n \"1xx\" : 0,\n \"2xx\" : 699482,\n \"3xx\" : 4522,\n \"4xx\" : 907,\n \"5xx\" : 266,\n \"codes\" : {\n \"200\" : 112674,\n \"301\" : 4522,\n \"404\" : 2504,\n \"503\" : 266\n },\n \"total\" : 705177\n },\n \"discarded\" : 1513,\n \"received\" : 172711587,\n \"sent\" : 19415530115\n}\nHTTP Cache:
\nsize (integer)\nmax_size (integer)\ncold (boolean)\nhitresponses (integer)\nbytes (integer)\nstaleresponses (integer)\n*_cache_use_stale” directives).\nbytes (integer)\nupdatingresponses (integer)\n*_cache_use_stale” directives).\nbytes (integer)\nrevalidatedresponses (integer)\n*_cache_revalidate” directives.\nbytes (integer)\nmissresponses (integer)\nbytes (integer)\nresponses_written (integer)\nbytes_written (integer)\nexpiredresponses (integer)\nbytes (integer)\nresponses_written (integer)\nbytes_written (integer)\nbypassresponses (integer)\n*_cache_bypass” directives.\nbytes (integer)\nresponses_written (integer)\nbytes_written (integer)\nExample:
\n\n{\n \"size\" : 530915328,\n \"max_size\" : 536870912,\n \"cold\" : false,\n \"hit\" : {\n \"responses\" : 254032,\n \"bytes\" : 6685627875\n },\n \"stale\" : {\n \"responses\" : 0,\n \"bytes\" : 0\n },\n \"updating\" : {\n \"responses\" : 0,\n \"bytes\" : 0\n },\n \"revalidated\" : {\n \"responses\" : 0,\n \"bytes\" : 0\n },\n \"miss\" : {\n \"responses\" : 1619201,\n \"bytes\" : 53841943822\n },\n \"expired\" : {\n \"responses\" : 45859,\n \"bytes\" : 1656847080,\n \"responses_written\" : 44992,\n \"bytes_written\" : 1641825173\n },\n \"bypass\" : {\n \"responses\" : 200187,\n \"bytes\" : 5510647548,\n \"responses_written\" : 200173,\n \"bytes_written\" : 44992\n }\n}\nHTTP Connections Limiting:
\npassed (integer)\nrejected (integer)\nrejected_dry_run (integer)\nExample:
\n\n{\n \"passed\" : 15,\n \"rejected\" : 0,\n \"rejected_dry_run\" : 2\n}\nHTTP Requests Rate Limiting:
\npassed (integer)\ndelayed (integer)\nrejected (integer)\ndelayed_dry_run (integer)\nrejected_dry_run (integer)\nExample:
\n\n{\n \"passed\" : 15,\n \"delayed\" : 4,\n \"rejected\" : 0,\n \"delayed_dry_run\" : 1,\n \"rejected_dry_run\" : 2\n}\nHTTP Upstream:
\npeersid (integer)\nserver (string)\nservice (string)\nname (string)\nbackup (boolean)\nweight (integer)\nstate (string)\nup”, “draining”, “down”, “unavail”, “checking”, and “unhealthy”.\nactive (integer)\nsslhandshakes (integer)\nhandshakes_failed (integer)\nsession_reuses (integer)\nno_common_protocol (integer)\nhandshake_timeout (integer)\npeer_rejected_cert (integer)\nverify_failuresexpired_cert (integer)\nrevoked_cert (integer)\nhostname_mismatch (integer)\nother (integer)\nmax_conns (integer)\nrequests (integer)\nresponses1xx (integer)\n1xx” status codes.\n2xx (integer)\n2xx” status codes.\n3xx (integer)\n3xx” status codes.\n4xx (integer)\n4xx” status codes.\n5xx (integer)\n5xx” status codes.\ncodescodeNumber (integer)\ntotal (integer)\nsent (integer)\nreceived (integer)\nfails (integer)\nunavail (integer)\nunavail”) due to the number of unsuccessful attempts reaching the max_fails threshold.\nhealth_checkschecks (integer)\nfails (integer)\nunhealthy (integer)\nunhealthy”).\nlast_passed (boolean)\ndowntime (integer)\nunavail”, “checking”, and “unhealthy” states.\ndownstart (string)\nunavail”, “checking”, or “unhealthy”, in the ISO 8601 format with millisecond resolution.\nselected (string)\nheader_time (integer)\nresponse_time (integer)\nresponse_time_histcount (integer)\nsum (integer)\nbuckets5 (integer)\n10 (integer)\n25 (integer)\n50 (integer)\n75 (integer)\n100 (integer)\n250 (integer)\n500 (integer)\n750 (integer)\n1000 (integer)\n2500 (integer)\n5000 (integer)\n7500 (integer)\n10000 (integer)\ninf (integer)\nkeepalive (integer)\nzombies (integer)\nzone (string)\nqueuesize (integer)\nmax_size (integer)\noverflows (integer)\nExample:
\n\n{\n \"upstream_backend\" : {\n \"peers\" : [\n {\n \"id\" : 0,\n \"server\" : \"10.0.0.1:8088\",\n \"name\" : \"10.0.0.1:8088\",\n \"backup\" : false,\n \"weight\" : 5,\n \"state\" : \"up\",\n \"active\" : 0,\n \"ssl\" : {\n \"handshakes\" : 620311,\n \"handshakes_failed\" : 3432,\n \"session_reuses\" : 36442,\n \"no_common_protocol\" : 4,\n \"handshake_timeout\" : 0,\n \"peer_rejected_cert\" : 0,\n \"verify_failures\" : {\n \"expired_cert\" : 2,\n \"revoked_cert\" : 1,\n \"hostname_mismatch\" : 2,\n \"other\" : 1\n }\n },\n \"max_conns\" : 20,\n \"requests\" : 667231,\n \"header_time\" : 20,\n \"response_time\" : 36,\n \"response_time_hist\" : {\n \"count\" : 9817,\n \"sum\" : 57625,\n \"buckets\" : {\n \"5\" : 4428,\n \"10\" : 4755,\n \"25\" : 350,\n \"50\" : 235,\n \"75\" : 54,\n \"100\" : 47,\n \"250\" : 1,\n \"500\" : 0,\n \"750\" : 0,\n \"1000\" : 0,\n \"2500\" : 0,\n \"5000\" : 0,\n \"7500\" : 0,\n \"10000\" : 0,\n \"inf\" : 0\n }\n },\n \"responses\" : {\n \"1xx\" : 0,\n \"2xx\" : 666310,\n \"3xx\" : 0,\n \"4xx\" : 915,\n \"5xx\" : 6,\n \"codes\" : {\n \"200\" : 666310,\n \"404\" : 915,\n \"503\" : 6\n },\n \"total\" : 667231\n },\n \"sent\" : 251946292,\n \"received\" : 19222475454,\n \"fails\" : 0,\n \"unavail\" : 0,\n \"health_checks\" : {\n \"checks\" : 26214,\n \"fails\" : 0,\n \"unhealthy\" : 0,\n \"last_passed\" : true\n },\n \"downtime\" : 0,\n \"downstart\" : \"2022-06-28T11:09:21.602Z\",\n \"selected\" : \"2022-06-28T15:01:25.000Z\"\n },\n {\n \"id\" : 1,\n \"server\" : \"10.0.0.1:8089\",\n \"name\" : \"10.0.0.1:8089\",\n \"backup\" : true,\n \"weight\" : 1,\n \"state\" : \"unhealthy\",\n \"active\" : 0,\n \"max_conns\" : 20,\n \"requests\" : 0,\n \"responses\" : {\n \"1xx\" : 0,\n \"2xx\" : 0,\n \"3xx\" : 0,\n \"4xx\" : 0,\n \"5xx\" : 0,\n \"codes\" : {\n },\n \"total\" : 0\n },\n \"sent\" : 0,\n \"received\" : 0,\n \"fails\" : 0,\n \"unavail\" : 0,\n \"health_checks\" : {\n \"checks\" : 26284,\n \"fails\" : 26284,\n \"unhealthy\" : 1,\n \"last_passed\" : false\n },\n \"downtime\" : 262925617,\n \"downstart\" : \"2022-06-28T11:09:21.602Z\",\n \"selected\" : \"2022-06-28T15:01:25.000Z\"\n }\n ],\n \"keepalive\" : 0,\n \"zombies\" : 0,\n \"zone\" : \"upstream_backend\"\n }\n}\nHTTP Upstream Server:
\nDynamically configurable parameters of an HTTP upstream\nserver:id (integer)\nserver (string)\nhttp” block. See also the resolve parameter of the HTTP upstream server.\nservice (string)\nweight (integer)\nmax_conns (integer)\nmax_fails (integer)\nfail_timeout (string)\nslow_start (string)\nroute (string)\nbackup (boolean)\ntrue, adds a backup server. This parameter cannot be changed.\ndown (boolean)\ndrain (boolean)\nparent (string)\nhost (string)\nExample:
\n\n{\n \"id\" : 1,\n \"server\" : \"10.0.0.1:8089\",\n \"weight\" : 4,\n \"max_conns\" : 0,\n \"max_fails\" : 0,\n \"fail_timeout\" : \"10s\",\n \"slow_start\" : \"10s\",\n \"route\" : \"\",\n \"backup\" : true,\n \"down\" : true\n}\nHTTP Keyval Shared Memory Zone:
\nContents of an HTTP keyval shared memory zone\nwhen using the GET method.Example:
\n\n{\n \"key1\" : \"value1\",\n \"key2\" : \"value2\",\n \"key3\" : \"value3\"\n}\nHTTP Keyval Shared Memory Zone:
\nContents of an HTTP keyval shared memory zone\nwhen using the POST or PATCH methods.Example:
\n\n{\n \"key1\" : \"value1\",\n \"key2\" : \"value2\",\n \"key3\" : {\n \"value\" : \"value3\",\n \"expire\" : 30000\n }\n}\nStream Server Zone:
\nprocessing (integer)\nconnections (integer)\nsessions2xx”, “4xx”, or “5xx”.2xx (integer)\n2xx”.\n4xx (integer)\n4xx”.\n5xx (integer)\n5xx”.\ntotal (integer)\ndiscarded (integer)\nreceived (integer)\nsent (integer)\nsslhandshakes (integer)\nhandshakes_failed (integer)\nsession_reuses (integer)\nno_common_protocol (integer)\nno_common_cipher (integer)\nhandshake_timeout (integer)\npeer_rejected_cert (integer)\nverify_failuresno_cert (integer)\nexpired_cert (integer)\nrevoked_cert (integer)\nother (integer)\nExample:
\n\n{\n \"dns\" : {\n \"processing\" : 1,\n \"connections\" : 155569,\n \"sessions\" : {\n \"2xx\" : 155564,\n \"4xx\" : 0,\n \"5xx\" : 0,\n \"total\" : 155569\n },\n \"discarded\" : 0,\n \"received\" : 4200363,\n \"sent\" : 20489184,\n \"ssl\" : {\n \"handshakes\" : 76455,\n \"handshakes_failed\" : 432,\n \"session_reuses\" : 28770,\n \"no_common_protocol\" : 4,\n \"no_common_cipher\" : 2,\n \"handshake_timeout\" : 0,\n \"peer_rejected_cert\" : 0,\n \"verify_failures\" : {\n \"no_cert\" : 0,\n \"expired_cert\" : 2,\n \"revoked_cert\" : 1,\n \"other\" : 1\n }\n }\n }\n}\nStream Connections Limiting:
\npassed (integer)\nrejected (integer)\nrejected_dry_run (integer)\nExample:
\n\n{\n \"passed\" : 15,\n \"rejected\" : 0,\n \"rejected_dry_run\" : 2\n}\nStream Upstream:
\npeersid (integer)\nserver (string)\nservice (string)\nname (string)\nbackup (boolean)\nweight (integer)\nstate (string)\nup”, “down”, “unavail”, “checking”, or “unhealthy”.\nactive (integer)\nsslhandshakes (integer)\nhandshakes_failed (integer)\nsession_reuses (integer)\nno_common_protocol (integer)\nhandshake_timeout (integer)\npeer_rejected_cert (integer)\nverify_failuresexpired_cert (integer)\nrevoked_cert (integer)\nhostname_mismatch (integer)\nother (integer)\nmax_conns (integer)\nconnections (integer)\nconnect_time (integer)\nfirst_byte_time (integer)\nresponse_time (integer)\nsent (integer)\nreceived (integer)\nfails (integer)\nunavail (integer)\nunavail”) due to the number of unsuccessful attempts reaching the max_fails threshold.\nhealth_checkschecks (integer)\nfails (integer)\nunhealthy (integer)\nunhealthy”).\nlast_passed (boolean)\ndowntime (integer)\nunavail”, “checking”, and “unhealthy” states.\ndownstart (string)\nunavail”, “checking”, or “unhealthy”, in the ISO 8601 format with millisecond resolution.\nselected (string)\nzombies (integer)\nzone (string)\nExample:
\n\n{\n \"dns\" : {\n \"peers\" : [\n {\n \"id\" : 0,\n \"server\" : \"10.0.0.1:12347\",\n \"name\" : \"10.0.0.1:12347\",\n \"backup\" : false,\n \"weight\" : 5,\n \"state\" : \"up\",\n \"active\" : 0,\n \"ssl\" : {\n \"handshakes\" : 200,\n \"handshakes_failed\" : 4,\n \"session_reuses\" : 189,\n \"no_common_protocol\" : 4,\n \"handshake_timeout\" : 0,\n \"peer_rejected_cert\" : 0,\n \"verify_failures\" : {\n \"expired_cert\" : 2,\n \"revoked_cert\" : 1,\n \"hostname_mismatch\" : 2,\n \"other\" : 1\n }\n },\n \"max_conns\" : 50,\n \"connections\" : 667231,\n \"sent\" : 251946292,\n \"received\" : 19222475454,\n \"fails\" : 0,\n \"unavail\" : 0,\n \"health_checks\" : {\n \"checks\" : 26214,\n \"fails\" : 0,\n \"unhealthy\" : 0,\n \"last_passed\" : true\n },\n \"downtime\" : 0,\n \"downstart\" : \"2022-06-28T11:09:21.602Z\",\n \"selected\" : \"2022-06-28T15:01:25.000Z\"\n },\n {\n \"id\" : 1,\n \"server\" : \"10.0.0.1:12348\",\n \"name\" : \"10.0.0.1:12348\",\n \"backup\" : true,\n \"weight\" : 1,\n \"state\" : \"unhealthy\",\n \"active\" : 0,\n \"max_conns\" : 50,\n \"connections\" : 0,\n \"sent\" : 0,\n \"received\" : 0,\n \"fails\" : 0,\n \"unavail\" : 0,\n \"health_checks\" : {\n \"checks\" : 26284,\n \"fails\" : 26284,\n \"unhealthy\" : 1,\n \"last_passed\" : false\n },\n \"downtime\" : 262925617,\n \"downstart\" : \"2022-06-28T11:09:21.602Z\",\n \"selected\" : \"2022-06-28T15:01:25.000Z\"\n }\n ],\n \"zombies\" : 0,\n \"zone\" : \"dns\"\n }\n}\nStream Upstream Server:
\nDynamically configurable parameters of a stream upstream\nserver:id (integer)\nserver (string)\nstream” block. See also the resolve parameter of the stream upstream server.\nservice (string)\nweight (integer)\nmax_conns (integer)\nmax_fails (integer)\nfail_timeout (string)\nslow_start (string)\nbackup (boolean)\ntrue, adds a backup server. This parameter cannot be changed.\ndown (boolean)\nparent (string)\nhost (string)\nExample:
\n\n{\n \"id\" : 0,\n \"server\" : \"10.0.0.1:12348\",\n \"weight\" : 1,\n \"max_conns\" : 0,\n \"max_fails\" : 1,\n \"fail_timeout\" : \"10s\",\n \"slow_start\" : 0,\n \"backup\" : false,\n \"down\" : false\n}\nStream Keyval Shared Memory Zone:
\nContents of a stream keyval shared memory zone when using the GET method.Example:
\n\n{\n \"key1\" : \"value1\",\n \"key2\" : \"value2\",\n \"key3\" : \"value3\"\n}\nStream Keyval Shared Memory Zone:
\nContents of a stream keyval shared memory zone\nwhen using the POST or PATCH methods.Example:
\n\n{\n \"key1\" : \"value1\",\n \"key2\" : \"value2\",\n \"key3\" : {\n \"value\" : \"value3\",\n \"expire\" : 30000\n }\n}\nStream Zone Sync Node:
\nzonesSynchronization information per each shared memory zone.
A collection of \"Sync Zone\" objects
\nstatusbytes_in (integer)\nmsgs_in (integer)\nmsgs_out (integer)\nbytes_out (integer)\nnodes_online (integer)\nExample:
\n\n{\n \"zones\" : {\n \"zone1\" : {\n \"records_pending\" : 2061,\n \"records_total\" : 260575\n },\n \"zone2\" : {\n \"records_pending\" : 0,\n \"records_total\" : 14749\n }\n },\n \"status\" : {\n \"bytes_in\" : 1364923761,\n \"msgs_in\" : 337236,\n \"msgs_out\" : 346717,\n \"bytes_out\" : 1402765472,\n \"nodes_online\" : 15\n }\n}\nSync Zone:
\nSynchronization status of a shared memory zone.records_pending (integer)\nrecords_total (integer)\nResolver Zone:
\nStatistics of DNS requests and responses per particular\nresolver zone.requestsname (integer)\nsrv (integer)\naddr (integer)\nresponsesnoerror (integer)\nformerr (integer)\nFormat error) responses.\nservfail (integer)\nServer failure) responses.\nnxdomain (integer)\nHost not found) responses.\nnotimp (integer)\nUnimplemented) responses.\nrefused (integer)\nOperation refused) responses.\ntimedout (integer)\nunknown (integer)\nExample:
\n\n{\n \"resolver_zone1\" : {\n \"requests\" : {\n \"name\" : 25460,\n \"srv\" : 130,\n \"addr\" : 2580\n },\n \"responses\" : {\n \"noerror\" : 26499,\n \"formerr\" : 0,\n \"servfail\" : 3,\n \"nxdomain\" : 0,\n \"notimp\" : 0,\n \"refused\" : 0,\n \"timedout\" : 243,\n \"unknown\" : 478\n }\n }\n}\nLicense:
\nLicense and usage reporting status of NGINX Plus instance.eval (boolean)\nactive_till (integer)\nreportinghealthy (boolean)\nfails (integer)\ngrace (integer)\nuuid (string)\nExample:
\n\n{\n \"eval\" : false,\n \"active_till\" : 1749268757,\n \"reporting\" : {\n \"healthy\" : true,\n \"fails\" : 2,\n \"grace\" : 15551961,\n \"uuid\" : \"13754cba-29fb-53e5-c32e-a6cf57c84b01\"\n }\n}\nWorker process:
\nStatistics per each worker process.id (integer)\npid (integer)\nconnectionsaccepted (integer)\ndropped (integer)\nactive (integer)\nidle (integer)\nhttprequeststotal (integer)\ncurrent (integer)\nExample:
\n\n{\n \"id\" : 0,\n \"pid\" : 32212,\n \"connections\" : {\n \"accepted\" : 1,\n \"dropped\" : 0,\n \"active\" : 1,\n \"idle\" : 0\n },\n \"http\" : {\n \"requests\" : {\n \"total\" : 15,\n \"current\" : 1\n }\n }\n}\nError:
\nnginx error object.errorstatus (integer)\ntext (string)\ncode (string)\nrequest_id (string)\nhref (string)\n\n
\n\n| Example Configuration Directives auth_basic auth_basic_user_file |
\nThe ngx_http_auth_basic_module module allows\nlimiting access to resources by validating the user name and password\nusing the “HTTP Basic Authentication” protocol.\n
\nAccess can also be limited by\naddress, by the\nresult of subrequest,\nor by JWT.\nSimultaneous limitation of access by address and by password is controlled\nby the satisfy directive.\n
\n\n\n\n
\nlocation / {\n auth_basic \"closed site\";\n auth_basic_user_file conf/htpasswd;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n auth_basic \n | \n
|---|---|
| \n Default:\n | \n\n auth_basic off;\n | \n
| \n Context:\n | \n\n http, server, location, limit_except\n | \n
\nEnables validation of user name and password using the\n“HTTP Basic Authentication” protocol.\nThe specified parameter is used as a realm.\nParameter value can contain variables (1.3.10, 1.2.7).\nThe special value off cancels the effect\nof the auth_basic directive\ninherited from the previous configuration level.\n
| \n Syntax:\n | \n\n auth_basic_user_file \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location, limit_except\n | \n
\nSpecifies a file that keeps user names and passwords,\nin the following format:\n
\n# comment\nname1:password1\nname2:password2:comment\nname3:password3\n
\nThe file name can contain variables.\n
\nThe following password types are supported:\n
crypt() function; can be generated using\nthe “htpasswd” utility from the Apache HTTP Server\ndistribution or the “openssl passwd” command;\n{scheme}data”\nsyntax (1.0.3+) as described in\nRFC 2307;\ncurrently implemented schemes include PLAIN (an example one,\nshould not be used), SHA (1.3.13) (plain SHA-1\nhashing, should not be used) and SSHA (salted SHA-1 hashing,\nused by some software packages, notably OpenLDAP and Dovecot).\n\nSupport for SHA scheme was added only to aid\nin migration from other web servers.\nIt should not be used for new passwords, since unsalted SHA-1 hashing\nthat it employs is vulnerable to\nrainbow table\nattacks.\n\n\n
\n\n\nThe ngx_http_auth_jwt_module module (1.11.3)\nimplements client authorization by validating the provided\nJSON Web Token (JWT)\nusing the specified keys.\nThe module supports\nJSON Web Signature (JWS),\nJSON Web Encryption (JWE)\n(1.19.7), and Nested JWT (1.21.0).\nThe module can be used for\nOpenID Connect\nauthentication.\n
\nThe module may be combined with\nother access modules, such as\nngx_http_access_module,\nngx_http_auth_basic_module,\nand\nngx_http_auth_request_module,\nvia the satisfy directive.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\nThe module supports the following JSON Web\nAlgorithms.\n
\nJWS algorithms:\n
\n\n
\nPrior to version 1.13.7,\nonly HS256, RS256, ES256 algorithms were supported.\n
\n
\nJWE content encryption algorithms (1.19.7):\n
\n
\nJWE key management algorithms (1.19.9):\n
\n
\n\n\n\n
\nlocation / {\n auth_jwt \"closed site\";\n auth_jwt_key_file conf/keys.json;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n auth_jwt \n \n | \n
|---|---|
| \n Default:\n | \n\n auth_jwt off;\n | \n
| \n Context:\n | \n\n http, server, location, limit_except\n | \n
\nEnables validation of JSON Web Token.\nThe specified string is used as a realm.\nParameter value can contain variables.\n
\nThe optional token parameter specifies a variable\nthat contains JSON Web Token.\nBy default, JWT is passed in the “Authorization” header\nas a\nBearer Token.\nJWT may be also passed as a cookie or a part of a query string:\n
\nauth_jwt \"closed site\" token=$cookie_auth_token;\n
\n
\nThe special value off cancels the effect\nof the auth_jwt directive\ninherited from the previous configuration level.\n
| \n Syntax:\n | \n\n auth_jwt_claim_set \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
This directive appeared in version 1.11.10.\n
\nSets the variable to a JWT claim parameter\nidentified by key names.\nName matching starts from the top level of the JSON tree.\nFor arrays, the variable keeps a list of array elements separated by commas.\n
\nauth_jwt_claim_set $email info e-mail;\nauth_jwt_claim_set $job info \"job title\";\n
\n
\nPrior to version 1.13.7, only one key name could be specified,\nand the result was undefined for arrays.\n
\n
\n
\nVariable values for tokens encrypted with JWE\nare available only after decryption which occurs during the\nAccess phase.\n
\n
| \n Syntax:\n | \n\n auth_jwt_header_set \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
This directive appeared in version 1.11.10.\n
\nSets the variable to a JOSE header parameter\nidentified by key names.\nName matching starts from the top level of the JSON tree.\nFor arrays, the variable keeps a list of array elements separated by commas.\n
\nPrior to version 1.13.7, only one key name could be specified,\nand the result was undefined for arrays.\n
\n
| \n Syntax:\n | \n\n auth_jwt_key_cache \n | \n
|---|---|
| \n Default:\n | \n\n auth_jwt_key_cache 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.21.4.\n
\nEnables or disables caching of keys\nobtained from a file\nor from a subrequest,\nand sets caching time for them.\nCaching of keys obtained from variables is not supported.\nBy default, caching of keys is disabled.\n
| \n Syntax:\n | \n\n auth_jwt_key_file \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location, limit_except\n | \n
\nSpecifies a file in\nJSON Web Key Set\nformat for validating JWT signature.\nParameter value can contain variables.\n
\nSeveral auth_jwt_key_file directives\ncan be specified on the same level (1.21.1):\n
\nauth_jwt_key_file conf/keys.json;\nauth_jwt_key_file conf/key.jwk;\n
\nIf at least one of the specified keys cannot be loaded or processed,\nnginx will return the\n500 (Internal Server Error) error.\n
| \n Syntax:\n | \n\n auth_jwt_key_request \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location, limit_except\n | \n
This directive appeared in version 1.15.6.\n
\nAllows retrieving a\nJSON Web Key Set\nfile from a subrequest for validating JWT signature and\nsets the URI where the subrequest will be sent to.\nParameter value can contain variables.\nTo avoid validation overhead,\nit is recommended to cache the key file:\n
\nproxy_cache_path /data/nginx/cache levels=1 keys_zone=foo:10m;\n\nserver {\n ...\n\n location / {\n auth_jwt \"closed site\";\n auth_jwt_key_request /jwks_uri;\n }\n\n location = /jwks_uri {\n internal;\n proxy_cache foo;\n proxy_pass http://idp.example.com/keys;\n }\n}\n \nSeveral auth_jwt_key_request directives\ncan be specified on the same level (1.21.1):\n
\nauth_jwt_key_request /jwks_uri;\nauth_jwt_key_request /jwks2_uri;\n
\nIf at least one of the specified keys cannot be loaded or processed,\nnginx will return the\n500 (Internal Server Error) error.\n
| \n Syntax:\n | \n\n auth_jwt_leeway \n | \n
|---|---|
| \n Default:\n | \n\n auth_jwt_leeway 0s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.13.10.\n
\nSets the maximum allowable leeway to compensate\nclock skew when verifying the\nexp\nand\nnbf\nJWT claims.\n
| \n Syntax:\n | \n\n auth_jwt_type \n | \n
|---|---|
| \n Default:\n | \n\n auth_jwt_type signed;\n | \n
| \n Context:\n | \n\n http, server, location, limit_except\n | \n
This directive appeared in version 1.19.7.\n
\nSpecifies which type of JSON Web Token to expect:\nJWS (signed),\nJWE (encrypted),\nor signed and then encrypted\nNested JWT (nested) (1.21.0).\n
| \n Syntax:\n | \n\n auth_jwt_require \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location, limit_except\n | \n
This directive appeared in version 1.21.2.\n
\nSpecifies additional checks for JWT validation.\nThe value can contain text, variables, and their combination,\nand must start with a variable (1.21.7).\nThe authentication will succeed only\nif all the values are not empty and are not equal to “0”.\n
\nmap $jwt_claim_iss $valid_jwt_iss {\n \"good\" 1;\n}\n...\n\nauth_jwt_require $valid_jwt_iss;\n\n
\nIf any of the checks fails,\nthe 401 error code is returned.\nThe optional error parameter (1.21.7)\nallows redefining the error code to 403.\n
\nThe ngx_http_auth_jwt_module module\nsupports embedded variables:\n
\n
$jwt_header_name$jwt_claim_name\nFor nested claims and claims including a dot (“.”),\nthe value of the variable cannot be evaluated;\nthe auth_jwt_claim_set directive should be used instead.\n
\n\n\nVariable values for tokens encrypted with JWE\nare available only after decryption which occurs during the\nAccess phase.\n
\n$jwt_payloadnested\nor encrypted tokens (1.21.2).\nFor nested tokens returns the enclosed JWS token.\nFor encrypted tokens returns JSON with claims.\n\n
\n\n| Example Configuration Directives auth_request auth_request_set |
\nThe ngx_http_auth_request_module module (1.5.4+) implements\nclient authorization based on the result of a subrequest.\nIf the subrequest returns a 2xx response code, the access is allowed.\nIf it returns 401 or 403,\nthe access is denied with the corresponding error code.\nAny other response code returned by the subrequest is considered an error.\n
\nFor the 401 error, the client also receives the\n“WWW-Authenticate” header from the subrequest response.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_auth_request_module\nconfiguration parameter.\n
\nThe module may be combined with\nother access modules, such as\nngx_http_access_module,\nngx_http_auth_basic_module,\nand\nngx_http_auth_jwt_module,\nvia the satisfy directive.\n
\nBefore version 1.7.3, responses to authorization subrequests could not be cached\n(using proxy_cache,\nproxy_store, etc.).\n
\n
\n\n\n\n
\nlocation /private/ {\n auth_request /auth;\n ...\n}\n\nlocation = /auth {\n proxy_pass ...\n proxy_pass_request_body off;\n proxy_set_header Content-Length \"\";\n proxy_set_header X-Original-URI $request_uri;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n auth_request \n | \n
|---|---|
| \n Default:\n | \n\n auth_request off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables authorization based on the result of a subrequest and sets\nthe URI to which the subrequest will be sent.\n
| \n Syntax:\n | \n\n auth_request_set \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the request variable to the given\nvalue after the authorization request completes.\nThe value may contain variables from the authorization request,\nsuch as $upstream_http_*.\n
| Example Configuration Directives auth_require |
\nThe ngx_http_auth_require_module module (1.29.0)\nimplements variable-based client authorization.\nIt can also use variables\nprovided by other access modules such as\nngx_http_auth_request_module\nor\nngx_http_auth_oidc_module.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nhttp {\n oidc_provider my_idp {\n ...\n }\n\n map $oidc_claim_role $admin_role {\n \"admin\" 1;\n }\n\n server {\n auth_oidc my_idp;\n\n location /admin {\n auth_require $admin_role;\n }\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n auth_require \n \n | \n
|---|---|
| \n Default:\n | \n\n auth_require off;\n | \n
| \n Context:\n | \n\n http, server, location, limit_except\n | \n
\nEnables authorization based on the specified variables.\nThe access is allowed only if all the variables are not\nempty and are not equal to “0”.\nOtherwise, the module returns 403 code, which can be\noverridden by the error parameter.\nSeveral auth_require directives can be used to return\ndifferent error codes.\n
| Example Configuration Directives autoindex autoindex_exact_size autoindex_format autoindex_localtime |
\nThe ngx_http_autoindex_module module processes requests\nending with the slash character (‘/’) and produces\na directory listing.\nUsually a request is passed to the ngx_http_autoindex_module\nmodule when the\nngx_http_index_module module\ncannot find an index file.\n
\n
\nlocation / {\n autoindex on;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n autoindex \n | \n
|---|---|
| \n Default:\n | \n\n autoindex off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables the directory listing output.\n
| \n Syntax:\n | \n\n autoindex_exact_size \n | \n
|---|---|
| \n Default:\n | \n\n autoindex_exact_size on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nFor the HTML format,\nspecifies whether exact file sizes should be output in the directory listing,\nor rather rounded to kilobytes, megabytes, and gigabytes.\n
| \n Syntax:\n | \n\n autoindex_format \n \n | \n
|---|---|
| \n Default:\n | \n\n autoindex_format html;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.9.\n
\nSets the format of a directory listing.\n
\nWhen the JSONP format is used, the name of a callback function is set\nwith the callback request argument.\nIf the argument is missing or has an empty value,\nthen the JSON format is used.\n
\nThe XML output can be transformed using the\nngx_http_xslt_module module.\n
| \n Syntax:\n | \n\n autoindex_localtime \n | \n
|---|---|
| \n Default:\n | \n\n autoindex_localtime off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nFor the HTML format,\nspecifies whether times in the directory listing should be\noutput in the local time zone or UTC.\n
\n\n| Example Configuration Directives ancient_browser ancient_browser_value modern_browser modern_browser_value |
\nThe ngx_http_browser_module module creates variables\nwhose values depend on the value of the “User-Agent”\nrequest header field:\n
$modern_browser$ancient_browser$msie\n
\n\n\n\nChoosing an index file:\n
\nmodern_browser_value \"modern.\";\n\nmodern_browser msie 5.5;\nmodern_browser gecko 1.0.0;\nmodern_browser opera 9.0;\nmodern_browser safari 413;\nmodern_browser konqueror 3.0;\n\nindex index.${modern_browser}html index.html;\n\n
\nRedirection for old browsers:\n
\nmodern_browser msie 5.0;\nmodern_browser gecko 0.9.1;\nmodern_browser opera 8.0;\nmodern_browser safari 413;\nmodern_browser konqueror 3.0;\n\nmodern_browser unlisted;\n\nancient_browser Links Lynx netscape4;\n\nif ($ancient_browser) {\n rewrite ^ /ancient.html;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n ancient_browser \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIf any of the specified substrings is found in the “User-Agent”\nrequest header field, the browser will be considered ancient.\nThe special string “netscape4” corresponds to the\nregular expression “^Mozilla/[1-4]”.\n
| \n Syntax:\n | \n\n ancient_browser_value \n | \n
|---|---|
| \n Default:\n | \n\n ancient_browser_value 1;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a value for the $ancient_browser variables.\n
| \n Syntax:\n | \n\n modern_browser modern_browser \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies a version starting from which a browser is considered modern.\nA browser can be any one of the following: msie,\ngecko (browsers based on Mozilla),\nopera, safari,\nor konqueror.\n
\nVersions can be specified in the following formats: X, X.X, X.X.X, or X.X.X.X.\nThe maximum values for each of the format are\n4000, 4000.99, 4000.99.99, and 4000.99.99.99, respectively.\n
\nThe special value unlisted specifies to consider\na browser as modern if it was not listed by the\nmodern_browser and ancient_browser\ndirectives.\nOtherwise such a browser is considered ancient.\nIf a request does not provide the “User-Agent” field\nin the header, the browser is treated as not being listed.\n
| \n Syntax:\n | \n\n modern_browser_value \n | \n
|---|---|
| \n Default:\n | \n\n modern_browser_value 1;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a value for the $modern_browser variables.\n
| Example Configuration Directives charset charset_map charset_types override_charset source_charset |
\nThe ngx_http_charset_module module adds the specified\ncharset to the “Content-Type” response header field.\nIn addition, the module can convert data from one charset to another,\nwith some limitations:\n
\n
\n\n\n\n
\ninclude conf/koi-win;\n\ncharset windows-1251;\nsource_charset koi8-r;\n
\n
\n\n\n| \n Syntax:\n | \n\n charset \n | \n
|---|---|
| \n Default:\n | \n\n charset off;\n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
\nAdds the specified charset to the “Content-Type”\nresponse header field.\nIf this charset is different from the charset specified\nin the source_charset directive, a conversion is performed.\n
\nThe parameter off cancels the addition of charset\nto the “Content-Type” response header field.\n
\nA charset can be defined with a variable:\n
\ncharset $charset;\n
\nIn such a case, all possible values of a variable need to be present\nin the configuration at least once in the form of the\ncharset_map, charset, or\nsource_charset directives.\nFor utf-8, windows-1251, and\nkoi8-r charsets, it is sufficient to include the files\nconf/koi-win, conf/koi-utf, and\nconf/win-utf into configuration.\nFor other charsets, simply making a fictitious conversion table works,\nfor example:\n
\ncharset_map iso-8859-5 _ { }\n\n
\nIn addition, a charset can be set in the\n“X-Accel-Charset” response header field.\nThis capability can be disabled using the\nproxy_ignore_headers,\nfastcgi_ignore_headers,\nuwsgi_ignore_headers,\nscgi_ignore_headers,\nand\ngrpc_ignore_headers\ndirectives.\n
| \n Syntax:\n | \n\n charset_map \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nDescribes the conversion table from one charset to another.\nA reverse conversion table is built using the same data.\nCharacter codes are given in hexadecimal.\nMissing characters in the range 80-FF are replaced with “?”.\nWhen converting from UTF-8, characters missing in a one-byte charset\nare replaced with “&#XXXX;”.\n
\nExample:\n
\ncharset_map koi8-r windows-1251 {\n C0 FE ; # small yu\n C1 E0 ; # small a\n C2 E1 ; # small b\n C3 F6 ; # small ts\n ...\n}\n\n
\nWhen describing a conversion table to UTF-8, codes for the UTF-8 charset should\nbe given in the second column, for example:\n
\ncharset_map koi8-r utf-8 {\n C0 D18E ; # small yu\n C1 D0B0 ; # small a\n C2 D0B1 ; # small b\n C3 D186 ; # small ts\n ...\n}\n\n
\nFull conversion tables from koi8-r to\nwindows-1251, and from koi8-r and\nwindows-1251 to utf-8\nare provided in the distribution files conf/koi-win,\nconf/koi-utf, and conf/win-utf.\n
| \n Syntax:\n | \n\n charset_types \n | \n
|---|---|
| \n Default:\n | \n\n charset_types text/html text/xml text/plain text/vnd.wap.wml\napplication/javascript application/rss+xml;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.9.\n
\nEnables module processing in responses with the specified MIME types\nin addition to “text/html”.\nThe special value “*” matches any MIME type (0.8.29).\n
\n
\nUntil version 1.5.4, “application/x-javascript” was used\nas the default MIME type instead of “application/javascript”.\n
\n
| \n Syntax:\n | \n\n override_charset \n | \n
|---|---|
| \n Default:\n | \n\n override_charset off;\n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
\nDetermines whether a conversion should be performed for answers\nreceived from a proxied or a FastCGI/uwsgi/SCGI/gRPC server\nwhen the answers already carry a charset in the “Content-Type”\nresponse header field.\nIf conversion is enabled, a charset specified in the received\nresponse is used as a source charset.\n
\nIt should be noted that if a response is received in a subrequest\nthen the conversion from the response charset to the main request charset\nis always performed, regardless of the override_charset\ndirective setting.\n\n
| \n Syntax:\n | \n\n source_charset \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
\nDefines the source charset of a response.\nIf this charset is different from the charset specified\nin the charset directive, a conversion is performed.\n
\n\n| \n Syntax:\n | \n\n absolute_redirect \n | \n
|---|---|
| \n Default:\n | \n\n absolute_redirect on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.11.8.\n
\nIf disabled, redirects issued by nginx will be relative.\n
\nSee also server_name_in_redirect\nand port_in_redirect directives.\n
| \n Syntax:\n | \n\n aio \n \n | \n
|---|---|
| \n Default:\n | \n\n aio off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.8.11.\n
\nEnables or disables the use of asynchronous file I/O (AIO)\non FreeBSD and Linux:\n
\nlocation /video/ {\n aio on;\n output_buffers 1 64k;\n}\n\n
\nOn FreeBSD, AIO can be used starting from FreeBSD 4.3.\nPrior to FreeBSD 11.0,\nAIO can either be linked statically into a kernel:\n
\noptions VFS_AIO\n
\nor loaded dynamically as a kernel loadable module:\n
\nkldload aio\n
\n
\nOn Linux, AIO can be used starting from kernel version 2.6.22.\nAlso, it is necessary to enable\ndirectio,\nor otherwise reading will be blocking:\n
\nlocation /video/ {\n aio on;\n directio 512;\n output_buffers 1 128k;\n}\n\n
\nOn Linux,\ndirectio\ncan only be used for reading blocks that are aligned on 512-byte\nboundaries (or 4K for XFS).\nFile’s unaligned end is read in blocking mode.\nThe same holds true for byte range requests and for FLV requests\nnot from the beginning of a file: reading of unaligned data at the\nbeginning and end of a file will be blocking.\n
\nWhen both AIO and sendfile are enabled on Linux,\nAIO is used for files that are larger than or equal to\nthe size specified in the directio directive,\nwhile sendfile is used for files of smaller sizes\nor when directio is disabled.\n
\nlocation /video/ {\n sendfile on;\n aio on;\n directio 8m;\n}\n\n
\nFinally, files can be read and sent\nusing multi-threading (1.7.11),\nwithout blocking a worker process:\n
\nlocation /video/ {\n sendfile on;\n aio threads;\n}\n \nRead and send file operations are offloaded to threads of the specified\npool.\nIf the pool name is omitted,\nthe pool with the name “default” is used.\nThe pool name can also be set with variables:\n
\naio threads=pool$disk;\n
\nBy default, multi-threading is disabled, it should be\nenabled with the\n--with-threads configuration parameter.\nCurrently, multi-threading is compatible only with the\nepoll,\nkqueue,\nand\neventport methods.\nMulti-threaded sending of files is only supported on Linux.\n
\nSee also the sendfile directive.\n
| \n Syntax:\n | \n\n aio_write \n | \n
|---|---|
| \n Default:\n | \n\n aio_write off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.9.13.\n
\nIf aio is enabled, specifies whether it is used for writing files.\nCurrently, this only works when using\naio threads\nand is limited to writing temporary files\nwith data received from proxied servers.\n
| \n Syntax:\n | \n\n alias \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nDefines a replacement for the specified location.\nFor example, with the following configuration\n
\nlocation /i/ {\n alias /data/w3/images/;\n}\n \non request of\n“/i/top.gif”, the file\n/data/w3/images/top.gif will be sent.\n
\nThe path value can contain variables,\nexcept $document_root and $realpath_root.\n
\nIf alias is used inside a location defined\nwith a regular expression then such regular expression should\ncontain captures and alias should refer to\nthese captures (0.7.40), for example:\n
\nlocation ~ ^/users/(.+\\.(?:gif|jpe?g|png))$ {\n alias /data/w3/images/$1;\n}\n\n
\nWhen location matches the last part of the directive’s value:\n
\nlocation /images/ {\n alias /data/w3/images/;\n}\n\nit is better to use the\nroot\ndirective instead:\n
\nlocation /images/ {\n root /data/w3;\n}\n\n
| \n Syntax:\n | \n\n auth_delay \n | \n
|---|---|
| \n Default:\n | \n\n auth_delay 0s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.17.10.\n
\nDelays processing of unauthorized requests with 401 response code\nto prevent timing attacks when access is limited by\npassword, by the\nresult of subrequest,\nor by JWT.\n
| \n Syntax:\n | \n\n chunked_transfer_encoding \n | \n
|---|---|
| \n Default:\n | \n\n chunked_transfer_encoding on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nAllows disabling chunked transfer encoding in HTTP/1.1.\nIt may come in handy when using a software failing to support\nchunked encoding despite the standard’s requirement.\n
| \n Syntax:\n | \n\n client_body_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n client_body_buffer_size 8k|16k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets buffer size for reading client request body.\nIn case the request body is larger than the buffer,\nthe whole body or only its part is written to a\ntemporary file.\nBy default, buffer size is equal to two memory pages.\nThis is 8K on x86, other 32-bit platforms, and x86-64.\nIt is usually 16K on other 64-bit platforms.\n
| \n Syntax:\n | \n\n client_body_in_file_only \n \n | \n
|---|---|
| \n Default:\n | \n\n client_body_in_file_only off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines whether nginx should save the entire client request body\ninto a file.\nThis directive can be used during debugging, or when using the\n$request_body_file\nvariable, or the\n$r->request_body_file\nmethod of the module\nngx_http_perl_module.\n
\nWhen set to the value on, temporary files are not\nremoved after request processing.\n
\nThe value clean will cause the temporary files\nleft after request processing to be removed.\n
| \n Syntax:\n | \n\n client_body_in_single_buffer \n | \n
|---|---|
| \n Default:\n | \n\n client_body_in_single_buffer off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines whether nginx should save the entire client request body\nin a single buffer.\nThe directive is recommended when using the\n$request_body\nvariable, to save the number of copy operations involved.\n
| \n Syntax:\n | \n\n client_body_temp_path \n \n | \n
|---|---|
| \n Default:\n | \n\n client_body_temp_path client_body_temp;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a directory for storing temporary files holding client request bodies.\nUp to three-level subdirectory hierarchy can be used under the specified\ndirectory.\nFor example, in the following configuration\n
\nclient_body_temp_path /spool/nginx/client_temp 1 2;\n
\na path to a temporary file might look like this:\n
\n/spool/nginx/client_temp/7/45/00000123457\n
\n
| \n Syntax:\n | \n\n client_body_timeout \n | \n
|---|---|
| \n Default:\n | \n\n client_body_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a timeout for reading client request body.\nThe timeout is set only for a period between two successive read operations,\nnot for the transmission of the whole request body.\nIf a client does not transmit anything within this time, the\nrequest is terminated with the\n408 (Request Time-out)\nerror.\n
| \n Syntax:\n | \n\n client_header_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n client_header_buffer_size 1k;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSets buffer size for reading client request header.\nFor most requests, a buffer of 1K bytes is enough.\nHowever, if a request includes long cookies, or comes from a WAP client,\nit may not fit into 1K.\nIf a request line or a request header field does not fit into\nthis buffer then larger buffers, configured by the\nlarge_client_header_buffers directive,\nare allocated.\n
\nIf the directive is specified on the server level,\nthe value from the default server can be used.\nDetails are provided in the\n“Virtual\nserver selection” section.\n
| \n Syntax:\n | \n\n client_header_timeout \n | \n
|---|---|
| \n Default:\n | \n\n client_header_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nDefines a timeout for reading client request header.\nIf a client does not transmit the entire header within this time, the\nrequest is terminated with the\n408 (Request Time-out)\nerror.\n
| \n Syntax:\n | \n\n client_max_body_size \n | \n
|---|---|
| \n Default:\n | \n\n client_max_body_size 1m;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the maximum allowed size of the client request body.\nIf the size in a request exceeds the configured value, the\n413 (Request Entity Too Large)\nerror is returned to the client.\nPlease be aware that\nbrowsers cannot correctly display\nthis error.\nSetting size to 0 disables checking of client\nrequest body size.\n
| \n Syntax:\n | \n\n connection_pool_size \n | \n
|---|---|
| \n Default:\n | \n\n connection_pool_size 256|512;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nAllows accurate tuning of per-connection memory allocations.\nThis directive has minimal impact on performance\nand should not generally be used.\nBy default, the size is equal to\n256 bytes on 32-bit platforms and 512 bytes on 64-bit platforms.\n
\nPrior to version 1.9.8, the default value was 256 on all platforms.\n
\n
| \n Syntax:\n | \n\n default_type \n | \n
|---|---|
| \n Default:\n | \n\n default_type text/plain;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines the default MIME type of a response.\nMapping of file name extensions to MIME types can be set\nwith the types directive.\n
| \n Syntax:\n | \n\n directio \n | \n
|---|---|
| \n Default:\n | \n\n directio off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.7.\n
\nEnables the use of\nthe O_DIRECT flag (FreeBSD, Linux),\nthe F_NOCACHE flag (macOS),\nor the directio() function (Solaris),\nwhen reading files that are larger than or equal to\nthe specified size.\nThe directive automatically disables (0.7.15) the use of\nsendfile\nfor a given request.\nIt can be useful for serving large files:\n
\ndirectio 4m;\n
\nor when using aio on Linux.\n
| \n Syntax:\n | \n\n directio_alignment \n | \n
|---|---|
| \n Default:\n | \n\n directio_alignment 512;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.8.11.\n
\nSets the alignment for\ndirectio.\nIn most cases, a 512-byte alignment is enough.\nHowever, when using XFS under Linux, it needs to be increased to 4K.\n
| \n Syntax:\n | \n\n disable_symlinks disable_symlinks \n \n | \n
|---|---|
| \n Default:\n | \n\n disable_symlinks off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.15.\n
\nDetermines how symbolic links should be treated when opening files:\n
offonif_not_ownerfrom=parton and if_not_owner),\nall components of the pathname are normally checked.\nChecking of symbolic links in the initial part of the pathname\nmay be avoided by specifying additionally the\nfrom=part parameter.\nIn this case, symbolic links are checked only from\nthe pathname component that follows the specified initial part.\nIf the value is not an initial part of the pathname checked, the whole\npathname is checked as if this parameter was not specified at all.\nIf the value matches the whole file name,\nsymbolic links are not checked.\nThe parameter value can contain variables.\n\n
\nExample:\n
\ndisable_symlinks on from=$document_root;\n
\n
\nThis directive is only available on systems that have the\nopenat() and fstatat() interfaces.\nSuch systems include modern versions of FreeBSD, Linux, and Solaris.\n
\nParameters on and if_not_owner\nadd a processing overhead.\n
\nOn systems that do not support opening of directories only for search,\nto use these parameters it is required that worker processes\nhave read permissions for all directories being checked.\n
\n
\n
\nThe\nngx_http_autoindex_module,\nngx_http_random_index_module,\nand ngx_http_dav_module\nmodules currently ignore this directive.\n
\n
| \n Syntax:\n | \n\n early_hints \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.0.\n
\nDefines conditions under which\nthe 103 (Early Hints) response\nwill be passed to a client.\nIf at least one value of the string parameters is not empty and is not\nequal to “0” then the response will be passed:\n
\nmap $http_sec_fetch_mode $early_hints {\n navigate $http2$http3;\n}\n\nserver {\n ...\n location / {\n early_hints $early_hints;\n proxy_pass http://example.com;\n }\n}\n\n
\n
\n103 (Early Hints) responses received from\nan upstream server are passed to a client as is, without interpretation.\n
\n
| \n Syntax:\n | \n\n error_log_tag \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.8.\n
\nDefines an additional context tag for HTTP\nerror log messages in\ntext or JSON\nformat, in addition to default tags.\nThe value can contain text, variables, and their combination:\n
\nerror_log_tag request_id $request_id;\n
\n
\nSeveral error_log_tag directives\ncan be specified on the same level.\nThese directives are inherited from the previous configuration level\nif and only if there are no error_log_tag directives\ndefined on the current level.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n error_page \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
\nDefines the URI that will be shown for the specified errors.\nA uri value can contain variables.\n
\nExample:\n
\nerror_page 404 /404.html;\nerror_page 500 502 503 504 /50x.html;\n
\n
\nThis causes an internal redirect to the specified uri\nwith the client request method changed to “GET”\n(for all methods other than\n“GET” and “HEAD”).\n
\nFurthermore, it is possible to change the response code to another\nusing the “=response” syntax, for example:\n
\nerror_page 404 =200 /empty.gif;\n
\n
\nIf an error response is processed by a proxied server\nor a FastCGI/uwsgi/SCGI/gRPC server,\nand the server may return different response codes (e.g., 200, 302, 401\nor 404), it is possible to respond with the code it returns:\n
\nerror_page 404 = /404.php;\n
\n
\nIf there is no need to change URI and method during internal redirection\nit is possible to pass error processing into a named location:\n
\nlocation / {\n error_page 404 = @fallback;\n}\n\nlocation @fallback {\n proxy_pass http://backend;\n}\n\n
\n
\nIf uri processing leads to an error,\nthe status code of the last occurred error is returned to the client.\n\n
\nIt is also possible to use URL redirects for error processing:\n
\nerror_page 403 http://example.com/forbidden.html;\nerror_page 404 =301 http://example.com/notfound.html;\n
\nIn this case, by default, the response code 302 is returned to the client.\nIt can only be changed to one of the redirect status\ncodes (301, 302, 303, 307, and 308).\n
\nThe code 307 was not treated as a redirect until versions 1.1.16 and 1.0.13.\n
\n\n
\nThe code 308 was not treated as a redirect until version 1.13.0.\n
\n
\nThese directives are inherited from the previous configuration level\nif and only if there are no error_page directives\ndefined on the current level.\n
| \n Syntax:\n | \n\n etag \n | \n
|---|---|
| \n Default:\n | \n\n etag on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.3.3.\n
\nEnables or disables automatic generation of the “ETag”\nresponse header field for static resources.\n
| \n Syntax:\n | \n\n http { ... }\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
\nProvides the configuration file context in which the HTTP server directives\nare specified.\n
| \n Syntax:\n | \n\n if_modified_since \n \n | \n
|---|---|
| \n Default:\n | \n\n if_modified_since exact;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.24.\n
\nSpecifies how to compare modification time of a response\nwith the time in the\n“If-Modified-Since”\nrequest header field:\n\n
offexactbefore\n
| \n Syntax:\n | \n\n ignore_invalid_headers \n | \n
|---|---|
| \n Default:\n | \n\n ignore_invalid_headers on;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nControls whether header fields with invalid names should be ignored.\nValid names are composed of English letters, digits, hyphens, and possibly\nunderscores (as controlled by the underscores_in_headers\ndirective).\n
\nIf the directive is specified on the server level,\nthe value from the default server can be used.\nDetails are provided in the\n“Virtual\nserver selection” section.\n
| \n Syntax:\n | \n\n internal;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nSpecifies that a given location can only be used for internal requests.\nFor external requests, the client error\n404 (Not Found)\nis returned.\nInternal requests are the following:\n\n
include virtual”\ncommand of the\nngx_http_ssi_module\nmodule, by the\nngx_http_addition_module\nmodule directives, and by\nauth_request and\nmirror directives;\n\n
\nExample:\n
\nerror_page 404 /404.html;\n\nlocation = /404.html {\n internal;\n}\n\n
\nThere is a limit of 10 internal redirects per request to prevent\nrequest processing cycles that can occur in incorrect configurations.\nIf this limit is reached, the error\n500 (Internal Server Error) is returned.\nIn such cases, the “rewrite or internal redirection cycle” message\ncan be seen in the error log.\n
\n
| \n Syntax:\n | \n\n keepalive_disable \n | \n
|---|---|
| \n Default:\n | \n\n keepalive_disable msie6;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDisables keep-alive connections with misbehaving browsers.\nThe browser parameters specify which\nbrowsers will be affected.\nThe value msie6 disables keep-alive connections\nwith old versions of MSIE, once a POST request is received.\nThe value safari disables keep-alive connections\nwith Safari and Safari-like browsers on macOS and macOS-like\noperating systems.\nThe value none enables keep-alive connections\nwith all browsers.\n
\nPrior to version 1.1.18, the value safari matched\nall Safari and Safari-like browsers on all operating systems, and\nkeep-alive connections with them were disabled by default.\n\n
| \n Syntax:\n | \n\n keepalive_min_timeout \n | \n
|---|---|
| \n Default:\n | \n\n keepalive_min_timeout 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.27.4.\n
\nSets a timeout during which a keep-alive\nclient connection will not be closed on the server side\nfor connection reuse or on graceful shutdown of worker processes.\n
| \n Syntax:\n | \n\n keepalive_requests \n | \n
|---|---|
| \n Default:\n | \n\n keepalive_requests 1000;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.8.0.\n
\nSets the maximum number of requests that can be\nserved through one keep-alive connection.\nAfter the maximum number of requests are made, the connection is closed.\n
\nClosing connections periodically is necessary to free\nper-connection memory allocations.\nTherefore, using too high maximum number of requests\ncould result in excessive memory usage and not recommended.\n
\n
\nPrior to version 1.19.10, the default value was 100.\n
\n
| \n Syntax:\n | \n\n keepalive_time \n | \n
|---|---|
| \n Default:\n | \n\n keepalive_time 1h;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.19.10.\n
\nLimits the maximum time during which\nrequests can be processed through one keep-alive connection.\nAfter this time is reached, the connection is closed\nfollowing the subsequent request processing.\n
| \n Syntax:\n | \n\n keepalive_timeout \n \n | \n
|---|---|
| \n Default:\n | \n\n keepalive_timeout 75s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nThe first parameter sets a timeout during which a keep-alive\nclient connection will stay open on the server side.\nThe zero value disables keep-alive client connections.\nThe optional second parameter sets a value in the\n“Keep-Alive: timeout=time”\nresponse header field.\nTwo parameters may differ.\n
\nThe\n“Keep-Alive: timeout=time”\nheader field is recognized by Mozilla and Konqueror.\nMSIE closes keep-alive connections by itself in about 60 seconds.\n
| \n Syntax:\n | \n\n large_client_header_buffers \n | \n
|---|---|
| \n Default:\n | \n\n large_client_header_buffers 4 8k;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSets the maximum number and size of\nbuffers used for reading large client request header.\nA request line cannot exceed the size of one buffer, or the\n414 (Request-URI Too Large)\nerror is returned to the client.\nA request header field cannot exceed the size of one buffer as well, or the\n400 (Bad Request)\nerror is returned to the client.\nBuffers are allocated only on demand.\nBy default, the buffer size is equal to 8K bytes.\nIf after the end of request processing a connection is transitioned\ninto the keep-alive state, these buffers are released.\n
\nIf the directive is specified on the server level,\nthe value from the default server can be used.\nDetails are provided in the\n“Virtual\nserver selection” section.\n
| \n Syntax:\n | \n\n limit_except \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nLimits allowed HTTP methods inside a location.\nThe method parameter can be one of the following:\nGET,\nHEAD,\nPOST,\nPUT,\nDELETE,\nMKCOL,\nCOPY,\nMOVE,\nOPTIONS,\nPROPFIND,\nPROPPATCH,\nLOCK,\nUNLOCK,\nor\nPATCH.\nAllowing the GET method makes the\nHEAD method also allowed.\nAccess to other methods can be limited using the\nngx_http_access_module,\nngx_http_auth_basic_module,\nand\nngx_http_auth_jwt_module\n(1.13.10)\nmodules directives:\n
\nlimit_except GET {\n allow 192.168.1.0/32;\n deny all;\n}\n\nPlease note that this will limit access to all methods\nexcept GET and HEAD.\n
| \n Syntax:\n | \n\n limit_rate \n | \n
|---|---|
| \n Default:\n | \n\n limit_rate 0;\n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
\nLimits the rate of response transmission to a client.\nThe rate is specified in bytes per second.\nThe zero value disables rate limiting.\n\nThe limit is set per a request, and so if a client simultaneously opens\ntwo connections, the overall rate will be twice as much\nas the specified limit.\n
\nParameter value can contain variables (1.17.0).\nIt may be useful in cases where rate should be limited\ndepending on a certain condition:\n
\nmap $slow $rate {\n 1 4k;\n 2 8k;\n}\n\nlimit_rate $rate;\n\n
\nRate limit can also be set in the\n$limit_rate variable,\nhowever, since version 1.17.0, this method is not recommended:\n
\nserver {\n\n if ($slow) {\n set $limit_rate 4k;\n }\n\n ...\n}\n\n
\nRate limit can also be set in the\n“X-Accel-Limit-Rate” header field of a proxied server response.\nThis capability can be disabled using the\nproxy_ignore_headers,\nfastcgi_ignore_headers,\nuwsgi_ignore_headers,\nand\nscgi_ignore_headers\ndirectives.\n
| \n Syntax:\n | \n\n limit_rate_after \n | \n
|---|---|
| \n Default:\n | \n\n limit_rate_after 0;\n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
This directive appeared in version 0.8.0.\n
\nSets the initial amount after which the further transmission\nof a response to a client will be rate limited.\nParameter value can contain variables (1.17.0).\n
\nExample:\n
\nlocation /flv/ {\n flv;\n limit_rate_after 500k;\n limit_rate 50k;\n}\n\n
| \n Syntax:\n | \n\n lingering_close \n \n | \n
|---|---|
| \n Default:\n | \n\n lingering_close on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\n This directive appeared in versions 1.1.0 and 1.0.6.\n \n
\n\nControls how nginx closes client connections.\n
\nThe default value “on” instructs nginx to\nwait for and\nprocess additional data from a client\nbefore fully closing a connection, but only\nif heuristics suggests that a client may be sending more data.\n
\nThe value “always” will cause nginx to unconditionally\nwait for and process additional client data.\n
\nThe value “off” tells nginx to never wait for\nmore data and close the connection immediately.\nThis behavior breaks the protocol and should not be used under normal\ncircumstances.\n
\nTo control closing\nHTTP/2 connections,\nthe directive must be specified on the server level (1.19.1).\n
| \n Syntax:\n | \n\n lingering_time \n | \n
|---|---|
| \n Default:\n | \n\n lingering_time 30s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nWhen lingering_close is in effect,\nthis directive specifies the maximum time during which nginx\nwill process (read and ignore) additional data coming from a client.\nAfter that, the connection will be closed, even if there will be\nmore data.\n
| \n Syntax:\n | \n\n lingering_timeout \n | \n
|---|---|
| \n Default:\n | \n\n lingering_timeout 5s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nWhen lingering_close is in effect, this directive specifies\nthe maximum waiting time for more client data to arrive.\nIf data are not received during this time, the connection is closed.\nOtherwise, the data are read and ignored, and nginx starts waiting\nfor more data again.\nThe “wait-read-ignore” cycle is repeated, but no longer than specified by the\nlingering_time directive.\n
| \n Syntax:\n | \n\n listen \n listen \n listen \n \n | \n
|---|---|
| \n Default:\n | \n\n listen *:80 | *:8000;\n | \n
| \n Context:\n | \n\n server\n | \n
\nSets the address and port for IP,\nor the path for a UNIX-domain socket on which\nthe server will accept requests.\nBoth address and port,\nor only address or only port can be specified.\nAn address may also be a hostname, for example:\n
\nlisten 127.0.0.1:8000;\nlisten 127.0.0.1;\nlisten 8000;\nlisten *:8000;\nlisten localhost:8000;\n
\nIPv6 addresses (0.7.36) are specified in square brackets:\n
\nlisten [::]:8000;\nlisten [::1];\n
\nUNIX-domain sockets (0.8.21) are specified with the “unix:”\nprefix:\n
\nlisten unix:/var/run/nginx.sock;\n
\n
\nIf only address is given, the port 80 is used.\n
\nIf the directive is not present then either *:80 is used\nif nginx runs with the superuser privileges, or *:8000\notherwise.\n
\nThe default_server parameter, if present,\nwill cause the server to become the default server for the specified\naddress:port pair.\nIf none of the directives have the default_server\nparameter then the first server with the\naddress:port pair will be\nthe default server for this pair.\n
\nIn versions prior to 0.8.21 this parameter is named simply\ndefault.\n\n
\nThe ssl parameter (0.7.14) allows specifying that all\nconnections accepted on this port should work in SSL mode.\nThis allows for a more compact configuration for the server that\nhandles both HTTP and HTTPS requests.\n
\nThe http2 parameter (1.9.5) configures the port to accept\nHTTP/2 connections.\nNormally, for this to work the ssl parameter should be\nspecified as well, but nginx can also be configured to accept HTTP/2\nconnections without SSL.\n
\nThe parameter is deprecated,\nthe http2 directive\nshould be used instead.\n
\n
\nThe quic parameter (1.25.0) configures the port to accept\nQUIC connections.\n
\nThe proxy_protocol parameter (1.5.12)\nallows specifying that all connections accepted on this port should use the\nPROXY\nprotocol.\n
\nThe PROXY protocol version 2 is supported since version 1.13.11.\n
\n
\nThe listen directive\ncan have several additional parameters specific to socket-related system calls.\nThese parameters can be specified in any\nlisten directive, but only once for a given\naddress:port pair.\n
\nIn versions prior to 0.8.21, they could only be\nspecified in thelistendirective together with the\ndefaultparameter.\n
\n
setfib=number\nSO_SETFIB option) for the listening socket.\nThis currently works only on FreeBSD.\nfastopen=number\n\nDo not enable this feature unless the server can handle\nreceiving the\n\nsame SYN packet with data more than once.\n\n
backlog=number\nbacklog parameter in the\nlisten() call that limits\nthe maximum length for the queue of pending connections.\nBy default,\nbacklog is set to -1 on FreeBSD, DragonFly BSD, and macOS,\nand to 511 on other platforms.\nrcvbuf=size\nSO_RCVBUF option) for the listening socket.\nsndbuf=size\nSO_SNDBUF option) for the listening socket.\naccept_filter=filter\nSO_ACCEPTFILTER option) for the listening socket\nthat filters incoming connections before passing them to\naccept().\nThis works only on FreeBSD and NetBSD 5.0+.\nPossible values are\ndataready\nand\nhttpready.\ndeferred\naccept()\n(the TCP_DEFER_ACCEPT socket option) on Linux.\nbind\nbind() call for a given\naddress:port pair.\nThis is useful because if there are several listen\ndirectives with the same port but different addresses, and one of the\nlisten directives listens on all addresses\nfor the given port (*:port), nginx\nwill bind() only to *:port.\nIt should be noted that the getsockname() system call will be\nmade in this case to determine the address that accepted the connection.\nIf the setfib,\nfastopen,\nbacklog, rcvbuf,\nsndbuf, accept_filter,\ndeferred, ipv6only,\nreuseport, multipath,\nor so_keepalive parameters\nare used then for a given\naddress:port pair\na separate bind() call will always be made.\nipv6only=on|off\nIPV6_V6ONLY socket option)\nwhether an IPv6 socket listening on a wildcard address [::]\nwill accept only IPv6 connections or both IPv6 and IPv4 connections.\nThis parameter is turned on by default.\nIt can only be set once on start.\n\nPrior to version 1.3.4,\nif this parameter was omitted then the operating system’s settings were\nin effect for the socket.\n\n
reuseport\nSO_REUSEPORT socket option on Linux 3.9+ and DragonFly BSD,\nor SO_REUSEPORT_LB on FreeBSD 12+), allowing a kernel\nto distribute incoming connections between worker processes.\nThis currently works only on Linux 3.9+, DragonFly BSD,\nand FreeBSD 12+ (1.15.1).\n\nInappropriate use of this option may have its security\nimplications.\n\n
multipath\nIPPROTO_MPTCP) for the listening socket.\nThis currently works only on Linux 5.6+.\n\nAdding or removing this parameter will also enable\nthe SO_REUSEPORT socket option, which may have its security\nimplications.\n\nso_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]\non”, the\nSO_KEEPALIVE option is turned on for the socket.\nIf it is set to the value “off”, the\nSO_KEEPALIVE option is turned off for the socket.\nSome operating systems support setting of TCP keepalive parameters on\na per-socket basis using the TCP_KEEPIDLE,\nTCP_KEEPINTVL, and TCP_KEEPCNT socket options.\nOn such systems\n(currently, Linux, NetBSD, Dragonfly, FreeBSD, and macOS),\nthey can be configured\nusing the keepidle, keepintvl, and\nkeepcnt parameters.\nOne or two parameters may be omitted, in which case the system default setting\nfor the corresponding socket option will be in effect.\nFor example,\n\nwill set the idle timeout (so_keepalive=30m::10
TCP_KEEPIDLE) to 30 minutes,\nleave the probe interval (TCP_KEEPINTVL) at its system default,\nand set the probes count (TCP_KEEPCNT) to 10 probes.\n\n
\nExample:\n
\nlisten 127.0.0.1 default_server accept_filter=dataready backlog=1024;\n
\n
| \n Syntax:\n | \n\n location [\n location \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server, location\n | \n
\nSets configuration depending on a request URI.\n
\nThe matching is performed against a normalized URI,\nafter decoding the text encoded in the “%XX” form,\nresolving references to relative path components “.”\nand “..”, and possible\ncompression of two or more\nadjacent slashes into a single slash.\n
\nA location can either be defined by a prefix string, or by a regular expression.\nRegular expressions are specified with the preceding\n“~*” modifier (for case-insensitive matching), or the\n“~” modifier (for case-sensitive matching).\nTo find location matching a given request, nginx first checks\nlocations defined using the prefix strings (prefix locations).\nAmong them, the location with the longest matching\nprefix is selected and remembered.\nThen regular expressions are checked, in the order of their appearance\nin the configuration file.\nThe search of regular expressions terminates on the first match,\nand the corresponding configuration is used.\nIf no match with a regular expression is found then the\nconfiguration of the prefix location remembered earlier is used.\n
\nlocation blocks can be nested, with some exceptions\nmentioned below.\n
\nFor case-insensitive operating systems such as macOS and Cygwin,\nmatching with prefix strings ignores a case (0.7.7).\nHowever, comparison is limited to one-byte locales.\n
\nRegular expressions can contain captures (0.7.40) that can later\nbe used in other directives.\n
\nIf the longest matching prefix location has the “^~” modifier\nthen regular expressions are not checked.\n
\nAlso, using the “=” modifier it is possible to define\nan exact match of URI and location.\nIf an exact match is found, the search terminates.\nFor example, if a “/” request happens frequently,\ndefining “location = /” will speed up the processing\nof these requests, as search terminates right after the first\ncomparison.\nSuch a location cannot obviously contain nested locations.\n
\n
\nIn versions from 0.7.1 to 0.8.41, if a request matched the prefix\nlocation without the “=” and “^~”\nmodifiers, the search also terminated and regular expressions were\nnot checked.\n
\n
\nLet’s illustrate the above by an example:\n
\nlocation = / {\n [ configuration A ]\n}\n\nlocation / {\n [ configuration B ]\n}\n\nlocation /documents/ {\n [ configuration C ]\n}\n\nlocation ^~ /images/ {\n [ configuration D ]\n}\n\nlocation ~* \\.(gif|jpg|jpeg)$ {\n [ configuration E ]\n}\n \nThe “/” request will match configuration A,\nthe “/index.html” request will match configuration B,\nthe “/documents/document.html” request will match\nconfiguration C,\nthe “/images/1.gif” request will match configuration D, and\nthe “/documents/1.jpg” request will match configuration E.\n
\nThe “@” prefix defines a named location.\nSuch a location is not used for a regular request processing, but instead\nused for request redirection.\nThey cannot be nested, and cannot contain nested locations.\n
\nIf a location is defined by a prefix string that ends with the slash character,\nand requests are processed by one of\nproxy_pass,\nfastcgi_pass,\nuwsgi_pass,\nscgi_pass,\nmemcached_pass, or\ngrpc_pass,\nthen the special processing is performed.\nIn response to a request with URI equal to this string,\nbut without the trailing slash,\na permanent redirect with the code 301 will be returned to the requested URI\nwith the slash appended.\nIf this is not desired, an exact match of the URI and location could be\ndefined like this:\n
\nlocation /user/ {\n proxy_pass http://user.example.com;\n}\n\nlocation = /user {\n proxy_pass http://login.example.com;\n}\n\n
| \n Syntax:\n | \n\n log_not_found \n | \n
|---|---|
| \n Default:\n | \n\n log_not_found on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables logging of errors about not found files into\nerror_log.\n
| \n Syntax:\n | \n\n log_subrequest \n | \n
|---|---|
| \n Default:\n | \n\n log_subrequest off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables logging of subrequests into\naccess_log.\n
| \n Syntax:\n | \n\n max_headers \n | \n
|---|---|
| \n Default:\n | \n\n max_headers 1000;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.29.8.\n
\nSets the maximum allowed number of header lines in requests.\nIf this limit is reached, the error\n400 (Bad Request)\nis returned.\n
| \n Syntax:\n | \n\n max_ranges \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.2.\n
\nLimits the maximum allowed number of ranges in byte-range requests.\nRequests that exceed the limit are processed as if there were no\nbyte ranges specified.\nBy default, the number of ranges is not limited.\nThe zero value disables the byte-range support completely.\n
| \n Syntax:\n | \n\n merge_slashes \n | \n
|---|---|
| \n Default:\n | \n\n merge_slashes on;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nEnables or disables compression of two or more adjacent slashes\nin a URI into a single slash.\n
\nNote that compression is essential for the correct matching of prefix string\nand regular expression locations.\nWithout it, the “//scripts/one.php” request would not match\n
\nlocation /scripts/ {\n ...\n}\n \nand might be processed as a static file.\nSo it gets converted to “/scripts/one.php”.\n
\nTurning the compression off can become necessary if a URI\ncontains base64-encoded names, since base64 uses the “/”\ncharacter internally.\nHowever, for security considerations, it is better to avoid turning\nthe compression off.\n
\nIf the directive is specified on the server level,\nthe value from the default server can be used.\nDetails are provided in the\n“Virtual\nserver selection” section.\n
| \n Syntax:\n | \n\n msie_padding \n | \n
|---|---|
| \n Default:\n | \n\n msie_padding on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables adding comments to responses for MSIE clients with status\ngreater than 400 to increase the response size to 512 bytes.\n
| \n Syntax:\n | \n\n msie_refresh \n | \n
|---|---|
| \n Default:\n | \n\n msie_refresh off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables issuing refreshes instead of redirects for MSIE clients.\n
| \n Syntax:\n | \n\n open_file_cache open_file_cache \n\n | \n
|---|---|
| \n Default:\n | \n\n open_file_cache off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nConfigures a cache that can store:\n
\nCaching of errors should be enabled separately by the\nopen_file_cache_errors\ndirective.\n\n
\n
\nThe directive has the following parameters:\n
max\ninactive\noff\n\n
\nExample:\n
\nopen_file_cache max=1000 inactive=20s;\nopen_file_cache_valid 30s;\nopen_file_cache_min_uses 2;\nopen_file_cache_errors on;\n
\n
| \n Syntax:\n | \n\n open_file_cache_errors \n | \n
|---|---|
| \n Default:\n | \n\n open_file_cache_errors off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables caching of file lookup errors by\nopen_file_cache.\n
| \n Syntax:\n | \n\n open_file_cache_min_uses \n | \n
|---|---|
| \n Default:\n | \n\n open_file_cache_min_uses 1;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the minimum number of file accesses during\nthe period configured by the inactive parameter\nof the open_file_cache directive, required for a file\ndescriptor to remain open in the cache.\n
| \n Syntax:\n | \n\n open_file_cache_valid \n | \n
|---|---|
| \n Default:\n | \n\n open_file_cache_valid 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a time after which\nopen_file_cache\nelements should be validated.\n\n
| \n Syntax:\n | \n\n output_buffers \n | \n
|---|---|
| \n Default:\n | \n\n output_buffers 2 32k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the number and size of the\nbuffers used for reading a response from a disk.\n
\nPrior to version 1.9.5, the default value was 1 32k.\n
\n
| \n Syntax:\n | \n\n port_in_redirect \n | \n
|---|---|
| \n Default:\n | \n\n port_in_redirect on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables specifying the port in\nabsolute redirects issued by nginx.\n
\nThe use of the primary server name in redirects is controlled by\nthe server_name_in_redirect directive.\n
| \n Syntax:\n | \n\n postpone_output \n | \n
|---|---|
| \n Default:\n | \n\n postpone_output 1460;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIf possible, the transmission of client data will be postponed until\nnginx has at least size bytes of data to send.\nThe zero value disables postponing data transmission.\n
| \n Syntax:\n | \n\n read_ahead \n | \n
|---|---|
| \n Default:\n | \n\n read_ahead 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the amount of pre-reading for the kernel when working with file.\n
\nOn Linux, the\nposix_fadvise(0, 0, 0, POSIX_FADV_SEQUENTIAL)\nsystem call is used, and so the size parameter is ignored.\n
\nOn FreeBSD, the\nfcntl(O_READAHEAD,\nsize)\nsystem call, supported since FreeBSD 9.0-CURRENT, is used.\nFreeBSD 7 has to be\npatched.\n
| \n Syntax:\n | \n\n recursive_error_pages \n | \n
|---|---|
| \n Default:\n | \n\n recursive_error_pages off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables doing several redirects using the\nerror_page\ndirective.\nThe number of such redirects is limited.\n
| \n Syntax:\n | \n\n request_pool_size \n | \n
|---|---|
| \n Default:\n | \n\n request_pool_size 4k;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nAllows accurate tuning of per-request memory allocations.\nThis directive has minimal impact on performance\nand should not generally be used.\n
| \n Syntax:\n | \n\n reset_timedout_connection \n | \n
|---|---|
| \n Default:\n | \n\n reset_timedout_connection off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables resetting timed out connections\nand connections\nclosed\nwith the non-standard code 444 (1.15.2).\nThe reset is performed as follows.\nBefore closing a socket, the\nSO_LINGER\noption is set on it with a timeout value of 0.\nWhen the socket is closed, TCP RST is sent to the client, and all memory\noccupied by this socket is released.\nThis helps avoid keeping an already closed socket with filled buffers\nin a FIN_WAIT1 state for a long time.\n
\nIt should be noted that timed out keep-alive connections are\nclosed normally.\n
| \n Syntax:\n | \n\n resolver \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nConfigures name servers used to resolve names of upstream servers\ninto addresses, for example:\n
\nresolver 127.0.0.1 [::1]:5353;\n
\nThe address can be specified as a domain name or IP address,\nwith an optional port (1.3.1, 1.2.2).\nIf port is not specified, the port 53 is used.\nName servers are queried in a round-robin fashion.\n
\nBefore version 1.1.7, only a single name server could be configured.\nSpecifying name servers using IPv6 addresses is supported\nstarting from versions 1.3.1 and 1.2.2.\n
\n
\nBy default, nginx will look up both IPv4 and IPv6 addresses while resolving.\nIf looking up of IPv4 or IPv6 addresses is not desired,\nthe ipv4=off (1.23.1) or\nthe ipv6=off parameter can be specified.\n
\nResolving of names into IPv6 addresses is supported\nstarting from version 1.5.8.\n
\n
\nBy default, nginx caches answers using the TTL value of a response.\nAn optional valid parameter allows overriding it:\n
\nresolver 127.0.0.1 [::1]:5353 valid=30s;\n
\n
\nBefore version 1.1.9, tuning of caching time was not possible,\nand nginx always cached answers for the duration of 5 minutes.\n
\n
\nTo prevent DNS spoofing, it is recommended\nconfiguring DNS servers in a properly secured trusted local network.\n
\n
\nThe optional status_zone parameter (1.17.1)\nenables\ncollection\nof DNS server statistics of requests and responses\nin the specified zone.\nThe parameter is available as part of our\ncommercial subscription.\n
| \n Syntax:\n | \n\n resolver_timeout \n | \n
|---|---|
| \n Default:\n | \n\n resolver_timeout 30s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a timeout for name resolution, for example:\n
\nresolver_timeout 5s;\n
\n
| \n Syntax:\n | \n\n root \n | \n
|---|---|
| \n Default:\n | \n\n root html;\n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
\nSets the root directory for requests.\nFor example, with the following configuration\n
\nlocation /i/ {\n root /data/w3;\n}\n \nThe /data/w3/i/top.gif file will be sent in response to\nthe “/i/top.gif” request.\n
\nThe path value can contain variables,\nexcept $document_root and $realpath_root.\n
\nA path to the file is constructed by merely adding a URI to the value\nof the root directive.\nIf a URI has to be modified, the\nalias directive should be used.\n
| \n Syntax:\n | \n\n satisfy \n | \n
|---|---|
| \n Default:\n | \n\n satisfy all;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nAllows access if all (all) or at least one\n(any) of the\nngx_http_access_module,\nngx_http_auth_basic_module,\nngx_http_auth_request_module,\nngx_http_auth_jwt_module\n(1.13.10),\nor\nngx_http_auth_oidc_module\n(1.27.4)\nmodules allow access.\n
\nExample:\n
\nlocation / {\n satisfy any;\n\n allow 192.168.1.0/32;\n deny all;\n\n auth_basic \"closed site\";\n auth_basic_user_file conf/htpasswd;\n}\n\n
| \n Syntax:\n | \n\n send_lowat \n | \n
|---|---|
| \n Default:\n | \n\n send_lowat 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIf the directive is set to a non-zero value, nginx will try to minimize\nthe number of send operations on client sockets by using either\nNOTE_LOWAT flag of the\nkqueue method\nor the SO_SNDLOWAT socket option.\nIn both cases the specified size is used.\n
\nThis directive is ignored on Linux, Solaris, and Windows.\n
| \n Syntax:\n | \n\n send_timeout \n | \n
|---|---|
| \n Default:\n | \n\n send_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a timeout for transmitting a response to the client.\nThe timeout is set only between two successive write operations,\nnot for the transmission of the whole response.\nIf the client does not receive anything within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n sendfile \n | \n
|---|---|
| \n Default:\n | \n\n sendfile off;\n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
\nEnables or disables the use of\nsendfile().\n
\nStarting from nginx 0.8.12 and FreeBSD 5.2.1,\naio can be used to pre-load data\nfor sendfile():\n
\nlocation /video/ {\n sendfile on;\n tcp_nopush on;\n aio on;\n}\n \nIn this configuration, sendfile() is called with\nthe SF_NODISKIO flag which causes it not to block on disk I/O,\nbut, instead, report back that the data are not in memory.\nnginx then initiates an asynchronous data load by reading one byte.\nOn the first read, the FreeBSD kernel loads the first 128K bytes\nof a file into memory, although next reads will only load data in 16K chunks.\nThis can be changed using the\nread_ahead directive.\n
\nBefore version 1.7.11, pre-loading could be enabled with\naio sendfile;.\n\n
| \n Syntax:\n | \n\n sendfile_max_chunk \n | \n
|---|---|
| \n Default:\n | \n\n sendfile_max_chunk 2m;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nLimits the amount of data that can be\ntransferred in a single sendfile() call.\nWithout the limit, one fast connection may seize the worker process entirely.\n
\nPrior to version 1.21.4, by default there was no limit.\n
\n
| \n Syntax:\n | \n\n server { ... }\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nSets configuration for a virtual server.\nThere is no clear separation between IP-based (based on the IP address)\nand name-based (based on the “Host” request header field)\nvirtual servers.\nInstead, the listen directives describe all\naddresses and ports that should accept connections for the server, and the\nserver_name directive lists all server names.\nExample configurations are provided in the\n“How nginx processes a request” document.\n
| \n Syntax:\n | \n\n server_name \n | \n
|---|---|
| \n Default:\n | \n\n server_name \"\";\n | \n
| \n Context:\n | \n\n server\n | \n
\nSets names of a virtual server, for example:\n
\nserver {\n server_name example.com www.example.com;\n}\n\n
\nThe first name becomes the primary server name.\n
\nServer names can include an asterisk (“*”)\nreplacing the first or last part of a name:\n
\nserver {\n server_name example.com *.example.com www.example.*;\n}\n\nSuch names are called wildcard names.\n
\nThe first two of the names mentioned above can be combined in one:\n
\nserver {\n server_name .example.com;\n}\n\n
\nIt is also possible to use regular expressions in server names,\npreceding the name with a tilde (“~”):\n
\nserver {\n server_name www.example.com ~^www\\d+\\.example\\.com$;\n}\n\n
\nRegular expressions can contain captures (0.7.40) that can later\nbe used in other directives:\n
\nserver {\n server_name ~^(www\\.)?(.+)$;\n\n location / {\n root /sites/$2;\n }\n}\n\nserver {\n server_name _;\n\n location / {\n root /sites/default;\n }\n}\n\n
\nNamed captures in regular expressions create variables (0.8.25)\nthat can later be used in other directives:\n
\nserver {\n server_name ~^(www\\.)?(?<domain>.+)$;\n\n location / {\n root /sites/$domain;\n }\n}\n\nserver {\n server_name _;\n\n location / {\n root /sites/default;\n }\n}\n\n
\nIf the directive’s parameter is set to “$hostname” (0.9.4), the\nmachine’s hostname is inserted.\n
\nIt is also possible to specify an empty server name (0.7.11):\n
\nserver {\n server_name www.example.com \"\";\n}\n\nIt allows this server to process requests without the “Host”\nheader field — instead of the default server — for the given address:port pair.\nThis is the default setting.\n
\nBefore 0.8.48, the machine’s hostname was used by default.\n
\n
\nThe search is performed in the following order of priority\nand terminates on the first matching variant:\n
*.example.com”\nmail.*”\n\n
\nDetailed description of server names is provided in a separate\nServer names document.\n
| \n Syntax:\n | \n\n server_name_in_redirect \n | \n
|---|---|
| \n Default:\n | \n\n server_name_in_redirect off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables the use of the primary server name, specified by the\nserver_name directive,\nin absolute redirects issued by nginx.\nWhen the use of the primary server name is disabled, the name from the\n“Host” request header field is used.\nIf this field is not present, the IP address of the server is used.\n
\nThe use of a port in redirects is controlled by\nthe port_in_redirect directive.\n
| \n Syntax:\n | \n\n server_names_hash_bucket_size \n | \n
|---|---|
| \n Default:\n | \n\n server_names_hash_bucket_size 32|64|128;\n | \n
| \n Context:\n | \n\n http\n | \n
\nSets the bucket size for the server names hash tables.\nThe default value depends on the size of the processor’s cache line.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
| \n Syntax:\n | \n\n server_names_hash_max_size \n | \n
|---|---|
| \n Default:\n | \n\n server_names_hash_max_size 512;\n | \n
| \n Context:\n | \n\n http\n | \n
\nSets the maximum size of the server names hash tables.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
| \n Syntax:\n | \n\n server_tokens \n \n | \n
|---|---|
| \n Default:\n | \n\n server_tokens on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables emitting nginx version on error pages and in the\n“Server” response header field.\n
\nThe build parameter (1.11.10) enables emitting\na build name\nalong with nginx version.\n
\nAdditionally, as part of our\ncommercial subscription,\nstarting from version 1.9.13\nthe signature on error pages and\nthe “Server” response header field value\ncan be set explicitly using the string with variables.\nAn empty string disables the emission of the “Server” field.\n
| \n Syntax:\n | \n\n subrequest_output_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n subrequest_output_buffer_size 4k|8k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.13.10.\n
\nSets the size of the buffer used for\nstoring the response body of a subrequest.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\nIt can be made smaller, however.\n
\nThe directive is applicable only for subrequests\nwith response bodies saved into memory.\nFor example, such subrequests are created by\nSSI.\n
| \n Syntax:\n | \n\n tcp_nodelay \n | \n
|---|---|
| \n Default:\n | \n\n tcp_nodelay on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables the use of the TCP_NODELAY option.\nThe option is enabled when a connection is transitioned into the\nkeep-alive state.\nAdditionally, it is enabled on SSL connections,\nfor unbuffered proxying,\nand for WebSocket proxying.\n
| \n Syntax:\n | \n\n tcp_nopush \n | \n
|---|---|
| \n Default:\n | \n\n tcp_nopush off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables the use of\nthe TCP_NOPUSH socket option on FreeBSD\nor the TCP_CORK socket option on Linux.\nThe options are enabled only when sendfile is used.\nEnabling the option allows\n
\n
| \n Syntax:\n | \n\n try_files try_files \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server, location\n | \n
\nChecks the existence of files in the specified order and uses\nthe first found file for request processing; the processing\nis performed in the current context.\nThe path to a file is constructed from the\nfile parameter\naccording to the\nroot and alias directives.\nIt is possible to check directory’s existence by specifying\na slash at the end of a name, e.g. “$uri/”.\nIf none of the files were found, an internal redirect to the\nuri specified in the last parameter is made.\nFor example:\n
\nlocation /images/ {\n try_files $uri /images/default.gif;\n}\n\nlocation = /images/default.gif {\n expires 30s;\n}\n \nThe last parameter can also point to a named location,\nas shown in examples below.\nStarting from version 0.7.51, the last parameter can also be a\ncode:\n
\nlocation / {\n try_files $uri $uri/index.html $uri.html =404;\n}\n\n
\nExample in proxying Mongrel:\n
\nlocation / {\n try_files /system/maintenance.html\n $uri $uri/index.html $uri.html\n @mongrel;\n}\n\nlocation @mongrel {\n proxy_pass http://mongrel;\n}\n\n
\nExample for Drupal/FastCGI:\n
\nlocation / {\n try_files $uri $uri/ @drupal;\n}\n\nlocation ~ \\.php$ {\n try_files $uri @drupal;\n\n fastcgi_pass ...;\n\n fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;\n fastcgi_param SCRIPT_NAME $fastcgi_script_name;\n fastcgi_param QUERY_STRING $args;\n\n ... other fastcgi_param's\n}\n\nlocation @drupal {\n fastcgi_pass ...;\n\n fastcgi_param SCRIPT_FILENAME /path/to/index.php;\n fastcgi_param SCRIPT_NAME /index.php;\n fastcgi_param QUERY_STRING q=$uri&$args;\n\n ... other fastcgi_param's\n}\n\nIn the following example,\n
\nlocation / {\n try_files $uri $uri/ @drupal;\n}\n \nthe try_files directive is equivalent to\n
\nlocation / {\n error_page 404 = @drupal;\n log_not_found off;\n}\n\nAnd here,\n
\nlocation ~ \\.php$ {\n try_files $uri @drupal;\n\n fastcgi_pass ...;\n\n fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;\n\n ...\n}\n \ntry_files checks the existence of the PHP file\nbefore passing the request to the FastCGI server.\n
\nExample for Wordpress and Joomla:\n
\nlocation / {\n try_files $uri $uri/ @wordpress;\n}\n\nlocation ~ \\.php$ {\n try_files $uri @wordpress;\n\n fastcgi_pass ...;\n\n fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;\n ... other fastcgi_param's\n}\n\nlocation @wordpress {\n fastcgi_pass ...;\n\n fastcgi_param SCRIPT_FILENAME /path/to/index.php;\n ... other fastcgi_param's\n}\n\n
| \n Syntax:\n | \n\n types { ... }\n | \n
|---|---|
| \n Default:\n | \n\n types {\n text/html html;\n image/gif gif;\n image/jpeg jpg;\n}\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nMaps file name extensions to MIME types of responses.\nExtensions are case-insensitive.\nSeveral extensions can be mapped to one type, for example:\n
\ntypes {\n application/octet-stream bin exe dll;\n application/octet-stream deb;\n application/octet-stream dmg;\n}\n\n
\nA sufficiently full mapping table is distributed with nginx in the\nconf/mime.types file.\n
\nTo make a particular location emit the\n“application/octet-stream”\nMIME type for all requests, the following configuration can be used:\n
\nlocation /download/ {\n types { }\n default_type application/octet-stream;\n}\n\n
| \n Syntax:\n | \n\n types_hash_bucket_size \n | \n
|---|---|
| \n Default:\n | \n\n types_hash_bucket_size 64;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the bucket size for the types hash tables.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
\nPrior to version 1.5.13,\nthe default value depended on the size of the processor’s cache line.\n
\n
| \n Syntax:\n | \n\n types_hash_max_size \n | \n
|---|---|
| \n Default:\n | \n\n types_hash_max_size 1024;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the maximum size of the types hash tables.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
| \n Syntax:\n | \n\n underscores_in_headers \n | \n
|---|---|
| \n Default:\n | \n\n underscores_in_headers off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nEnables or disables the use of underscores in client request header fields.\nWhen the use of underscores is disabled, request header fields whose names\ncontain underscores are\nmarked as invalid and become subject to the\nignore_invalid_headers directive.\n
\nIf the directive is specified on the server level,\nthe value from the default server can be used.\nDetails are provided in the\n“Virtual\nserver selection” section.\n
| \n Syntax:\n | \n\n variables_hash_bucket_size \n | \n
|---|---|
| \n Default:\n | \n\n variables_hash_bucket_size 64;\n | \n
| \n Context:\n | \n\n http\n | \n
\nSets the bucket size for the variables hash table.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
| \n Syntax:\n | \n\n variables_hash_max_size \n | \n
|---|---|
| \n Default:\n | \n\n variables_hash_max_size 1024;\n | \n
| \n Context:\n | \n\n http\n | \n
\nSets the maximum size of the variables hash table.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
\nPrior to version 1.5.13, the default value was 512.\n
\n
\n\n\n\nThe ngx_http_core_module module supports embedded variables\nwith names matching the Apache Server variables.\nFirst of all, these are variables representing client request header\nfields, such as $http_user_agent, $http_cookie,\nand so on.\nAlso there are other variables:\n
$arg_namename in the request line\n$args$binary_remote_addr$body_bytes_sent%B” parameter of the\nmod_log_config\nApache module\n$bytes_sent$connection$connection_requests$connection_time$content_length$content_typename cookie\n$document_root$document_uri$uri\n$host$hostname$http_name$httpson”\nif connection operates in SSL mode,\nor an empty string otherwise\n$is_args?” if a request line has arguments,\nor an empty string otherwise\n$is_request_port:” if\n$request_port is non-empty,\nor an empty string otherwise (1.29.3)\n$limit_rate$msec$nginx_version$pid$pipep” if request was pipelined, “.”\notherwise (1.3.12, 1.2.7)\n$proxy_protocol_addr\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
$proxy_protocol_port\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
$proxy_protocol_server_addr\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
$proxy_protocol_server_port\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
$proxy_protocol_tlv_namename can be a TLV type name or its numeric value.\nIn the latter case, the value is hexadecimal\nand should be prefixed with 0x:\n\n\nSSL TLVs can also be accessed by TLV type name\nor its numeric value,\nboth prefixed by\n$proxy_protocol_tlv_alpn\n$proxy_protocol_tlv_0x01\n
ssl_:\n\n\n\n$proxy_protocol_tlv_ssl_version\n$proxy_protocol_tlv_ssl_0x21\n
\nThe following TLV type names are supported:\n
alpn (0x01) - \nupper layer protocol used over the connection\nauthority (0x02) - \nhost name value passed by the client\nunique_id (0x05) - \nunique connection id\nnetns (0x30) - \nname of the namespace\nssl (0x20) - \nbinary SSL TLV structure\n\n
\n\n\nThe following SSL TLV type names are supported:\n
ssl_version (0x21) - \nSSL version used in client connection\nssl_cn (0x22) - \nSSL certificate Common Name\nssl_cipher (0x23) - \nname of the used cipher\nssl_sig_alg (0x24) - \nalgorithm used to sign the certificate\nssl_key_alg (0x25) - \npublic-key algorithm\n\n
\n\n\nAlso, the following special SSL TLV type name is supported:\n
ssl_verify - \nclient SSL certificate verification result,\n0 if the client presented a certificate\nand it was successfully verified,\nnon-zero otherwise.\n\n
\n\n\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
$query_string$args\n$realpath_root$remote_addr$remote_port$remote_user$request$request_body\nThe variable’s value is made available in locations\nprocessed by the\nproxy_pass,\nfastcgi_pass,\nuwsgi_pass,\nand\nscgi_pass\ndirectives when the request body was read to\na memory buffer.\n
\n$request_body_file\nAt the end of processing, the file needs to be removed.\nTo always write the request body to a file,\nclient_body_in_file_only needs to be enabled.\nWhen the name of a temporary file is passed in a proxied request\nor in a request to a FastCGI/uwsgi/SCGI server,\npassing the request body should be disabled by the\n\nproxy_pass_request_body off,\n\nfastcgi_pass_request_body off,\n\nuwsgi_pass_request_body off, or\n\nscgi_pass_request_body off\ndirectives, respectively.\n
\n$request_completionOK” if a request has completed,\nor an empty string otherwise\n$request_filename$request_id$request_length$request_methodGET” or “POST”\n$request_port$request_time$request_uri$schemehttp” or “https”\n$sent_http_name$sent_trailer_name$server_addr\nComputing a value of this variable usually requires one system call.\nTo avoid a system call, the listen directives\nmust specify addresses and use the bind parameter.\n
$server_name$server_port$server_protocolHTTP/1.0”,\n“HTTP/1.1”,\n“HTTP/2.0”,\nor\n“HTTP/3.0”\n$status$tcpinfo_rtt,\n$tcpinfo_rttvar,\n$tcpinfo_snd_cwnd,\n$tcpinfo_rcv_space\nTCP_INFO socket option\n$time_iso8601$time_iso8601_ms\n
\nThis variable is available as part of our\ncommercial subscription.\n
\n
\n$time_local$uri\nThe value of $uri may change during request processing,\ne.g. when doing internal redirects, or when using index files.\n
\n
\n\n| Example Configuration Directives create_full_put_path dav_access dav_methods min_delete_depth |
\nThe ngx_http_dav_module module is intended for file\nmanagement automation via the WebDAV protocol.\nThe module processes HTTP and WebDAV\nmethods PUT, DELETE, MKCOL, COPY, and MOVE.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_dav_module\nconfiguration parameter.\n
\n
\nWebDAV clients that require additional WebDAV methods to operate\nwill not work with this module.\n
\n
\n\n\n\n
\nlocation / {\n root /data/www;\n\n client_body_temp_path /data/client_temp;\n\n dav_methods PUT DELETE MKCOL COPY MOVE;\n\n create_full_put_path on;\n dav_access group:rw all:r;\n\n limit_except GET {\n allow 192.168.1.0/32;\n deny all;\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n create_full_put_path \n | \n
|---|---|
| \n Default:\n | \n\n create_full_put_path off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nThe WebDAV specification only allows creating files in already\nexisting directories.\nThis directive allows creating all needed intermediate directories.\n
| \n Syntax:\n | \n\n dav_access \n | \n
|---|---|
| \n Default:\n | \n\n dav_access user:rw;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets access permissions for newly created files and directories, e.g.:\n
\ndav_access user:rw group:rw all:r;\n
\n
\nIf any group or all access permissions\nare specified then user permissions may be omitted:\n
\ndav_access group:rw all:r;\n
\n
| \n Syntax:\n | \n\n dav_methods \n \n | \n
|---|---|
| \n Default:\n | \n\n dav_methods off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nAllows the specified HTTP and WebDAV methods.\nThe parameter off denies all methods processed\nby this module.\nThe following methods are supported:\nPUT, DELETE, MKCOL,\nCOPY, and MOVE.\n
\nA file uploaded with the PUT method is first written to a temporary file,\nand then the file is renamed.\nStarting from version 0.8.9, temporary files and the persistent store\ncan be put on different file systems.\nHowever, be aware that in this case a file is copied\nacross two file systems instead of the cheap renaming operation.\nIt is thus recommended that for any given location both saved files and a\ndirectory holding temporary files, set by the\nclient_body_temp_path\ndirective, are put on the same file system.\n
\nWhen creating a file with the PUT method, it is possible to specify\nthe modification date by passing it in the “Date”\nheader field.\n
| \n Syntax:\n | \n\n min_delete_depth \n | \n
|---|---|
| \n Default:\n | \n\n min_delete_depth 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nAllows the DELETE method to remove files provided that\nthe number of elements in a request path is not less than the specified\nnumber.\nFor example, the directive\n
\nmin_delete_depth 4;\n
\nallows removing files on requests\n
\n/users/00/00/name\n/users/00/00/name/pic.jpg\n/users/00/00/page.html\n
\nand denies the removal of\n
\n/users/00/00\n
\n
\n\n| Example Configuration Directives empty_gif |
\nThe ngx_http_empty_gif_module module emits\nsingle-pixel transparent GIF.\n
\n
\nlocation = /_.gif {\n empty_gif;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n empty_gif;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nTurns on module processing in a surrounding location.\n
\n\n| Example Configuration Directives f4f f4f_buffer_size |
\nThe ngx_http_f4f_module module provides\nserver-side support for Adobe HTTP Dynamic Streaming (HDS).\n
\nThis module implements handling of HTTP Dynamic Streaming requests in the\n“/videoSeg1-Frag1” form — extracting the needed fragment\nfrom the videoSeg1.f4f file using the videoSeg1.f4x\nindex file.\nThis module is an alternative to the Adobe’s f4f module (HTTP Origin Module)\nfor Apache.\n
\nUsual pre-processing with Adobe’s f4fpackager is required, see relevant\ndocumentation for details.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nlocation /video/ {\n f4f;\n ...\n}\n\n
\n\n\n| \n Syntax:\n | \n\n f4f;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nTurns on module processing in the surrounding location.\n
| \n Syntax:\n | \n\n f4f_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n f4f_buffer_size 512k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the size of the buffer used for\nreading the .f4x index file.\n
\nThe ngx_http_fastcgi_module module allows passing\nrequests to a FastCGI server.\n
\n
\nlocation / {\n fastcgi_pass localhost:9000;\n fastcgi_index index.php;\n\n fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;\n fastcgi_param QUERY_STRING $query_string;\n fastcgi_param REQUEST_METHOD $request_method;\n fastcgi_param CONTENT_TYPE $content_type;\n fastcgi_param CONTENT_LENGTH $content_length;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n fastcgi_allow_upstream \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nDefines conditions under which access to a FastCGI server\nis allowed or denied.\nIf all string parameters are not empty\nand not equal to “0” then the access is allowed.\nThe conditions are evaluated each time\nbefore a connection to a FastCGI server is established.\nParameter values can contain variables:\n
\ngeo $upstream_last_addr $allow {\n volatile;\n 10.10.0.0/24 1;\n}\n\nserver {\n listen 127.0.0.1:8080;\n\n location / {\n fastcgi_pass localhost:9000;\n fastcgi_allow_upstream $allow;\n ...\n }\n}\n\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n fastcgi_bind \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.8.22.\n
\nMakes outgoing connections to a FastCGI server originate\nfrom the specified local IP address with an optional port (1.11.2).\nParameter value can contain variables (1.3.12).\nThe special value off (1.3.12) cancels the effect\nof the fastcgi_bind directive\ninherited from the previous configuration level, which allows the\nsystem to auto-assign the local IP address and port.\n
\nThe transparent parameter (1.11.0) allows\noutgoing connections to a FastCGI server originate\nfrom a non-local IP address,\nfor example, from a real IP address of a client:\n
\nfastcgi_bind $remote_addr transparent;\n
\nIn order for this parameter to work,\nit is usually necessary to run nginx worker processes with the\nsuperuser privileges.\nOn Linux it is not required (1.13.8) as if\nthe transparent parameter is specified, worker processes\ninherit the CAP_NET_RAW capability from the master process.\nIt is also necessary to configure kernel routing table\nto intercept network traffic from the FastCGI server.\n
| \n Syntax:\n | \n\n fastcgi_bind_dynamic \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_bind_dynamic off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nWhen enabled, makes the bind operation\nat each connection attempt.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n fastcgi_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_buffer_size 4k|8k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the size of the buffer used for reading the first part\nof the response received from the FastCGI server.\nThis part usually contains a small response header;\nif it exceeds the buffer size, the response is considered\ninvalid.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\nIt can be made smaller, however.\n
| \n Syntax:\n | \n\n fastcgi_buffering \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_buffering on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.6.\n
\nEnables or disables buffering of responses from the FastCGI server.\n
\nWhen buffering is enabled, nginx receives a response from the FastCGI server\nas soon as possible, saving it into the buffers set by the\nfastcgi_buffer_size and fastcgi_buffers directives.\nIf the whole response does not fit into memory, a part of it can be saved\nto a temporary file on the disk.\nWriting to temporary files is controlled by the\nfastcgi_max_temp_file_size and\nfastcgi_temp_file_write_size directives.\n
\nWhen buffering is disabled, the response is passed to a client synchronously,\nimmediately as it is received.\nnginx will not try to read the whole response from the FastCGI server.\nThe maximum size of the data that nginx can receive from the server\nat a time is set by the fastcgi_buffer_size directive.\n
\nBuffering can also be enabled or disabled by passing\n“yes” or “no” in the\n“X-Accel-Buffering” response header field.\nThis capability can be disabled using the\nfastcgi_ignore_headers directive.\n
| \n Syntax:\n | \n\n fastcgi_buffers \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_buffers 8 4k|8k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the number and size of the\nbuffers used for reading a response from the FastCGI server,\nfor a single connection.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\n
| \n Syntax:\n | \n\n fastcgi_busy_buffers_size \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_busy_buffers_size 8k|16k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nWhen buffering of responses from the FastCGI\nserver is enabled, limits the total size of buffers that\ncan be busy sending a response to the client while the response is not\nyet fully read.\nIn the meantime, the rest of the buffers can be used for reading the response\nand, if needed, buffering part of the response to a temporary file.\nBy default, size is limited by the size of two buffers set by the\nfastcgi_buffer_size and fastcgi_buffers directives.\n
| \n Syntax:\n | \n\n fastcgi_cache \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_cache off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a shared memory zone used for caching.\nThe same zone can be used in several places.\nParameter value can contain variables (1.7.9).\nThe off parameter disables caching inherited\nfrom the previous configuration level.\n
| \n Syntax:\n | \n\n fastcgi_cache_background_update \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_cache_background_update off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.11.10.\n
\nAllows starting a background subrequest\nto update an expired cache item,\nwhile a stale cached response is returned to the client.\nNote that it is necessary to\nallow\nthe usage of a stale cached response when it is being updated.\n
| \n Syntax:\n | \n\n fastcgi_cache_bypass \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines conditions under which the response will not be taken from a cache.\nIf at least one value of the string parameters is not empty and is not\nequal to “0” then the response will not be taken from the cache:\n
\nfastcgi_cache_bypass $cookie_nocache $arg_nocache$arg_comment;\nfastcgi_cache_bypass $http_pragma $http_authorization;\n
\nCan be used along with the fastcgi_no_cache directive.\n
| \n Syntax:\n | \n\n fastcgi_cache_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a key for caching, for example\n
\nfastcgi_cache_key localhost:9000$request_uri;\n
\n
| \n Syntax:\n | \n\n fastcgi_cache_lock \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_cache_lock off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.12.\n
\nWhen enabled, only one request at a time will be allowed to populate\na new cache element identified according to the fastcgi_cache_key\ndirective by passing a request to a FastCGI server.\nOther requests of the same cache element will either wait\nfor a response to appear in the cache or the cache lock for\nthis element to be released, up to the time set by the\nfastcgi_cache_lock_timeout directive.\n
| \n Syntax:\n | \n\n fastcgi_cache_lock_age \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_cache_lock_age 5s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.8.\n
\nIf the last request passed to the FastCGI server\nfor populating a new cache element\nhas not completed for the specified time,\none more request may be passed to the FastCGI server.\n
| \n Syntax:\n | \n\n fastcgi_cache_lock_timeout \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_cache_lock_timeout 5s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.12.\n
\nSets a timeout for fastcgi_cache_lock.\nWhen the time expires,\nthe request will be passed to the FastCGI server,\nhowever, the response will not be cached.\n
\nBefore 1.7.8, the response could be cached.\n
\n
| \n Syntax:\n | \n\n fastcgi_cache_max_range_offset \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.11.6.\n
\nSets an offset in bytes for byte-range requests.\nIf the range is beyond the offset,\nthe range request will be passed to the FastCGI server\nand the response will not be cached.\n
| \n Syntax:\n | \n\n fastcgi_cache_methods \n \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_cache_methods GET HEAD;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.59.\n
\nIf the client request method is listed in this directive then\nthe response will be cached.\n“GET” and “HEAD” methods are always\nadded to the list, though it is recommended to specify them explicitly.\nSee also the fastcgi_no_cache directive.\n
| \n Syntax:\n | \n\n fastcgi_cache_min_uses \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_cache_min_uses 1;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the number of requests after which the response\nwill be cached.\n
| \n Syntax:\n | \n\n fastcgi_cache_path \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nSets the path and other parameters of a cache.\nCache data are stored in files.\nBoth the key and file name in a cache are a result of\napplying the MD5 function to the proxied URL.\n\nThe levels parameter defines hierarchy levels of a cache:\nfrom 1 to 3, each level accepts values 1 or 2.\nFor example, in the following configuration\n
\nfastcgi_cache_path /data/nginx/cache levels=1:2 keys_zone=one:10m;\n
\nfile names in a cache will look like this:\n
\n/data/nginx/cache/c/29/b7f54b2df7773722d382f4809d65029c\n
\n
\nA cached response is first written to a temporary file,\nand then the file is renamed.\nStarting from version 0.8.9, temporary files and the cache can be put on\ndifferent file systems.\nHowever, be aware that in this case a file is copied\nacross two file systems instead of the cheap renaming operation.\nIt is thus recommended that for any given location both cache and a directory\nholding temporary files\nare put on the same file system.\nA directory for temporary files is set based on\nthe use_temp_path parameter (1.7.10).\nIf this parameter is omitted or set to the value on,\nthe directory set by the fastcgi_temp_path directive\nfor the given location will be used.\nIf the value is set to off,\ntemporary files will be put directly in the cache directory.\n
\nIn addition, all active keys and information about data are stored\nin a shared memory zone, whose name and size\nare configured by the keys_zone parameter.\nOne megabyte zone can store about 8 thousand keys.\n
\nAs part of\ncommercial subscription,\nthe shared memory zone also stores extended\ncache information,\nthus, it is required to specify a larger zone size for the same number of keys.\nFor example,\none megabyte zone can store about 4 thousand keys.\n
\n
\nCached data that are not accessed during the time specified by the\ninactive parameter get removed from the cache\nregardless of their freshness.\nBy default, inactive is set to 10 minutes.\n
\nThe special “cache manager” process monitors the maximum cache size set\nby the max_size parameter,\nand the minimum amount of free space set\nby the min_free (1.19.1) parameter\non the file system with cache.\nWhen the size is exceeded or there is not enough free space,\nit removes the least recently used data.\nThe data is removed in iterations configured by\nmanager_files,\nmanager_threshold, and\nmanager_sleep parameters (1.11.5).\nDuring one iteration no more than manager_files items\nare deleted (by default, 100).\nThe duration of one iteration is limited by the\nmanager_threshold parameter (by default, 200 milliseconds).\nBetween iterations, a pause configured by the manager_sleep\nparameter (by default, 50 milliseconds) is made.\n
\nA minute after the start the special “cache loader” process is activated.\nIt loads information about previously cached data stored on file system\ninto a cache zone.\nThe loading is also done in iterations.\nDuring one iteration no more than loader_files items\nare loaded (by default, 100).\nBesides, the duration of one iteration is limited by the\nloader_threshold parameter (by default, 200 milliseconds).\nBetween iterations, a pause configured by the loader_sleep\nparameter (by default, 50 milliseconds) is made.\n
\nAdditionally,\nthe following parameters are available as part of our\ncommercial subscription:\n
\n
purger=on|off\non\n(default is off)\nwill activate the “cache purger” process that\npermanently iterates through all cache entries\nand deletes the entries that match the wildcard key.\npurger_files=number\npurger_files is set to 10.\npurger_threshold=number\npurger_threshold is set to 50 milliseconds.\npurger_sleep=number\npurger_sleep is set to 50 milliseconds.\n\n
\n
\nIn versions 1.7.3, 1.7.7, and 1.11.10 cache header format has been changed.\nPreviously cached responses will be considered invalid\nafter upgrading to a newer nginx version.\n
\n
| \n Syntax:\n | \n\n fastcgi_cache_purge string ...;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.7.\n
\nDefines conditions under which the request will be considered a cache\npurge request.\nIf at least one value of the string parameters is not empty and is not equal\nto “0” then the cache entry with a corresponding\ncache key is removed.\nThe result of successful operation is indicated by returning\nthe 204 (No Content) response.\n
\nIf the cache key of a purge request ends\nwith an asterisk (“*”), all cache entries matching the\nwildcard key will be removed from the cache.\nHowever, these entries will remain on the disk until they are deleted\nfor either inactivity,\nor processed by the cache purger (1.7.12),\nor a client attempts to access them.\n
\nExample configuration:\n
\nfastcgi_cache_path /data/nginx/cache keys_zone=cache_zone:10m;\n\nmap $request_method $purge_method {\n PURGE 1;\n default 0;\n}\n\nserver {\n ...\n location / {\n fastcgi_pass backend;\n fastcgi_cache cache_zone;\n fastcgi_cache_key $uri;\n fastcgi_cache_purge $purge_method;\n }\n}\n\n
\nThis functionality is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n fastcgi_cache_revalidate \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_cache_revalidate off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.7.\n
\nEnables revalidation of expired cache items using conditional requests with\nthe “If-Modified-Since” and “If-None-Match”\nheader fields.\n
| \n Syntax:\n | \n\n fastcgi_cache_use_stale \n \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_cache_use_stale off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines in which cases a stale cached response can be used\nwhen an error occurs during communication with the FastCGI server.\nThe directive’s parameters match the parameters of the\nfastcgi_next_upstream directive.\n
\nThe error parameter also permits\nusing a stale cached response if a FastCGI server to process a request\ncannot be selected.\n
\nAdditionally, the updating parameter permits\nusing a stale cached response if it is currently being updated.\nThis allows minimizing the number of accesses to FastCGI servers\nwhen updating cached data.\n
\nUsing a stale cached response\ncan also be enabled directly in the response header\nfor a specified number of seconds after the response became stale (1.11.10).\nThis has lower priority than using the directive parameters.\n
\n
\nTo minimize the number of accesses to FastCGI servers when\npopulating a new cache element, the fastcgi_cache_lock\ndirective can be used.\n
| \n Syntax:\n | \n\n fastcgi_cache_valid [\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets caching time for different response codes.\nFor example, the following directives\n
\nfastcgi_cache_valid 200 302 10m;\nfastcgi_cache_valid 404 1m;\n
\nset 10 minutes of caching for responses with codes 200 and 302\nand 1 minute for responses with code 404.\n
\nIf only caching time is specified\n
\nfastcgi_cache_valid 5m;\n
\nthen only 200, 301, and 302 responses are cached.\n
\nIn addition, the any parameter can be specified\nto cache any responses:\n
\nfastcgi_cache_valid 200 302 10m;\nfastcgi_cache_valid 301 1h;\nfastcgi_cache_valid any 1m;\n
\n
\nParameters of caching can also be set directly\nin the response header.\nThis has higher priority than setting of caching time using the directive.\n
@ prefix, it sets an absolute\ntime in seconds since Epoch, up to which the response may be cached.\n*”, such a\nresponse will not be cached (1.7.7).\nIf the header includes the “Vary” field\nwith another value, such a response will be cached\ntaking into account the corresponding request header fields (1.7.7).\n\nProcessing of one or more of these response header fields can be disabled\nusing the fastcgi_ignore_headers directive.\n
| \n Syntax:\n | \n\n fastcgi_catch_stderr \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a string to search for in the error stream of a response\nreceived from a FastCGI server.\nIf the string is found then it is considered that the FastCGI\nserver has returned an invalid response.\nThis allows handling application errors in nginx, for example:\n
\nlocation /php/ {\n fastcgi_pass backend:9000;\n ...\n fastcgi_catch_stderr \"PHP Fatal error\";\n fastcgi_next_upstream error timeout invalid_header;\n}\n\n
| \n Syntax:\n | \n\n fastcgi_connect_timeout \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_connect_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a timeout for establishing a connection with a FastCGI server.\nIt should be noted that this timeout cannot usually exceed 75 seconds.\n
| \n Syntax:\n | \n\n fastcgi_force_ranges \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_force_ranges off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.7.\n
\nEnables byte-range support\nfor both cached and uncached responses from the FastCGI server\nregardless of the “Accept-Ranges” field in these responses.\n
| \n Syntax:\n | \n\n fastcgi_hide_header \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nBy default,\nnginx does not pass the header fields “Status” and\n“X-Accel-...” from the response of a FastCGI\nserver to a client.\nThe fastcgi_hide_header directive sets additional fields\nthat will not be passed.\nIf, on the contrary, the passing of fields needs to be permitted,\nthe fastcgi_pass_header directive can be used.\n
| \n Syntax:\n | \n\n fastcgi_ignore_client_abort \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_ignore_client_abort off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines whether the connection with a FastCGI server should be\nclosed when a client closes the connection without waiting\nfor a response.\n
| \n Syntax:\n | \n\n fastcgi_ignore_headers \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDisables processing of certain response header fields from the FastCGI server.\nThe following fields can be ignored: “X-Accel-Redirect”,\n“X-Accel-Expires”, “X-Accel-Limit-Rate” (1.1.6),\n“X-Accel-Buffering” (1.1.6),\n“X-Accel-Charset” (1.1.6), “Expires”,\n“Cache-Control”, “Set-Cookie” (0.8.44),\nand “Vary” (1.7.7).\n
\nIf not disabled, processing of these header fields has the following\neffect:\n
\n
| \n Syntax:\n | \n\n fastcgi_index \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a file name that will be appended after a URI that ends with\na slash, in the value of the $fastcgi_script_name variable.\nFor example, with these settings\n
\nfastcgi_index index.php;\nfastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;\n
\nand the “/page.php” request,\nthe SCRIPT_FILENAME parameter will be equal to\n“/home/www/scripts/php/page.php”,\nand with the “/” request it will be equal to\n“/home/www/scripts/php/index.php”.\n
| \n Syntax:\n | \n\n fastcgi_intercept_errors \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_intercept_errors off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines whether FastCGI server responses with codes greater than or equal\nto 300 should be passed to a client\nor be intercepted and redirected to nginx for processing\nwith the error_page directive.\n
| \n Syntax:\n | \n\n fastcgi_keep_conn \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_keep_conn off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.4.\n
\nBy default, a FastCGI server will close a connection right after\nsending the response.\nHowever, when this directive is set to the value on,\nnginx will instruct a FastCGI server to keep connections open.\nThis is necessary, in particular, for\nkeepalive\nconnections to FastCGI servers to function.\n
| \n Syntax:\n | \n\n fastcgi_limit_rate \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_limit_rate 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.7.\n
\nLimits the speed of reading the response from the FastCGI server.\nThe rate is specified in bytes per second.\nThe zero value disables rate limiting.\nThe limit is set per a request, and so if nginx simultaneously opens\ntwo connections to the FastCFI server,\nthe overall rate will be twice as much as the specified limit.\nThe limitation works only if\nbuffering of responses from the FastCGI\nserver is enabled.\nParameter value can contain variables (1.27.0).\n
| \n Syntax:\n | \n\n fastcgi_max_temp_file_size \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_max_temp_file_size 1024m;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nWhen buffering of responses from the FastCGI\nserver is enabled, and the whole response does not fit into the buffers\nset by the fastcgi_buffer_size and fastcgi_buffers\ndirectives, a part of the response can be saved to a temporary file.\nThis directive sets the maximum size of the temporary file.\nThe size of data written to the temporary file at a time is set\nby the fastcgi_temp_file_write_size directive.\n
\nThe zero value disables buffering of responses to temporary files.\n
\n
\nThis restriction does not apply to responses\nthat will be cached\nor stored on disk.\n
\n
| \n Syntax:\n | \n\n fastcgi_next_upstream \n \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_next_upstream error timeout;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies in which cases a request should be passed to the next server:\n
errortimeoutdenied\n
\nThis parameter is available as part of our\ncommercial subscription.\n
\n
\ninvalid_headerhttp_500http_503http_403http_404http_429non_idempotentPOST, LOCK, PATCH)\nare not passed to the next server\nif a request has been sent to an upstream server (1.9.13);\nenabling this option explicitly allows retrying such requests;\noff\n
\nOne should bear in mind that passing a request to the next server is\nonly possible if nothing has been sent to a client yet.\nThat is, if an error or timeout occurs in the middle of the\ntransferring of a response, fixing this is impossible.\n
\nThe directive also defines what is considered an\nunsuccessful\nattempt of communication with a server.\nThe cases of error, timeout,\ndenied and\ninvalid_header are always considered unsuccessful attempts,\neven if they are not specified in the directive.\nThe cases of http_500, http_503,\nand http_429 are\nconsidered unsuccessful attempts only if they are specified in the directive.\nThe cases of http_403 and http_404\nare never considered unsuccessful attempts.\n
\nPassing a request to the next server can be limited by\nthe number of tries\nand by time.\n
| \n Syntax:\n | \n\n fastcgi_next_upstream_timeout \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_next_upstream_timeout 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.5.\n
\nLimits the time during which a request can be passed to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n fastcgi_next_upstream_tries \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_next_upstream_tries 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.5.\n
\nLimits the number of possible tries for passing a request to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n fastcgi_no_cache \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines conditions under which the response will not be saved to a cache.\nIf at least one value of the string parameters is not empty and is not\nequal to “0” then the response will not be saved:\n
\nfastcgi_no_cache $cookie_nocache $arg_nocache$arg_comment;\nfastcgi_no_cache $http_pragma $http_authorization;\n
\nCan be used along with the fastcgi_cache_bypass directive.\n
| \n Syntax:\n | \n\n fastcgi_param \n \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_param HTTP_HOST $host$is_request_port$request_port;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a parameter that should be passed to the FastCGI server.\nThe value can contain text, variables, and their combination.\nThese directives are inherited from the previous configuration level\nif and only if there are no fastcgi_param directives\ndefined on the current level.\n
\nThe following example shows the minimum required settings for PHP:\n
\nfastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;\nfastcgi_param QUERY_STRING $query_string;\n
\n
\nThe SCRIPT_FILENAME parameter is used in PHP for\ndetermining the script name, and the QUERY_STRING\nparameter is used to pass request parameters.\n
\nFor scripts that process POST requests, the\nfollowing three parameters are also required:\n
\nfastcgi_param REQUEST_METHOD $request_method;\nfastcgi_param CONTENT_TYPE $content_type;\nfastcgi_param CONTENT_LENGTH $content_length;\n
\n
\nIf PHP was built with the --enable-force-cgi-redirect\nconfiguration parameter, the REDIRECT_STATUS parameter\nshould also be passed with the value “200”:\n
\nfastcgi_param REDIRECT_STATUS 200;\n
\n
\nIf the directive is specified with if_not_empty (1.1.11) then\nsuch a parameter will be passed to the server only if its value is not empty:\n
\nfastcgi_param HTTPS $https if_not_empty;\n
\n
| \n Syntax:\n | \n\n fastcgi_pass \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location, if in location\n | \n
\nSets the address of a FastCGI server.\nThe address can be specified as a domain name or IP address,\nand a port:\n
\nfastcgi_pass localhost:9000;\n
\nor as a UNIX-domain socket path:\n
\nfastcgi_pass unix:/tmp/fastcgi.socket;\n
\n
\nIf a domain name resolves to several addresses, all of them will be\nused in a round-robin fashion.\nIn addition, an address can be specified as a\nserver group.\n
\nParameter value can contain variables.\nIn this case, if an address is specified as a domain name,\nthe name is searched among the described\nserver groups,\nand, if not found, is determined using a\nresolver.\n
| \n Syntax:\n | \n\n fastcgi_pass_header \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nPermits passing otherwise disabled header\nfields from a FastCGI server to a client.\n
| \n Syntax:\n | \n\n fastcgi_pass_request_body \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_pass_request_body on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIndicates whether the original request body is passed\nto the FastCGI server.\nSee also the fastcgi_pass_request_headers directive.\n
| \n Syntax:\n | \n\n fastcgi_pass_request_headers \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_pass_request_headers on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIndicates whether the header fields of the original request are passed\nto the FastCGI server.\nSee also the fastcgi_pass_request_body directive.\n
| \n Syntax:\n | \n\n fastcgi_read_timeout \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_read_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a timeout for reading a response from the FastCGI server.\nThe timeout is set only between two successive read operations,\nnot for the transmission of the whole response.\nIf the FastCGI server does not transmit anything within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n fastcgi_request_buffering \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_request_buffering on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.11.\n
\nEnables or disables buffering of a client request body.\n
\nWhen buffering is enabled, the entire request body is\nread\nfrom the client before sending the request to a FastCGI server.\n
\nWhen buffering is disabled, the request body is sent to the FastCGI server\nimmediately as it is received.\nIn this case, the request cannot be passed to the\nnext server\nif nginx already started sending the request body.\n
| \n Syntax:\n | \n\n fastcgi_request_dynamic \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_request_dynamic off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nEnables or disables creation of a separate request instance\nfor each FastCGI server.\nBy default, a single request is used for all FastCGI servers.\nIf enabled, a separate request instance is created,\nallowing per-server request customization.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n fastcgi_send_lowat \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_send_lowat 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIf the directive is set to a non-zero value, nginx will try to\nminimize the number\nof send operations on outgoing connections to a FastCGI server by using either\nNOTE_LOWAT flag of the\nkqueue method,\nor the SO_SNDLOWAT socket option,\nwith the specified size.\n
\nThis directive is ignored on Linux, Solaris, and Windows.\n
| \n Syntax:\n | \n\n fastcgi_send_timeout \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_send_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a timeout for transmitting a request to the FastCGI server.\nThe timeout is set only between two successive write operations,\nnot for the transmission of the whole request.\nIf the FastCGI server does not receive anything within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n fastcgi_socket_keepalive \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_socket_keepalive off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.15.6.\n
\nConfigures the “TCP keepalive” behavior\nfor outgoing connections to a FastCGI server.\nBy default, the operating system’s settings are in effect for the socket.\nIf the directive is set to the value “on”, the\nSO_KEEPALIVE socket option is turned on for the socket.\n
| \n Syntax:\n | \n\n fastcgi_split_path_info \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nDefines a regular expression that captures a value for the\n$fastcgi_path_info variable.\nThe regular expression should have two captures: the first becomes\na value of the $fastcgi_script_name variable, the second\nbecomes a value of the $fastcgi_path_info variable.\nFor example, with these settings\n
\nlocation ~ ^(.+\\.php)(.*)$ {\n fastcgi_split_path_info ^(.+\\.php)(.*)$;\n fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;\n fastcgi_param PATH_INFO $fastcgi_path_info;\n \nand the “/show.php/article/0001” request,\nthe SCRIPT_FILENAME parameter will be equal to\n“/path/to/php/show.php”, and the\nPATH_INFO parameter will be equal to\n“/article/0001”.\n
| \n Syntax:\n | \n\n fastcgi_store \n \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_store off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables saving of files to a disk.\nThe on parameter saves files with paths\ncorresponding to the directives\nalias or\nroot.\nThe off parameter disables saving of files.\nIn addition, the file name can be set explicitly using the\nstring with variables:\n
\nfastcgi_store /data/www$original_uri;\n
\n
\nThe modification time of files is set according to the received\n“Last-Modified” response header field.\nThe response is first written to a temporary file,\nand then the file is renamed.\nStarting from version 0.8.9, temporary files and the persistent store\ncan be put on different file systems.\nHowever, be aware that in this case a file is copied\nacross two file systems instead of the cheap renaming operation.\nIt is thus recommended that for any given location both saved files and a\ndirectory holding temporary files, set by the fastcgi_temp_path\ndirective, are put on the same file system.\n
\nThis directive can be used to create local copies of static unchangeable\nfiles, e.g.:\n
\nlocation /images/ {\n root /data/www;\n error_page 404 = /fetch$uri;\n}\n\nlocation /fetch/ {\n internal;\n\n fastcgi_pass backend:9000;\n ...\n\n fastcgi_store on;\n fastcgi_store_access user:rw group:rw all:r;\n fastcgi_temp_path /data/temp;\n\n alias /data/www/;\n}\n\n
| \n Syntax:\n | \n\n fastcgi_store_access \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_store_access user:rw;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets access permissions for newly created files and directories, e.g.:\n
\nfastcgi_store_access user:rw group:rw all:r;\n
\n
\nIf any group or all access permissions\nare specified then user permissions may be omitted:\n
\nfastcgi_store_access group:rw all:r;\n
\n
| \n Syntax:\n | \n\n fastcgi_temp_file_write_size \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_temp_file_write_size 8k|16k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nLimits the size of data written to a temporary file\nat a time, when buffering of responses from the FastCGI server\nto temporary files is enabled.\nBy default, size is limited by two buffers set by the\nfastcgi_buffer_size and fastcgi_buffers directives.\nThe maximum size of a temporary file is set by the\nfastcgi_max_temp_file_size directive.\n
| \n Syntax:\n | \n\n fastcgi_temp_path \n \n | \n
|---|---|
| \n Default:\n | \n\n fastcgi_temp_path fastcgi_temp;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a directory for storing temporary files\nwith data received from FastCGI servers.\nUp to three-level subdirectory hierarchy can be used underneath the specified\ndirectory.\nFor example, in the following configuration\n
\nfastcgi_temp_path /spool/nginx/fastcgi_temp 1 2;\n
\na temporary file might look like this:\n
\n/spool/nginx/fastcgi_temp/7/45/00000123457\n
\n
\nSee also the use_temp_path parameter of the\nfastcgi_cache_path directive.\n
\nHTTP request header fields are passed to a FastCGI server as parameters.\nIn applications and scripts running as FastCGI servers,\nthese parameters are usually made available as environment variables.\nFor example, the “User-Agent” header field is passed as the\nHTTP_USER_AGENT parameter.\nIn addition to HTTP request header fields, it is possible to pass arbitrary\nparameters using the fastcgi_param directive.\n
\nThe ngx_http_fastcgi_module module supports embedded\nvariables that can be used to set parameters using the\nfastcgi_param directive:\n
$fastcgi_script_name\nSCRIPT_FILENAME and PATH_TRANSLATED\nparameters that determine the script name in PHP.\nFor example, for the “/info/” request with the\nfollowing directives\n\nthe\nfastcgi_index index.php;\nfastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;\n
SCRIPT_FILENAME parameter will be equal to\n“/home/www/scripts/php/info/index.php”.\n\n\nWhen using the fastcgi_split_path_info directive,\nthe $fastcgi_script_name variable equals the value of\nthe first capture set by the directive.\n
$fastcgi_path_infoPATH_INFO parameter.\n\n
\n\n| Example Configuration Directives flv |
\nThe ngx_http_flv_module module provides pseudo-streaming\nserver-side support for Flash Video (FLV) files.\n
\nIt handles requests with the start argument in\nthe request URI’s query string specially, by sending back the contents\nof a file starting from the requested byte offset and with the prepended FLV\nheader.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_flv_module\nconfiguration parameter.\n
\n
\nlocation ~ \\.flv$ {\n flv;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n flv;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nTurns on module processing in a surrounding location.\n
\n\n| Example Configuration Directives geoip_country geoip_city geoip_org geoip_proxy geoip_proxy_recursive |
\nThe ngx_http_geoip_module module (0.8.6+) creates variables\nwith values depending on the client IP address, using the precompiled\nMaxMind databases.\n
\nWhen using the databases with IPv6 support (1.3.12, 1.2.7),\nIPv4 addresses are looked up as IPv4-mapped IPv6 addresses.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_geoip_module\nconfiguration parameter.\n
\nThis module requires the\nMaxMind GeoIP library.\n
\n
\n\n\n\n
\nhttp {\n geoip_country GeoIP.dat;\n geoip_city GeoLiteCity.dat;\n geoip_proxy 192.168.100.0/24;\n geoip_proxy 2001:0db8::/32;\n geoip_proxy_recursive on;\n ...\n\n
\n\n\n| \n Syntax:\n | \n\n geoip_country \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nSpecifies a database used to determine the country\ndepending on the client IP address.\nThe following variables are available when using this database:\n
$geoip_country_codeRU”, “US”.\n$geoip_country_code3\nRUS”, “USA”.\n$geoip_country_nameRussian Federation”, “United States”.\n\n
| \n Syntax:\n | \n\n geoip_city \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nSpecifies a database used to determine the country, region, and city\ndepending on the client IP address.\nThe following variables are available when using this database:\n
$geoip_area_code\nThis variable may contain outdated information since\nthe corresponding database field is deprecated.\n\n
$geoip_city_continent_codeEU”, “NA”.\n$geoip_city_country_code\nRU”, “US”.\n$geoip_city_country_code3\nRUS”, “USA”.\n$geoip_city_country_name\nRussian Federation”, “United States”.\n$geoip_dma_code$geoip_latitude$geoip_longitude$geoip_region48”, “DC”.\n$geoip_region_nameMoscow City”, “District of Columbia”.\n$geoip_cityMoscow”, “Washington”.\n$geoip_postal_code\n
| \n Syntax:\n | \n\n geoip_org \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
This directive appeared in version 1.0.3.\n
\nSpecifies a database used to determine the organization\ndepending on the client IP address.\nThe following variable is available when using this database:\n
$geoip_org\n
| \n Syntax:\n | \n\n geoip_proxy \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\n This directive appeared in versions 1.3.0 and 1.2.1.\n \n
\n\nDefines trusted addresses.\nWhen a request comes from a trusted address,\nan address from the “X-Forwarded-For” request\nheader field will be used instead.\n
| \n Syntax:\n | \n\n geoip_proxy_recursive \n | \n
|---|---|
| \n Default:\n | \n\n geoip_proxy_recursive off;\n | \n
| \n Context:\n | \n\n http\n | \n
\n This directive appeared in versions 1.3.0 and 1.2.1.\n \n
\n\nIf recursive search is disabled then instead of the original client\naddress that matches one of the trusted addresses, the last\naddress sent in “X-Forwarded-For” will be used.\nIf recursive search is enabled then instead of the original client\naddress that matches one of the trusted addresses, the last\nnon-trusted address sent in “X-Forwarded-For” will be used.\n
\n\n| Example Configuration Directives geo |
\nThe ngx_http_geo_module module creates variables\nwith values depending on the client IP address.\n
\n
\ngeo $geo {\n default 0;\n\n 127.0.0.1 2;\n 192.168.1.0/24 1;\n 10.1.0.0/16 1;\n\n ::1 2;\n 2001:0db8::/32 1;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n geo [\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nDescribes the dependency of values of the specified variable\non the client IP address.\nBy default, the address is taken from the $remote_addr variable,\nbut it can also be taken from another variable (0.7.27), for example:\n
\ngeo $arg_remote_addr $geo {\n ...;\n}\n\n
\n
\nSince variables are evaluated only when used, the mere existence\nof even a large number of declared “geo” variables\ndoes not cause any extra costs for request processing.\n\n
\nIf the value of a variable does not represent a valid IP address\nthen the “255.255.255.255” address is used.\n
\nAddresses are specified either as prefixes in CIDR notation\n(including individual addresses) or as ranges (0.7.23).\n
\nIPv6 prefixes are supported starting from versions 1.3.10 and 1.2.7.\n
\n
\nThe following special parameters are also supported:\n
deletedefault0.0.0.0/0” and “::/0”\ncan be used instead of default.\nWhen default is not specified, the default\nvalue will be an empty string.\nincludeproxy\nTrusted IPv6 addresses are supported starting from versions 1.3.0 and 1.2.1.\n\n
proxy_recursiverangesvolatile\n
\nExample:\n
\ngeo $country {\n default ZZ;\n include conf/geo.conf;\n delete 127.0.0.0/16;\n proxy 192.168.100.0/24;\n proxy 2001:0db8::/32;\n\n 127.0.0.0/24 US;\n 127.0.0.1/32 RU;\n 10.1.0.0/16 RU;\n 192.168.1.0/24 UK;\n}\n\n
\nThe conf/geo.conf file could contain the following lines:\n
\n10.2.0.0/16 RU;\n192.168.2.0/24 RU;\n
\n
\nA value of the most specific match is used.\nFor example, for the 127.0.0.1 address the value “RU”\nwill be chosen, not “US”.\n
\nExample with ranges:\n
\ngeo $country {\n ranges;\n default ZZ;\n 127.0.0.0-127.0.0.0 US;\n 127.0.0.1-127.0.0.1 RU;\n 127.0.0.1-127.0.0.255 US;\n 10.1.0.0-10.1.255.255 RU;\n 192.168.1.0-192.168.1.255 UK;\n}\n\n
\n\n\nThe ngx_http_grpc_module module allows passing requests\nto a gRPC server (1.13.10).\nThe module requires the\nngx_http_v2_module module.\n
\n
\nserver {\n listen 9000;\n\n http2 on;\n\n location / {\n grpc_pass 127.0.0.1:9000;\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n grpc_allow_upstream \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nDefines conditions under which access to a gRPC server\nis allowed or denied.\nIf all string parameters are not empty\nand not equal to “0” then the access is allowed.\nThe conditions are evaluated each time\nbefore a connection to a gRPC server is established.\nParameter values can contain variables:\n
\ngeo $upstream_last_addr $allow {\n volatile;\n 10.10.0.0/24 1;\n}\n\nserver {\n listen 127.0.0.1:8080;\n http2 on;\n\n location / {\n grpc_pass localhost:9000;\n grpc_allow_upstream $allow;\n ...\n }\n}\n\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n grpc_bind \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nMakes outgoing connections to a gRPC server originate\nfrom the specified local IP address with an optional port.\nParameter value can contain variables.\nThe special value off cancels the effect\nof the grpc_bind directive\ninherited from the previous configuration level, which allows the\nsystem to auto-assign the local IP address and port.\n
\nThe transparent parameter allows\noutgoing connections to a gRPC server originate\nfrom a non-local IP address,\nfor example, from a real IP address of a client:\n
\ngrpc_bind $remote_addr transparent;\n
\nIn order for this parameter to work,\nit is usually necessary to run nginx worker processes with the\nsuperuser privileges.\nOn Linux it is not required as if\nthe transparent parameter is specified, worker processes\ninherit the CAP_NET_RAW capability from the master process.\nIt is also necessary to configure kernel routing table\nto intercept network traffic from the gRPC server.\n
| \n Syntax:\n | \n\n grpc_bind_dynamic \n | \n
|---|---|
| \n Default:\n | \n\n grpc_bind_dynamic off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nWhen enabled, makes the bind operation\nat each connection attempt.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n grpc_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n grpc_buffer_size 4k|8k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the size of the buffer used for reading the response\nreceived from the gRPC server.\nThe first part of the response usually contains a small header;\nif it exceeds the buffer size, the response is considered\ninvalid.\nThe response is passed to the client synchronously, as soon as it is received.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\nIt can be made smaller, however.\n
| \n Syntax:\n | \n\n grpc_connect_timeout \n | \n
|---|---|
| \n Default:\n | \n\n grpc_connect_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a timeout for establishing a connection with a gRPC server.\nIt should be noted that this timeout cannot usually exceed 75 seconds.\n
| \n Syntax:\n | \n\n grpc_hide_header \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nBy default,\nnginx does not pass the header fields “Date”,\n“Server”, and\n“X-Accel-...” from the response of a gRPC\nserver to a client.\nThe grpc_hide_header directive sets additional fields\nthat will not be passed.\nIf, on the contrary, the passing of fields needs to be permitted,\nthe grpc_pass_header directive can be used.\n
| \n Syntax:\n | \n\n grpc_ignore_headers \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDisables processing of certain response header fields from the gRPC server.\nThe following fields can be ignored: “X-Accel-Redirect”\nand “X-Accel-Charset”.\n
\nIf not disabled, processing of these header fields has the following\neffect:\n
\n
| \n Syntax:\n | \n\n grpc_intercept_errors \n | \n
|---|---|
| \n Default:\n | \n\n grpc_intercept_errors off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines whether gRPC server responses with codes greater than or equal\nto 300 should be passed to a client\nor be intercepted and redirected to nginx for processing\nwith the error_page directive.\n
| \n Syntax:\n | \n\n grpc_next_upstream \n \n | \n
|---|---|
| \n Default:\n | \n\n grpc_next_upstream error timeout;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies in which cases a request should be passed to the next server:\n
errortimeoutdenied\n
\nThis parameter is available as part of our\ncommercial subscription.\n
\n
\ninvalid_headerhttp_500http_502http_503http_504http_403http_404http_429non_idempotentPOST, LOCK, PATCH)\nare not passed to the next server\nif a request has been sent to an upstream server;\nenabling this option explicitly allows retrying such requests;\noff\n
\nOne should bear in mind that passing a request to the next server is\nonly possible if nothing has been sent to a client yet.\nThat is, if an error or timeout occurs in the middle of the\ntransferring of a response, fixing this is impossible.\n
\nThe directive also defines what is considered an\nunsuccessful\nattempt of communication with a server.\nThe cases of error, timeout,\ndenied and\ninvalid_header are always considered unsuccessful attempts,\neven if they are not specified in the directive.\nThe cases of http_500, http_502,\nhttp_503, http_504,\nand http_429 are\nconsidered unsuccessful attempts only if they are specified in the directive.\nThe cases of http_403 and http_404\nare never considered unsuccessful attempts.\n
\nPassing a request to the next server can be limited by\nthe number of tries\nand by time.\n
| \n Syntax:\n | \n\n grpc_next_upstream_timeout \n | \n
|---|---|
| \n Default:\n | \n\n grpc_next_upstream_timeout 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nLimits the time during which a request can be passed to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n grpc_next_upstream_tries \n | \n
|---|---|
| \n Default:\n | \n\n grpc_next_upstream_tries 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nLimits the number of possible tries for passing a request to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n grpc_pass \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location, if in location\n | \n
\nSets the gRPC server address.\nThe address can be specified as a domain name or IP address,\nand a port:\n
\ngrpc_pass localhost:9000;\n
\nor as a UNIX-domain socket path:\n
\ngrpc_pass unix:/tmp/grpc.socket;\n
\nAlternatively, the “grpc://” scheme can be used:\n
\ngrpc_pass grpc://127.0.0.1:9000;\n
\nTo use gRPC over SSL, the “grpcs://” scheme should be used:\n
\ngrpc_pass grpcs://127.0.0.1:443;\n
\n
\nIf a domain name resolves to several addresses, all of them will be\nused in a round-robin fashion.\nIn addition, an address can be specified as a\nserver group.\n
\nParameter value can contain variables (1.17.8).\nIn this case, if an address is specified as a domain name,\nthe name is searched among the described\nserver groups,\nand, if not found, is determined using a\nresolver.\n
| \n Syntax:\n | \n\n grpc_pass_header \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nPermits passing otherwise disabled header\nfields from a gRPC server to a client.\n
| \n Syntax:\n | \n\n grpc_read_timeout \n | \n
|---|---|
| \n Default:\n | \n\n grpc_read_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a timeout for reading a response from the gRPC server.\nThe timeout is set only between two successive read operations,\nnot for the transmission of the whole response.\nIf the gRPC server does not transmit anything within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n grpc_request_dynamic \n | \n
|---|---|
| \n Default:\n | \n\n grpc_request_dynamic off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nEnables or disables creation of a separate request instance\nfor each gRPC server.\nBy default, a single request is used for all gRPC servers.\nIf enabled, a separate request instance is created,\nallowing per-server request customization.\nFor example, the server-specific “Host” request header field\ncan be set:\n
\ngrpc_request_dynamic on;\ngrpc_set_header Host $upstream_last_server_name;\n
\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n grpc_send_timeout \n | \n
|---|---|
| \n Default:\n | \n\n grpc_send_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a timeout for transmitting a request to the gRPC server.\nThe timeout is set only between two successive write operations,\nnot for the transmission of the whole request.\nIf the gRPC server does not receive anything within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n grpc_set_header \n | \n
|---|---|
| \n Default:\n | \n\n grpc_set_header Content-Length $content_length;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nAllows redefining or appending fields to the request header\npassed to the gRPC server.\nThe value can contain text, variables, and their combinations.\nThese directives are inherited from the previous configuration level\nif and only if there are no grpc_set_header directives\ndefined on the current level.\n
\nIf the value of a header field is an empty string then this\nfield will not be passed to a gRPC server:\n
\ngrpc_set_header Accept-Encoding \"\";\n
\n
| \n Syntax:\n | \n\n grpc_socket_keepalive \n | \n
|---|---|
| \n Default:\n | \n\n grpc_socket_keepalive off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.15.6.\n
\nConfigures the “TCP keepalive” behavior\nfor outgoing connections to a gRPC server.\nBy default, the operating system’s settings are in effect for the socket.\nIf the directive is set to the value “on”, the\nSO_KEEPALIVE socket option is turned on for the socket.\n
| \n Syntax:\n | \n\n grpc_ssl_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies a file with the certificate in the PEM format\nused for authentication to a gRPC SSL server.\n
\nSince version 1.21.0, variables can be used in the file name.\n
| \n Syntax:\n | \n\n grpc_ssl_certificate_cache grpc_ssl_certificate_cache \n \n | \n
|---|---|
| \n Default:\n | \n\n grpc_ssl_certificate_cache off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.27.4.\n
\nDefines a cache that stores\nSSL certificates and\nsecret keys\nspecified with variables.\n
\nThe directive has the following parameters:\n
max\ninactive\nvalid\noff\n\n
\nExample:\n
\ngrpc_ssl_certificate $grpc_ssl_server_name.crt;\ngrpc_ssl_certificate_key $grpc_ssl_server_name.key;\ngrpc_ssl_certificate_cache max=1000 inactive=20s valid=1m;\n
\n
| \n Syntax:\n | \n\n grpc_ssl_certificate_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies a file with the secret key in the PEM format\nused for authentication to a gRPC SSL server.\n
\nThe value\nengine:name:id\ncan be specified instead of the file,\nwhich loads a secret key with a specified id\nfrom the OpenSSL engine name.\n
\nThe value\nstore:scheme:id\ncan be specified instead of the file (1.29.0),\nwhich is used to load a secret key with a specified id\nand OpenSSL provider registered URI scheme, such as\npkcs11.\n
\nSince version 1.21.0, variables can be used in the file name.\n
| \n Syntax:\n | \n\n grpc_ssl_ciphers \n | \n
|---|---|
| \n Default:\n | \n\n grpc_ssl_ciphers DEFAULT;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies the enabled ciphers for requests to a gRPC SSL server.\nThe ciphers are specified in the format understood by the OpenSSL library.\n
\nThe full list can be viewed using the\n“openssl ciphers” command.\n
| \n Syntax:\n | \n\n grpc_ssl_conf_command \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.19.4.\n
\nSets arbitrary OpenSSL configuration\ncommands\nwhen establishing a connection with the gRPC SSL server.\n
\nThe directive is supported when using OpenSSL 1.0.2 or higher.\n
\n
\nSeveral grpc_ssl_conf_command directives\ncan be specified on the same level.\nThese directives are inherited from the previous configuration level\nif and only if there are\nno grpc_ssl_conf_command directives\ndefined on the current level.\n
\n
\nNote that configuring OpenSSL directly\nmight result in unexpected behavior.\n
\n
| \n Syntax:\n | \n\n grpc_ssl_crl \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies a file with revoked certificates (CRL)\nin the PEM format used to verify\nthe certificate of the gRPC SSL server.\nWhen using intermediate certificates, their CRLs should be\nspecified in the same file.\n
| \n Syntax:\n | \n\n grpc_ssl_key_log path;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.27.2.\n
\nEnables logging of gRPC SSL server connection SSL keys\nand specifies the path to the key log file.\nKeys are logged in the\nSSLKEYLOGFILE\nformat compatible with Wireshark.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n grpc_ssl_name \n | \n
|---|---|
| \n Default:\n | \n\n grpc_ssl_name host from grpc_pass;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nAllows overriding the server name used to\nverify\nthe certificate of the gRPC SSL server and to be\npassed through SNI\nwhen establishing a connection with the gRPC SSL server.\n
\nBy default, the host part from grpc_pass is used.\n
| \n Syntax:\n | \n\n grpc_ssl_password_file \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies a file with passphrases for\nsecret keys\nwhere each passphrase is specified on a separate line.\nPassphrases are tried in turn when loading the key.\n
| \n Syntax:\n | \n\n grpc_ssl_protocols \n [\n | \n
|---|---|
| \n Default:\n | \n\n grpc_ssl_protocols TLSv1.2 TLSv1.3;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables the specified protocols for requests to a gRPC SSL server.\n
\n
\nThe TLSv1.3 parameter is used by default\nsince 1.23.4.\n\n
| \n Syntax:\n | \n\n grpc_ssl_server_name \n | \n
|---|---|
| \n Default:\n | \n\n grpc_ssl_server_name off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables passing of the server name through\nTLS\nServer Name Indication extension (SNI, RFC 6066)\nwhen establishing a connection with the gRPC SSL server.\n
| \n Syntax:\n | \n\n grpc_ssl_session_reuse \n | \n
|---|---|
| \n Default:\n | \n\n grpc_ssl_session_reuse on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines whether SSL sessions can be reused when working with\nthe gRPC server.\nIf the errors\n“digest check failed”\nappear in the logs, try disabling session reuse.\n
| \n Syntax:\n | \n\n grpc_ssl_trusted_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to verify\nthe certificate of the gRPC SSL server.\n
| \n Syntax:\n | \n\n grpc_ssl_verify \n | \n
|---|---|
| \n Default:\n | \n\n grpc_ssl_verify off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables verification of the gRPC SSL server certificate.\n
| \n Syntax:\n | \n\n grpc_ssl_verify_depth \n | \n
|---|---|
| \n Default:\n | \n\n grpc_ssl_verify_depth 1;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the verification depth in the gRPC SSL server certificates chain.\n
\n\n| Example Configuration Directives gunzip gunzip_buffers |
\nThe ngx_http_gunzip_module module is a filter that\ndecompresses responses with “Content-Encoding: gzip”\nfor clients that do not support “gzip” encoding method.\nThe module will be useful when it is desirable to store\ndata compressed to save space and reduce I/O costs.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_gunzip_module\nconfiguration parameter.\n
\n
\nlocation /storage/ {\n gunzip on;\n ...\n}\n\n
\n\n\n| \n Syntax:\n | \n\n gunzip \n | \n
|---|---|
| \n Default:\n | \n\n gunzip off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables decompression of gzipped responses\nfor clients that lack gzip support.\nIf enabled, the following directives are also taken into account\nwhen determining if clients support gzip:\ngzip_http_version,\ngzip_proxied, and\ngzip_disable.\nSee also the gzip_vary directive.\n
| \n Syntax:\n | \n\n gunzip_buffers \n | \n
|---|---|
| \n Default:\n | \n\n gunzip_buffers 32 4k|16 8k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the number and size of buffers\nused to decompress a response.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\n
| Example Configuration Directives gzip gzip_buffers gzip_comp_level gzip_disable gzip_http_version gzip_min_length gzip_proxied gzip_types gzip_vary Embedded Variables |
\nThe ngx_http_gzip_module module is a filter\nthat compresses responses using the “gzip” method.\nThis often helps to reduce the size of transmitted data by half or even more.\n
\nWhen using the SSL/TLS protocol, compressed responses may be subject to\nBREACH attacks.\n
\n
\n\n\n\n
\ngzip on;\ngzip_min_length 1000;\ngzip_proxied expired no-cache no-store private auth;\ngzip_types text/plain application/xml;\n
\n
\nThe $gzip_ratio variable can be used to log the\nachieved compression ratio.\n
| \n Syntax:\n | \n\n gzip \n | \n
|---|---|
| \n Default:\n | \n\n gzip off;\n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
\nEnables or disables gzipping of responses.\n
| \n Syntax:\n | \n\n gzip_buffers \n | \n
|---|---|
| \n Default:\n | \n\n gzip_buffers 32 4k|16 8k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the number and size of buffers\nused to compress a response.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\n
\nUntil version 0.7.28, four 4K or 8K buffers were used by default.\n
\n
| \n Syntax:\n | \n\n gzip_comp_level \n | \n
|---|---|
| \n Default:\n | \n\n gzip_comp_level 1;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a gzip compression level of a response.\nAcceptable values are in the range from 1 to 9.\n
| \n Syntax:\n | \n\n gzip_disable \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.6.23.\n
\nDisables gzipping of responses for requests with\n“User-Agent” header fields matching\nany of the specified regular expressions.\n
\nThe special mask “msie6” (0.7.12) corresponds to\nthe regular expression “MSIE [4-6]\\.”, but works faster.\nStarting from version 0.8.11, “MSIE 6.0; ... SV1”\nis excluded from this mask.\n
| \n Syntax:\n | \n\n gzip_http_version \n | \n
|---|---|
| \n Default:\n | \n\n gzip_http_version 1.1;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the minimum HTTP version of a request required to compress a response.\n
| \n Syntax:\n | \n\n gzip_min_length \n | \n
|---|---|
| \n Default:\n | \n\n gzip_min_length 20;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the minimum length of a response that will be gzipped.\nThe length is determined only from the “Content-Length”\nresponse header field.\n
| \n Syntax:\n | \n\n gzip_proxied \n \n | \n
|---|---|
| \n Default:\n | \n\n gzip_proxied off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables gzipping of responses for proxied\nrequests depending on the request and response.\nThe fact that the request is proxied is determined by\nthe presence of the “Via” request header field.\nThe directive accepts multiple parameters:\n
offexpiredno-cacheno-cache” parameter;\nno-storeno-store” parameter;\nprivateprivate” parameter;\nno_last_modifiedno_etagauthany\n
| \n Syntax:\n | \n\n gzip_types \n | \n
|---|---|
| \n Default:\n | \n\n gzip_types text/html;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables gzipping of responses for the specified MIME types in addition\nto “text/html”.\nThe special value “*” matches any MIME type (0.8.29).\nResponses with the “text/html” type are always compressed.\n
| \n Syntax:\n | \n\n gzip_vary \n | \n
|---|---|
| \n Default:\n | \n\n gzip_vary off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables inserting the “Vary: Accept-Encoding”\nresponse header field if the directives\ngzip,\ngzip_static, or\ngunzip\nare active.\n
\n\n\n\n
$gzip_ratio\n
\n\n| Example Configuration Directives gzip_static |
\nThe ngx_http_gzip_static_module module allows\nsending precompressed files with the “.gz”\nfilename extension instead of regular files.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_gzip_static_module\nconfiguration parameter.\n
\n
\ngzip_static on;\ngzip_proxied expired no-cache no-store private auth;\n
\n
\n\n\n| \n Syntax:\n | \n\n gzip_static \n \n | \n
|---|---|
| \n Default:\n | \n\n gzip_static off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables (“on”) or disables (“off”)\nchecking the existence of precompressed files.\nThe following directives are also taken into account:\ngzip_http_version,\ngzip_proxied,\ngzip_disable,\nand gzip_vary.\n
\nWith the “always” value (1.3.6), gzipped file is used\nin all cases, without checking if the client supports it.\nIt is useful if there are no uncompressed files on the disk anyway\nor the ngx_http_gunzip_module\nis used.\n
\nThe files can be compressed using the gzip command,\nor any other compatible one.\nIt is recommended that the modification date and time of original and\ncompressed files be the same.\n
| Example Configuration Directives add_header add_header_inherit add_trailer add_trailer_inherit expires |
\nThe ngx_http_headers_module module allows adding\nthe “Expires” and “Cache-Control” header\nfields, and arbitrary fields, to a response header.\n
\n
\nexpires 24h;\nexpires modified +24h;\nexpires @24h;\nexpires 0;\nexpires -1;\nexpires epoch;\nexpires $expires;\nadd_header Cache-Control private;\n
\n
\n\n\n| \n Syntax:\n | \n\n add_header \n\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
\nAdds the specified field to a response header provided that\nthe response code equals 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304,\n307 (1.1.16, 1.0.13), or 308 (1.13.0).\nParameter value can contain variables.\n
\nThere could be several add_header directives.\nThese directives are inherited from the previous configuration level\nif and only if there are no add_header directives\ndefined on the current level.\nInheritance rules can be redefined with the\nadd_header_inherit directive (1.29.3).\n
\nIf the always parameter is specified (1.7.5),\nthe header field will be added regardless of the response code.\n
| \n Syntax:\n | \n\n add_header_inherit \n \n | \n
|---|---|
| \n Default:\n | \n\n add_header_inherit on;\n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
This directive appeared in version 1.29.3.\n
\nAllows altering inheritance rules for the values specified in the\nadd_header directives.\nBy default, the\nstandard inheritance model is used.\n
\nThe merge parameter enables appending values\nfrom the previous level to the values defined at the current level.\n
\nThe off parameter cancels inheritance of the values\nfrom the previous configuration level.\n
\nThe inheritance rules themselves are inherited in a standard way.\nFor example, add_header_inherit merge;\nspecified at the top level will\nbe inherited in all nested levels recursively unless redefined later.\n
| \n Syntax:\n | \n\n add_trailer \n\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
This directive appeared in version 1.13.2.\n
\nAdds the specified field to the end of a response provided that\nthe response code equals 200, 201, 206, 301, 302, 303, 307, or 308.\nParameter value can contain variables.\n
\nThere could be several add_trailer directives.\nThese directives are inherited from the previous configuration level\nif and only if there are no add_trailer directives\ndefined on the current level.\nInheritance rules can be redefined with the\nadd_trailer_inherit directive (1.29.3).\n
\nIf the always parameter is specified\nthe specified field will be added regardless of the response code.\n
| \n Syntax:\n | \n\n add_trailer_inherit \n \n | \n
|---|---|
| \n Default:\n | \n\n add_trailer_inherit on;\n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
This directive appeared in version 1.29.3.\n
\nAllows altering inheritance rules for the values specified in the\nadd_trailer directives.\nBy default, the\nstandard inheritance model is used.\n
\nThe merge parameter enables appending values\nfrom the previous level to the values defined at the current level.\n
\nThe off parameter cancels inheritance of the values\nfrom the previous configuration level.\n
\nThe inheritance rules themselves are inherited in a standard way.\nFor example, add_trailer_inherit merge;\nspecified at the top level will\nbe inherited in all nested levels recursively unless redefined later.\n
| \n Syntax:\n | \n\n expires [expires \n \n | \n
|---|---|
| \n Default:\n | \n\n expires off;\n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
\nEnables or disables adding or modifying the “Expires”\nand “Cache-Control” response header fields provided that\nthe response code equals 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304,\n307 (1.1.16, 1.0.13), or 308 (1.13.0).\nThe parameter can be a positive or negative\ntime.\n
\nThe time in the “Expires” field is computed as a sum of the\ncurrent time and time specified in the directive.\nIf the modified parameter is used (0.7.0, 0.6.32)\nthen the time is computed as a sum of the file’s modification time and\nthe time specified in the directive.\n
\nIn addition, it is possible to specify a time of day using\nthe “@” prefix (0.7.9, 0.6.34):\n
\nexpires @15h30m;\n
\n
\nThe contents of the “Cache-Control” field depends\non the sign of the specified time:\n
t”,\nwhere t is a time specified in the directive, in seconds.\n\n
\nThe epoch parameter sets “Expires”\nto the value “Thu, 01 Jan 1970 00:00:01 GMT”,\nand “Cache-Control” to “no-cache”.\n
\nThe max parameter sets “Expires”\nto the value “Thu, 31 Dec 2037 23:55:55 GMT”,\nand “Cache-Control” to 10 years.\n
\nThe off parameter disables adding or modifying the\n“Expires” and “Cache-Control” response\nheader fields.\n
\nThe last parameter value can contain variables (1.7.9):\n
\nmap $sent_http_content_type $expires {\n default off;\n application/pdf 42d;\n ~image/ max;\n}\n\nexpires $expires;\n\n
\n\n| Example Configuration Directives hls hls_buffers hls_forward_args hls_fragment hls_mp4_buffer_size hls_mp4_max_buffer_size |
\nThe ngx_http_hls_module module provides HTTP Live Streaming\n(HLS) server-side support for MP4 and MOV media files.\nSuch files typically have the .mp4, .m4v,\n.m4a, .mov, or .qt filename extensions.\nThe module supports H.264 video codec, AAC and MP3 audio codecs.\n
\nFor each media file, two URIs are supported:\n
.m3u8” filename extension.\nThe URI can accept optional arguments:\nstart” and “end”\ndefine playlist boundaries in seconds (1.9.0).\noffset” shifts an initial playback position\nto the time offset in seconds (1.9.0).\nA positive value sets a time offset from the beginning of the playlist.\nA negative value sets a time offset\nfrom the end of the last fragment in the playlist.\nlen” defines the fragment length in seconds.\n.ts” filename extension.\nThe URI can accept optional arguments:\nstart” and “end”\ndefine fragment boundaries in seconds.\n\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nlocation / {\n hls;\n hls_fragment 5s;\n hls_buffers 10 10m;\n hls_mp4_buffer_size 1m;\n hls_mp4_max_buffer_size 5m;\n root /var/video/;\n}\n \nWith this configuration, the following URIs are supported for\nthe “/var/video/test.mp4” file:\n
\nhttp://hls.example.com/test.mp4.m3u8?offset=1.000&start=1.000&end=2.200\nhttp://hls.example.com/test.mp4.m3u8?len=8.000\nhttp://hls.example.com/test.mp4.ts?start=1.000&end=2.200\n
\n
\n\n\n| \n Syntax:\n | \n\n hls;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nTurns on HLS streaming in the surrounding location.\n
| \n Syntax:\n | \n\n hls_buffers \n | \n
|---|---|
| \n Default:\n | \n\n hls_buffers 8 2m;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the maximum number and size of buffers\nthat are used for reading and writing data frames.\n
| \n Syntax:\n | \n\n hls_forward_args \n | \n
|---|---|
| \n Default:\n | \n\n hls_forward_args off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.12.\n
\nAdds arguments from a playlist request to URIs of fragments.\nThis may be useful for performing client authorization at the moment of\nrequesting a fragment, or when protecting an HLS stream with the\nngx_http_secure_link_module\nmodule.\n
\nFor example, if a client requests a playlist\nhttp://example.com/hls/test.mp4.m3u8?a=1&b=2,\nthe arguments a=1 and b=2\nwill be added to URIs of fragments after the arguments\nstart and end:\n
\n#EXTM3U\n#EXT-X-VERSION:3\n#EXT-X-TARGETDURATION:15\n#EXT-X-PLAYLIST-TYPE:VOD\n\n#EXTINF:9.333,\ntest.mp4.ts?start=0.000&end=9.333&a=1&b=2\n#EXTINF:7.167,\ntest.mp4.ts?start=9.333&end=16.500&a=1&b=2\n#EXTINF:5.416,\ntest.mp4.ts?start=16.500&end=21.916&a=1&b=2\n#EXTINF:5.500,\ntest.mp4.ts?start=21.916&end=27.416&a=1&b=2\n#EXTINF:15.167,\ntest.mp4.ts?start=27.416&end=42.583&a=1&b=2\n#EXTINF:9.626,\ntest.mp4.ts?start=42.583&end=52.209&a=1&b=2\n\n#EXT-X-ENDLIST\n
\n
\nIf an HLS stream is protected with the\nngx_http_secure_link_module\nmodule, $uri should not be used in the\nsecure_link_md5\nexpression because this will cause errors when requesting the fragments.\nBase URI should be used\ninstead of $uri\n($hls_uri in the example):\n
\nhttp {\n ...\n\n map $uri $hls_uri {\n ~^(?<base_uri>.*).m3u8$ $base_uri;\n ~^(?<base_uri>.*).ts$ $base_uri;\n default $uri;\n }\n\n server {\n ...\n\n location /hls/ {\n hls;\n hls_forward_args on;\n\n alias /var/videos/;\n\n secure_link $arg_md5,$arg_expires;\n secure_link_md5 \"$secure_link_expires$hls_uri$remote_addr secret\";\n\n if ($secure_link = \"\") {\n return 403;\n }\n\n if ($secure_link = \"0\") {\n return 410;\n }\n }\n }\n}\n\n
| \n Syntax:\n | \n\n hls_fragment \n | \n
|---|---|
| \n Default:\n | \n\n hls_fragment 5s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines the default fragment length for playlist URIs requested without the\n“len” argument.\n
| \n Syntax:\n | \n\n hls_mp4_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n hls_mp4_buffer_size 512k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the initial size of the buffer used for\nprocessing MP4 and MOV files.\n
| \n Syntax:\n | \n\n hls_mp4_max_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n hls_mp4_max_buffer_size 10m;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDuring metadata processing, a larger buffer may become necessary.\nIts size cannot exceed the specified size,\nor else nginx will return the server error\n500 (Internal Server Error),\nand log the following message:\n
\n\"/some/movie/file.mp4\" mp4 moov atom is too large:\n12583268, you may want to increase hls_mp4_max_buffer_size\n
\n
\n\n| Example Configuration Directives image_filter image_filter_buffer image_filter_interlace image_filter_jpeg_quality image_filter_sharpen image_filter_transparency image_filter_webp_quality |
\nThe ngx_http_image_filter_module module (0.7.54+) is a filter\nthat transforms images in JPEG, GIF, PNG, and WebP formats.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_image_filter_module\nconfiguration parameter.\n
\nThis module utilizes the\nlibgd library.\nIt is recommended to use the latest available version of the library.\n
\n
\nThe WebP format support appeared in version 1.11.6.\nTo transform images in this format,\nthe libgd library must be compiled with the WebP support.\n\n
\n\n\n\n
\nlocation /img/ {\n proxy_pass http://backend;\n image_filter resize 150 100;\n image_filter rotate 90;\n error_page 415 = /empty;\n}\n\nlocation = /empty {\n empty_gif;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n image_filter image_filter image_filter image_filter \n image_filter \n image_filter \n \n | \n
|---|---|
| \n Default:\n | \n\n image_filter off;\n | \n
| \n Context:\n | \n\n location\n | \n
\nSets the type of transformation to perform on images:\n
offtestsize\n{ \"img\" : { \"width\": 100, \"height\": 100, \"type\": \"gif\" } }\n\nIn case of an error, the output is as follows:\n\n{}\n\nrotate\n90|180|270\nresize and crop transformations.\nresize\nwidth\nheight\n-”.\nIn case of an error, the server will return code\n415 (Unsupported Media Type).\nParameter values can contain variables.\nWhen used along with the rotate parameter,\nthe rotation happens after reduction.\ncrop\nwidth\nheight\n-”.\nIn case of an error, the server will return code\n415 (Unsupported Media Type).\nParameter values can contain variables.\nWhen used along with the rotate parameter,\nthe rotation happens before reduction.\n\n
| \n Syntax:\n | \n\n image_filter_buffer \n | \n
|---|---|
| \n Default:\n | \n\n image_filter_buffer 1M;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the maximum size of the buffer used for reading images.\nWhen the size is exceeded the server returns error\n415 (Unsupported Media Type).\n
| \n Syntax:\n | \n\n image_filter_interlace \n | \n
|---|---|
| \n Default:\n | \n\n image_filter_interlace off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.3.15.\n
\nIf enabled, final images will be interlaced.\nFor JPEG, final images will be in “progressive JPEG” format.\n
| \n Syntax:\n | \n\n image_filter_jpeg_quality \n | \n
|---|---|
| \n Default:\n | \n\n image_filter_jpeg_quality 75;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the desired quality of the transformed JPEG images.\nAcceptable values are in the range from 1 to 100.\nLesser values usually imply both lower image quality and less data to transfer.\nThe maximum recommended value is 95.\nParameter value can contain variables.\n
| \n Syntax:\n | \n\n image_filter_sharpen \n | \n
|---|---|
| \n Default:\n | \n\n image_filter_sharpen 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIncreases sharpness of the final image.\nThe sharpness percentage can exceed 100.\nThe zero value disables sharpening.\nParameter value can contain variables.\n
| \n Syntax:\n | \n\n image_filter_transparency \n | \n
|---|---|
| \n Default:\n | \n\n image_filter_transparency on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines whether transparency should be preserved when transforming\nGIF images or PNG images with colors specified by a palette.\nThe loss of transparency results in images of a better quality.\nThe alpha channel transparency in PNG is always preserved.\n
| \n Syntax:\n | \n\n image_filter_webp_quality \n | \n
|---|---|
| \n Default:\n | \n\n image_filter_webp_quality 80;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.11.6.\n
\nSets the desired quality of the transformed WebP images.\nAcceptable values are in the range from 1 to 100.\nLesser values usually imply both lower image quality and less data to transfer.\nParameter value can contain variables.\n
| Example Configuration Directives index |
\nThe ngx_http_index_module module processes requests\nending with the slash character (‘/’).\nSuch requests can also be processed by the\nngx_http_autoindex_module\nand\nngx_http_random_index_module\nmodules.\n
\n
\nlocation / {\n index index.$geo.html index.html;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n index \n | \n
|---|---|
| \n Default:\n | \n\n index index.html;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines files that will be used as an index.\nThe file name can contain variables.\nFiles are checked in the specified order.\nThe last element of the list can be a file with an absolute path.\nExample:\n
\nindex index.$geo.html index.0.html /index.html;\n
\n
\nIt should be noted that using an index file causes an internal redirect,\nand the request can be processed in a different location.\nFor example, with the following configuration:\n
\nlocation = / {\n index index.html;\n}\n\nlocation / {\n ...\n}\n \na “/” request will actually be processed in the\nsecond location as “/index.html”.\n
| Example Configuration Directives internal_redirect |
\nThe ngx_http_internal_redirect_module module (1.23.4) allows\nmaking an internal redirect.\nIn contrast to\nrewriting URIs,\nthe redirection is made after checking\nrequest and\nconnection processing limits,\nand access limits.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nlimit_req_zone $jwt_claim_sub zone=jwt_sub:10m rate=1r/s;\n\nserver {\n location / {\n auth_jwt \"realm\";\n auth_jwt_key_file key.jwk;\n\n internal_redirect @rate_limited;\n }\n\n location @rate_limited {\n internal;\n\n limit_req zone=jwt_sub burst=10;\n proxy_pass http://backend;\n }\n}\n\nThe example implements\nper-user\nrate limiting.\nImplementation without internal_redirect\nis vulnerable to DoS attacks by unsigned JWTs, as normally the\nlimit_req\ncheck is performed\nbefore\nauth_jwt check.\nUsing internal_redirect\nallows reordering these checks.\n
\n\n\n| \n Syntax:\n | \n\n internal_redirect \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server, location\n | \n
\nSets the URI for internal redirection of the request.\nIt is also possible to use a\nnamed location\ninstead of the URI.\nThe uri value can contain variables.\nIf the uri value is empty,\nthen the redirect will not be made.\n
\nThe ngx_http_js_module module is used to implement\nlocation and variable handlers\nin njs —\na subset of the JavaScript language.\n
\nDownload and install instructions are available\nhere.\n
\n\n\n\nThe example works since\n0.4.0.\n
\nhttp {\n js_import http.js;\n\n js_set $foo http.foo;\n js_set $summary http.summary;\n js_set $hash http.hash;\n\n resolver 10.0.0.1;\n\n server {\n listen 8000;\n\n location / {\n add_header X-Foo $foo;\n js_content http.baz;\n }\n\n location = /summary {\n return 200 $summary;\n }\n\n location = /hello {\n js_content http.hello;\n }\n\n # since 0.7.0\n location = /fetch {\n js_content http.fetch;\n js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;\n }\n\n # since 0.7.0\n location = /crypto {\n add_header Hash $hash;\n return 200;\n }\n }\n}\n\n
\nThe http.js file:\n
\nfunction foo(r) {\n r.log(\"hello from foo() handler\");\n return \"foo\";\n}\n\nfunction summary(r) {\n var a, s, h;\n\n s = \"JS summary\\n\\n\";\n\n s += \"Method: \" + r.method + \"\\n\";\n s += \"HTTP version: \" + r.httpVersion + \"\\n\";\n s += \"Host: \" + r.headersIn.host + \"\\n\";\n s += \"Remote Address: \" + r.remoteAddress + \"\\n\";\n s += \"URI: \" + r.uri + \"\\n\";\n\n s += \"Headers:\\n\";\n for (h in r.headersIn) {\n s += \" header '\" + h + \"' is '\" + r.headersIn[h] + \"'\\n\";\n }\n\n s += \"Args:\\n\";\n for (a in r.args) {\n s += \" arg '\" + a + \"' is '\" + r.args[a] + \"'\\n\";\n }\n\n return s;\n}\n\nfunction baz(r) {\n r.status = 200;\n r.headersOut.foo = 1234;\n r.headersOut['Content-Type'] = \"text/plain; charset=utf-8\";\n r.headersOut['Content-Length'] = 15;\n r.sendHeader();\n r.send(\"nginx\");\n r.send(\"java\");\n r.send(\"script\");\n\n r.finish();\n}\n\nfunction hello(r) {\n r.return(200, \"Hello world!\");\n}\n\n// since 0.7.0\nasync function fetch(r) {\n let results = await Promise.all([ngx.fetch('https://nginx.org/'),\n ngx.fetch('https://nginx.org/en/')]);\n\n r.return(200, JSON.stringify(results, undefined, 4));\n}\n\n// since 0.7.0\nasync function hash(r) {\n let hash = await crypto.subtle.digest('SHA-512', r.headersIn.host);\n r.setReturnValue(Buffer.from(hash).toString('hex'));\n}\n\nexport default {foo, summary, baz, hello, fetch, hash};\n\n
\n\n\n| \n Syntax:\n | \n\n js_body_filter \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location, if in location, limit_except\n | \n
This directive appeared in version 0.5.2.\n
\nSets an njs function as a response body filter.\nThe filter function is called for each data chunk of a response body\nwith the following arguments:\n\n
rdatabuffer_type value,\nby default is a string.\nSince 0.8.5, the\ndata value is implicitly converted to a valid UTF-8 string\nby default.\nFor binary data, the buffer_type value\nshould be set to buffer.\nflagslast\n
\nThe filter function can pass its own modified version\nof the input data chunk to the next body filter by calling\nr.sendBuffer().\nFor example, to transform all the lowercase letters in the response body:\n
\nfunction filter(r, data, flags) {\n r.sendBuffer(data.toLowerCase(), flags);\n}\n\n
\nIf the filter function changes the length of the response body, the\n“Content-Length” response header (if present) should be cleared\nin js_header_filter\nto enforce chunked transfer encoding:\n
\nexample.conf:\n location /foo {\n # proxy_pass http://localhost:8080;\n\n js_header_filter main.clear_content_length;\n js_body_filter main.filter;\n }\n\nexample.js:\n function clear_content_length(r) {\n delete r.headersOut['Content-Length'];\n }\n\n
\nTo stop filtering and pass the data chunks to the client\nwithout calling js_body_filter,\nr.done()\ncan be used.\nFor example, to prepend some data to the response body:\n
\nfunction prepend(r, data, flags) {\n r.sendBuffer(\"XXX\");\n r.sendBuffer(data, flags);\n r.done();\n}\n\n
\n
\nAs the js_body_filter handler\nreturns its result immediately, it supports\nonly synchronous operations.\nThus, asynchronous operations such as\nr.subrequest()\nor\nsetTimeout()\nare not supported.\n\n
\n
\nThe directive can be specified inside the\nif block\nsince 0.7.7.\n
\n
| \n Syntax:\n | \n\n js_access \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location, if in location, limit_except\n | \n
This directive appeared in version 0.9.9.\n
\nSets an njs function as a handler in the\naccess phase.\nAsynchronous operations such as\nr.subrequest(),\nngx.fetch(),\nand setTimeout()\nare supported.\n
\nA handler that returns without calling\nr.return()\nor\nr.decline()\ngrants access.\nTo deny access or send a custom response (for example, a redirect),\nthe handler may call\nr.return().\nTo make the handler express no opinion, deferring the decision to other\naccess checkers under\nsatisfy any,\nthe handler may call\nr.decline().\n
\nFor example:\n
\nexample.conf:\n location /protected/ {\n js_access main.auth;\n proxy_pass http://upstream;\n }\n\nexample.js:\n async function auth(r) {\n let reply = await ngx.fetch('http://authsvc/check', {\n headers: {Authorization: r.headersIn.Authorization}\n });\n\n if (reply.status != 200) {\n r.return(401);\n return;\n }\n }\n\n export default {auth};\n\n
| \n Syntax:\n | \n\n js_content \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location, if in location, limit_except\n | \n
\nSets an njs function as a location content handler.\nSince 0.4.0,\na module function can be referenced.\n
\n
\nThe directive can be specified inside the\nif block\nsince 0.7.7.\n
\n
| \n Syntax:\n | \n\n js_context_reuse \n | \n
|---|---|
| \n Default:\n | \n\n js_context_reuse 128;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.8.6.\n
\nSets a maximum number of JS context to be reused for\nQuickJS engine.\nEach context is used for a single request.\nThe finished context is put into a pool of reusable contexts.\nIf the pool is full, the context is destroyed.\n
| \n Syntax:\n | \n\n js_engine \n | \n
|---|---|
| \n Default:\n | \n\n js_engine njs;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.8.6.\n
\nSets a JavaScript engine\nto be used for njs scripts.\nThe njs parameter sets the njs engine, also used by default.\nThe qjs parameter sets the QuickJS engine.\n
| \n Syntax:\n | \n\n js_fetch_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_buffer_size 16k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.4.\n
\nSets the size of the buffer used for reading and writing\nwith Fetch API.\n
| \n Syntax:\n | \n\n js_fetch_ciphers \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_ciphers HIGH:!aNULL:!MD5;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.0.\n
\nSpecifies the enabled ciphers for HTTPS requests\nwith Fetch API.\nThe ciphers are specified in the format understood by the\nOpenSSL library.\n
\nThe full list can be viewed using the\n“openssl ciphers” command.\n
| \n Syntax:\n | \n\n js_fetch_max_response_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_max_response_buffer_size 1m;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.4.\n
\nSets the maximum size of the response received\nwith Fetch API.\n
| \n Syntax:\n | \n\n js_fetch_protocols \n [\n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_protocols TLSv1 TLSv1.1 TLSv1.2;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.0.\n
\nEnables the specified protocols for HTTPS requests\nwith Fetch API.\n
| \n Syntax:\n | \n\n js_fetch_timeout \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.4.\n
\nDefines a timeout for reading and writing\nfor Fetch API.\nThe timeout is set only between two successive read/write operations,\nnot for the whole response.\nIf no data is transmitted within this time, the connection is closed.\n
| \n Syntax:\n | \n\n js_fetch_trusted_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.0.\n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to\nverify\nthe HTTPS certificate\nwith Fetch API.\n
| \n Syntax:\n | \n\n js_fetch_verify \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_verify on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.4.\n
\nEnables or disables verification of the HTTPS server certificate\nwith Fetch API.\n
| \n Syntax:\n | \n\n js_fetch_verify_depth \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_verify_depth 100;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.0.\n
\nSets the verification depth in the HTTPS server certificates chain\nwith Fetch API.\n
| \n Syntax:\n | \n\n js_fetch_proxy \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.9.4.\n
\nConfigures a forward proxy URL\nwith Fetch API.\nThe url supports the HTTP scheme only\nand can contain optional user credentials\nin the format http://[user:password@]host:port\nfor Basic authentication.\nSupports both HTTP and HTTPS connections to destination servers.\nIf the url is empty, proxy routing is disabled.\nThe parameter value can contain variables.\n
\nExample:\n
\nlocation /fetch {\n js_fetch_proxy http://user:pass@proxy.example.com:3128;\n js_content main.fetch_handler;\n}\n\n
| \n Syntax:\n | \n\n js_fetch_keepalive \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_keepalive 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.9.2.\n
\nActivates the cache for connections to destination servers.\nWhen the value is greater than 0,\nenables keepalive connections for\nFetch API.\n
\nThe connections parameter sets the maximum number of idle\nkeepalive connections to destination servers that are preserved in the cache\nof each worker process.\nWhen this number is exceeded, the least recently used connections are closed.\n
\nExample:\n
\nlocation /fetch {\n js_fetch_keepalive 32;\n js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;\n js_content main.fetch_handler;\n}\n\n
| \n Syntax:\n | \n\n js_fetch_keepalive_requests \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_keepalive_requests 1000;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.9.2.\n
\nSets the maximum number of requests that can be served through one keepalive\nconnection with Fetch API.\nAfter the maximum number of requests is made, the connection is closed.\n
\nClosing connections periodically is necessary to free per-connection memory\nallocations.\nTherefore, using too high maximum number of requests could result in\nexcessive memory usage and not recommended.\n
| \n Syntax:\n | \n\n js_fetch_keepalive_time \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_keepalive_time 1h;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.9.2.\n
\nLimits the maximum time during which requests can be processed through one\nkeepalive connection with Fetch API.\nAfter this time is reached, the connection is closed following the subsequent\nrequest processing.\n
| \n Syntax:\n | \n\n js_fetch_keepalive_timeout \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_keepalive_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.9.2.\n
\nSets a timeout during which an idle keepalive connection to a destination server\nwill stay open with Fetch API.\n
| \n Syntax:\n | \n\n js_header_filter \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location, if in location, limit_except\n | \n
This directive appeared in version 0.5.1.\n
\nSets an njs function as a response header filter.\nThe directive allows changing arbitrary header fields of a response header.\n
\n
\nAs the js_header_filter handler\nreturns its result immediately, it supports\nonly synchronous operations.\nThus, asynchronous operations such as\nr.subrequest()\nor\nsetTimeout()\nare not supported.\n\n
\n
\nThe directive can be specified inside the\nif block\nsince 0.7.7.\n
\n
| \n Syntax:\n | \n\n js_import \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.4.0.\n
\nImports a module that implements location and variable handlers in njs.\nThe export_name is used as a namespace\nto access module functions.\nIf the export_name is not specified,\nthe module name will be used as a namespace.\n
\njs_import http.js;\n
\nHere, the module name http is used as a namespace\nwhile accessing exports.\nIf the imported module exports foo(),\nhttp.foo is used to refer to it.\n
\nSeveral js_import directives can be specified.\n
\nWhen js_import is specified inside a\nlocation,\nthe imported modules are visible only if no JavaScript code\nhas been invoked earlier in the request.\nA single VM is created per request when a\njs_set variable is first accessed\nor when a js_content, js_header_filter,\njs_body_filter, or js_access handler\nis first invoked.\nThe VM is cloned from the configuration scope active at that moment,\nand all subsequent JavaScript invocations within the request reuse it.\nThus, if any of the above is referenced before the request is mapped\nto its final location, for example from a server-level\nset,\nthe VM is bound to the import set of the outer scope, and modules\nimported in the matched location will not be visible.\nTo avoid this, declare such imports in a common parent scope.\n
\n
\nThe directive can be specified on the\nserverandlocationlevel\nsince 0.7.7.\n
\n
| \n Syntax:\n | \n\n js_include \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nSpecifies a file that implements location and variable handlers in njs:\n
\nnginx.conf:\njs_include http.js;\nlocation /version {\n js_content version;\n}\n\nhttp.js:\nfunction version(r) {\n r.return(200, njs.version);\n}\n\n
\nThe directive was made obsolete in version\n0.4.0\nand was removed in version\n0.7.1.\nThe js_import directive should be used instead.\n
| \n Syntax:\n | \n\n js_load_http_native_module \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
This directive appeared in version 0.9.5.\n
\nLoads a native module\n(shared library) for use in HTTP JavaScript code.\nThe directive is\nQuickJS-only\nand is not available when using the njs built-in JavaScript engine.\n
\nThe path parameter\nspecifies the absolute path to the shared library file.\nThe optional as name parameter\nprovides an alias name for importing the module in JavaScript code.\nIf not specified, the module can be imported using its filename.\n
\nExample:\n
\njs_load_http_native_module /path/to/mylib.so;\njs_load_http_native_module /path/to/other.so as myalias;\n\nhttp {\n js_import main.js;\n # ... rest of http configuration\n}\n\nIn JavaScript code:\n
\n// Import by filename\nimport * as mylib from 'mylib.so';\n\n// Import by alias\nimport * as myalias from 'myalias';\n\n// Use exported functions\nlet result = mylib.add(5, 10);\n
\n
\n
\nFor security reasons, this directive is only allowed\nin the main configuration context.\nNative modules run with full process privileges;\nuse absolute paths and ensure proper code review.\n\n
| \n Syntax:\n | \n\n js_path \n\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.3.0.\n
\nSets an additional path for njs modules.\n
\n
\nThe directive can be specified on the\nserverandlocationlevel\nsince 0.7.7.\n
\n
| \n Syntax:\n | \n\n js_periodic \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
This directive appeared in version 0.8.1.\n
\nSpecifies a content handler to run at regular interval.\nThe handler receives a\nsession object\nas its first argument,\nit also has access to global objects such as\nngx.\n
\nThe optional interval parameter\nsets the interval between two consecutive runs,\nby default, 5 seconds.\n
\nThe optional jitter parameter sets the time within which\nthe location content handler will be randomly delayed,\nby default, there is no delay.\n
\nBy default, the js_handler is executed on worker process 0.\nThe optional worker_affinity parameter\nallows specifying particular worker processes\nwhere the location content handler should be executed.\nEach worker process set is represented by a bitmask of allowed worker processes.\nThe all mask allows the handler to be executed\nin all worker processes.\n
\nExample:\n
\nexample.conf:\n\nlocation @periodics {\n # to be run at 1 minute intervals in worker process 0\n js_periodic main.handler interval=60s;\n\n # to be run at 1 minute intervals in all worker processes\n js_periodic main.handler interval=60s worker_affinity=all;\n\n # to be run at 1 minute intervals in worker processes 1 and 3\n js_periodic main.handler interval=60s worker_affinity=0101;\n\n resolver 10.0.0.1;\n js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;\n}\n\nexample.js:\n\nasync function handler(s) {\n let reply = await ngx.fetch('https://nginx.org/en/docs/njs/');\n let body = await reply.text();\n\n ngx.log(ngx.INFO, body);\n}\n\n
| \n Syntax:\n | \n\n js_preload_object \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.8.\n
\nPreloads an\nimmutable object\nat configure time.\nThe name is used as a name of the global variable\nthough which the object is available in njs code.\nIf the name is not specified,\nthe file name will be used instead.\n
\njs_preload_object map.json;\n
\nHere, the map is used as a name\nwhile accessing the preloaded object.\n
\nSeveral js_preload_object directives can be specified.\n
| \n Syntax:\n | \n\n js_set \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets an njs function\nfor the specified variable.\nSince 0.4.0,\na module function can be referenced.\n
\nThe function is called when\nthe variable is referenced for the first time for a given request.\nThe exact moment depends on a\nphase\nat which the variable is referenced.\nThis can be used to perform some logic\nnot related to variable evaluation.\nFor example, if the variable is referenced only in the\nlog_format directive,\nits handler will not be executed until the log phase.\nThis handler can be used to do some cleanup\nright before the request is freed.\n
\nSince 0.8.6,\nif an optional argument nocache is specified,\nthe handler is called every time it is referenced.\nDue to current limitations\nof the rewrite module,\nwhen a nocache variable is referenced by the\nset directive\nits handler should always return a fixed-length value.\n
\n
\nAs the js_set handler\nreturns its result immediately, it supports\nonly synchronous operations.\nThus, asynchronous operations such as\nr.subrequest()\nor\nsetTimeout()\nare not supported.\n\n
\n
\nThe directive can be specified on the\nserverandlocationlevel\nsince 0.7.7.\n
\n
| \n Syntax:\n | \n\n js_shared_dict_zone \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
This directive appeared in version 0.8.0.\n
\nSets the name and size of the shared memory zone\nthat keeps the\nkey-value dictionary\nshared between worker processes.\n
\nBy default the shared dictionary uses a string as a key and a value.\nThe optional type parameter\nallows redefining the value type to number.\n
\nThe optional timeout parameter sets\nthe time in milliseconds\nafter which all shared dictionary entries are removed from the zone.\nIf some entries require a different removal time, it can be set\nwith the timeout argument of the\nadd,\nincr, and\nset\nmethods\n(0.8.5).\n
\nThe optional evict parameter removes the oldest\nkey-value pair when the zone storage is exhausted.\n
\nThe optional state parameter specifies a file\nthat keeps the shared dictionary state\nin JSON format and makes it persistent across nginx restarts\n(0.9.1).\n
\nExample:\n
\nexample.conf:\n # Creates a 1Mb dictionary with string values,\n # removes key-value pairs after 60 seconds of inactivity:\n js_shared_dict_zone zone=foo:1M timeout=60s;\n\n # Creates a 512Kb dictionary with string values,\n # forcibly removes oldest key-value pairs when the zone is exhausted:\n js_shared_dict_zone zone=bar:512K timeout=30s evict;\n\n # Creates a 32Kb permanent dictionary with number values:\n js_shared_dict_zone zone=num:32k type=number;\n\n # Creates a 1Mb dictionary with string values and persistent state:\n js_shared_dict_zone zone=persistent:1M state=/tmp/dict.json;\n\nexample.js:\n function get(r) {\n r.return(200, ngx.shared.foo.get(r.args.key));\n }\n\n function set(r) {\n r.return(200, ngx.shared.foo.set(r.args.key, r.args.value));\n }\n\n function del(r) {\n r.return(200, ngx.shared.bar.delete(r.args.key));\n }\n\n function increment(r) {\n r.return(200, ngx.shared.num.incr(r.args.key, 2));\n }\n\n
| \n Syntax:\n | \n\n js_var \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.5.3.\n
\nDeclares\na writable\nvariable.\nThe value can contain text, variables, and their combination.\nThe variable is not overwritten after a redirect\nunlike variables created with the\nset directive.\n
\n
\nThe directive can be specified on the\nserverandlocationlevel\nsince 0.7.7.\n
\n
\n\n\n\nEach HTTP njs handler receives one argument, a request\nobject.\n
\n\n| Example Configuration Directives keyval keyval_zone |
\nThe ngx_http_keyval_module module (1.13.3) creates variables\nwith values taken from key-value pairs managed by the\nAPI\nor a variable (1.15.10) that can also be set with\nnjs.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nhttp {\n\n keyval_zone zone=one:32k state=/var/lib/nginx/state/one.keyval;\n keyval $arg_text $text zone=one;\n ...\n server {\n ...\n location / {\n return 200 $text;\n }\n\n location /api {\n api write=on;\n }\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n keyval \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nCreates a new $variable whose value\nis looked up by the key in the key-value database.\nMatching rules are defined by the\ntype parameter of the\nkeyval_zone directive.\nThe database is stored in a shared memory zone\nspecified by the zone parameter.\n
| \n Syntax:\n | \n\n keyval_zone \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nSets the name and size of the shared memory zone\nthat keeps the key-value database.\nKey-value pairs are managed by the\nAPI.\n
\nThe optional state parameter specifies a file\nthat keeps the current state of the key-value database in the JSON format\nand makes it persistent across nginx restarts.\nChanging the file content directly should be avoided.\n
\nExamples:\n
\nkeyval_zone zone=one:32k state=/var/lib/nginx/state/one.keyval; # path for Linux\nkeyval_zone zone=one:32k state=/var/db/nginx/state/one.keyval; # path for FreeBSD\n
\n
\nThe optional timeout parameter (1.15.0) sets\nthe time after which key-value pairs are removed from the zone.\n
\nThe optional type parameter (1.17.1) activates\nan extra index optimized for matching the key of a certain type\nand defines matching rules when evaluating\na keyval $variable.\n
\nThe index is stored in the same shared memory zone\nand thus requires additional storage.\n
\n\n
type=stringtype=iptype=prefix\n
\nThe optional sync parameter (1.15.0) enables\nsynchronization\nof the shared memory zone.\nThe synchronization requires the\ntimeout parameter to be set.\n
\nIf the synchronization is enabled, removal of key-value pairs (no matter\none\nor\nall)\nwill be performed only on a target cluster node.\nThe same key-value pairs on other cluster nodes\nwill be removed upon timeout.\n\n
\n\n| Example Configuration Directives limit_conn limit_conn_dry_run limit_conn_log_level limit_conn_status limit_conn_zone limit_zone Embedded Variables |
\nThe ngx_http_limit_conn_module module is used to\nlimit the number of connections per the defined key, in\nparticular, the number of connections from a single IP address.\n
\nNot all connections are counted.\nA connection is counted only if it has a request being processed by the server\nand the whole request header has already been read.\n
\n\n\n\n
\nhttp {\n limit_conn_zone $binary_remote_addr zone=addr:10m;\n\n ...\n\n server {\n\n ...\n\n location /download/ {\n limit_conn addr 1;\n }\n\n
\n\n\n| \n Syntax:\n | \n\n limit_conn \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the shared memory zone\nand the maximum allowed number of connections for a given key value.\nWhen this limit is exceeded, the server will return the\nerror\nin reply to a request.\nFor example, the directives\n
\nlimit_conn_zone $binary_remote_addr zone=addr:10m;\n\nserver {\n location /download/ {\n limit_conn addr 1;\n }\n\nallow only one connection per an IP address at a time.\n
\nIn HTTP/2 and HTTP/3,\neach concurrent request is considered a separate connection.\n
\n
\nThere could be several limit_conn directives.\nFor example, the following configuration will limit the number\nof connections to the server per a client IP and, at the same time,\nthe total number of connections to the virtual server:\n
\nlimit_conn_zone $binary_remote_addr zone=perip:10m;\nlimit_conn_zone $server_name zone=perserver:10m;\n\nserver {\n ...\n limit_conn perip 10;\n limit_conn perserver 100;\n}\n\n\n
\nThese directives are inherited from the previous configuration level\nif and only if there are no limit_conn directives\ndefined on the current level.\n
| \n Syntax:\n | \n\n limit_conn_dry_run \n | \n
|---|---|
| \n Default:\n | \n\n limit_conn_dry_run off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.17.6.\n
\nEnables the dry run mode.\nIn this mode, the number of connections is not limited, however,\nin the shared memory zone, the number of excessive connections is accounted\nas usual.\n
| \n Syntax:\n | \n\n limit_conn_log_level \n\n | \n
|---|---|
| \n Default:\n | \n\n limit_conn_log_level error;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.8.18.\n
\nSets the desired logging level for cases when the server\nlimits the number of connections.\n
| \n Syntax:\n | \n\n limit_conn_status \n | \n
|---|---|
| \n Default:\n | \n\n limit_conn_status 503;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.3.15.\n
\nSets the status code to return in response to rejected requests.\n
| \n Syntax:\n | \n\n limit_conn_zone \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nSets parameters for a shared memory zone\nthat will keep states for various keys.\nIn particular, the state includes the current number of connections.\nThe key can contain text, variables, and their combination.\nRequests with an empty key value are not accounted.\n
\nPrior to version 1.7.6, a key could contain exactly one variable.\n\nUsage example:\n
\nlimit_conn_zone $binary_remote_addr zone=addr:10m;\n
\nHere, a client IP address serves as a key.\nNote that instead of $remote_addr, the\n$binary_remote_addr variable is used here.\nThe $remote_addr variable’s size can\nvary from 7 to 15 bytes.\nThe stored state occupies either\n32 or 64 bytes of memory on 32-bit platforms and always 64\nbytes on 64-bit platforms.\nThe $binary_remote_addr variable’s size\nis always 4 bytes for IPv4 addresses or 16 bytes for IPv6 addresses.\nThe stored state always occupies 32 or 64 bytes\non 32-bit platforms and 64 bytes on 64-bit platforms.\nOne megabyte zone can keep about 32 thousand 32-byte states\nor about 16 thousand 64-byte states.\nIf the zone storage is exhausted, the server will return the\nerror\nto all further requests.\n
\n
\nAdditionally, as part of our\ncommercial subscription,\nthe\nstatus information\nfor each such shared memory zone can be\nobtained or\nreset\nwith the API since 1.17.7.\n
\n
| \n Syntax:\n | \n\n limit_zone \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nThis directive was made obsolete in version 1.1.8\nand was removed in version 1.7.6.\nAn equivalent limit_conn_zone directive\nwith a changed syntax should be used instead:\n
\nlimit_conn_zone\n$variable\nzone=name:size;\n
\n
\n\n\n\n
$limit_conn_statusPASSED,\nREJECTED, or\nREJECTED_DRY_RUN\n\n
\n\n| Example Configuration Directives limit_req limit_req_dry_run limit_req_log_level limit_req_status limit_req_zone Embedded Variables |
\nThe ngx_http_limit_req_module module (0.7.21) is used\nto limit the request processing rate per a defined key,\nin particular, the processing rate of requests coming\nfrom a single IP address.\nThe limitation is done using the “leaky bucket” method.\n
\n
\nhttp {\n limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;\n\n ...\n\n server {\n\n ...\n\n location /search/ {\n limit_req zone=one burst=5;\n }\n\n
\n\n\n| \n Syntax:\n | \n\n limit_req \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the shared memory zone\nand the maximum burst size of requests.\nIf the requests rate exceeds the rate configured for a zone,\ntheir processing is delayed such that requests are processed\nat a defined rate.\nExcessive requests are delayed until their number exceeds the\nmaximum burst size\nin which case the request is terminated with an\nerror.\nBy default, the maximum burst size is equal to zero.\nFor example, the directives\n
\nlimit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;\n\nserver {\n location /search/ {\n limit_req zone=one burst=5;\n }\n\nallow not more than 1 request per second at an average,\nwith bursts not exceeding 5 requests.\n
\nIf delaying of excessive requests while requests are being limited is not\ndesired, the parameter nodelay should be used:\n
\nlimit_req zone=one burst=5 nodelay;\n
\n
\nThe delay parameter (1.15.7) specifies a limit\nat which excessive requests become delayed.\nDefault value is zero, i.e. all excessive requests are delayed.\n
\nThere could be several limit_req directives.\nFor example, the following configuration will limit the processing rate\nof requests coming from a single IP address and, at the same time,\nthe request processing rate by the virtual server:\n
\nlimit_req_zone $binary_remote_addr zone=perip:10m rate=1r/s;\nlimit_req_zone $server_name zone=perserver:10m rate=10r/s;\n\nserver {\n ...\n limit_req zone=perip burst=5 nodelay;\n limit_req zone=perserver burst=10;\n}\n\n\n
\nThese directives are inherited from the previous configuration level\nif and only if there are no limit_req directives\ndefined on the current level.\n
| \n Syntax:\n | \n\n limit_req_dry_run \n | \n
|---|---|
| \n Default:\n | \n\n limit_req_dry_run off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.17.1.\n
\nEnables the dry run mode.\nIn this mode, requests processing rate is not limited, however,\nin the shared memory zone, the number of excessive requests is accounted\nas usual.\n
| \n Syntax:\n | \n\n limit_req_log_level \n\n | \n
|---|---|
| \n Default:\n | \n\n limit_req_log_level error;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.8.18.\n
\nSets the desired logging level\nfor cases when the server refuses to process requests\ndue to rate exceeding,\nor delays request processing.\nLogging level for delays is one point less than for refusals; for example,\nif “limit_req_log_level notice” is specified,\ndelays are logged with the info level.\n
| \n Syntax:\n | \n\n limit_req_status \n | \n
|---|---|
| \n Default:\n | \n\n limit_req_status 503;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.3.15.\n
\nSets the status code to return in response to rejected requests.\n
| \n Syntax:\n | \n\n limit_req_zone \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nSets parameters for a shared memory zone\nthat will keep states for various keys.\nIn particular, the state stores the current number of excessive requests.\nThe key can contain text, variables, and their combination.\nRequests with an empty key value are not accounted.\n
\nPrior to version 1.7.6, a key could contain exactly one variable.\n\nUsage example:\n
\nlimit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;\n
\n
\nHere, the states are kept in a 10 megabyte zone “one”, and an\naverage request processing rate for this zone cannot exceed\n1 request per second.\n
\nA client IP address serves as a key.\nNote that instead of $remote_addr, the\n$binary_remote_addr variable is used here.\nThe $binary_remote_addr variable’s size\nis always 4 bytes for IPv4 addresses or 16 bytes for IPv6 addresses.\nThe stored state always occupies\n64 bytes on 32-bit platforms and 128 bytes on 64-bit platforms.\nOne megabyte zone can keep about 16 thousand 64-byte states\nor about 8 thousand 128-byte states.\n
\nIf the zone storage is exhausted, the least recently used state is removed.\nIf even after that a new state cannot be created, the request is terminated with\nan error.\n
\nThe rate is specified in requests per second (r/s).\nIf a rate of less than one request per second is desired,\nit is specified in request per minute (r/m).\nFor example, half-request per second is 30r/m.\n
\nThe sync parameter (1.15.3) enables\nsynchronization\nof the shared memory zone.\n
\nThe sync parameter is available as part of our\ncommercial subscription.\n\n
\n
\nAdditionally, as part of our\ncommercial subscription,\nthe\nstatus information\nfor each such shared memory zone can be\nobtained or\nreset\nwith the API since 1.17.7.\n
\n
\n\n\n\n
$limit_req_statusPASSED,\nDELAYED,\nREJECTED,\nDELAYED_DRY_RUN, or\nREJECTED_DRY_RUN\n\n
\n\n| Example Configuration Directives access_log log_format open_log_file_cache |
\nThe ngx_http_log_module module writes request logs\nin the specified format.\n
\nRequests are logged in the context of a location where processing ends.\nIt may be different from the original location, if an\ninternal\nredirect happens during request processing.\n
\n\n\n\n
\nlog_format compression '$remote_addr - $remote_user [$time_local] '\n '\"$request\" $status $bytes_sent '\n '\"$http_referer\" \"$http_user_agent\" \"$gzip_ratio\"';\n\naccess_log /spool/logs/nginx-access.log compression buffer=32k;\n
\n
\n\n\n| \n Syntax:\n | \n\n access_log \n access_log \n | \n
|---|---|
| \n Default:\n | \n\n access_log logs/access.log combined;\n | \n
| \n Context:\n | \n\n http, server, location, if in location, limit_except\n | \n
\nSets the path, format, and configuration for a buffered log write.\nSeveral logs can be specified on the same configuration level.\nLogging to syslog\ncan be configured by specifying\nthe “syslog:” prefix in the first parameter.\nThe special value off cancels all\naccess_log directives on the current level.\nIf the format is not specified then the predefined\n“combined” format is used.\n
\nIf either the buffer or gzip\n(1.3.10, 1.2.7)\nparameter is used, writes to log will be buffered.\n
\nThe buffer size must not exceed the size of an atomic write to a disk file.\nFor FreeBSD this size is unlimited.\n
\n
\nWhen buffering is enabled, the data will be written to the file:\n
flush\nparameter (1.3.10, 1.2.7);\n\n
\nIf the gzip parameter is used, then the buffered data will\nbe compressed before writing to the file.\nThe compression level can be set between 1 (fastest, less compression)\nand 9 (slowest, best compression).\nBy default, the buffer size is equal to 64K bytes, and the compression level\nis set to 1.\nSince the data is compressed in atomic blocks, the log file can be decompressed\nor read by “zcat” at any time.\n
\nExample:\n
\naccess_log /path/to/log.gz combined gzip flush=5m;\n
\n
\n
\nFor gzip compression to work, nginx must be built with the zlib library.\n
\n
\nThe file path can contain variables (0.7.6+),\nbut such logs have some constraints:\n
valid parameter\naccess_log on the same configuration level:\n\nserver {\n root /spool/vhost/data/$host;\n access_log /spool/vhost/logs/$host;\n ...\n\n\n
\nThe if parameter (1.7.0) enables conditional logging.\nA request will not be logged if the condition evaluates to “0”\nor an empty string.\nIn the following example, the requests with response codes 2xx and 3xx\nwill not be logged:\n
\nmap $status $loggable {\n ~^[23] 0;\n default 1;\n}\n\naccess_log /path/to/access.log combined if=$loggable;\n\n
| \n Syntax:\n | \n\n log_format \n \n | \n
|---|---|
| \n Default:\n | \n\n log_format combined \"...\";\n | \n
| \n Context:\n | \n\n http\n | \n
\nSpecifies log format.\n
\nThe escape parameter (1.11.8) allows setting\njson or default characters escaping\nin variables, by default, default escaping is used.\nThe none value (1.13.10) disables escaping.\n
\nFor default escaping,\ncharacters “\"”, “\\”,\nand other characters with values less than 32 (0.7.0) or above 126 (1.1.6)\nare escaped as “\\xXX”.\nIf the variable value is not found,\na hyphen (“-”) will be logged.\n
\nFor json escaping,\nall characters not allowed\nin JSON strings\nwill be escaped:\ncharacters “\"” and\n“\\” are escaped as\n“\\\"” and “\\\\”,\ncharacters with values less than 32 are escaped as\n“\\n”,\n“\\r”,\n“\\t”,\n“\\b”,\n“\\f”, or\n“\\u00XX”.\n\n
\nThe log format can contain common variables, and variables that\nexist only at the time of a log write:\n
$bytes_sent$connection$connection_requests\n$msec$pipep” if request was pipelined, “.”\notherwise\n$request_length$request_time$status$time_iso8601$time_local\n\n
\nIn the modern nginx versions variables\n$status\n(1.3.2, 1.2.2),\n$bytes_sent\n(1.3.8, 1.2.5),\n$connection\n(1.3.8, 1.2.5),\n$connection_requests\n(1.3.8, 1.2.5),\n$msec\n(1.3.9, 1.2.6),\n$request_time\n(1.3.9, 1.2.6),\n$pipe\n(1.3.12, 1.2.7),\n$request_length\n(1.3.12, 1.2.7),\n$time_iso8601\n(1.3.12, 1.2.7),\nand\n$time_local\n(1.3.12, 1.2.7)\nare also available as common variables.\n
\n\n
\nHeader lines sent to a client have the prefix\n“sent_http_”, for example,\n$sent_http_content_range.\n
\nThe configuration always includes the predefined\n“combined” format:\n
\nlog_format combined '$remote_addr - $remote_user [$time_local] '\n '\"$request\" $status $body_bytes_sent '\n '\"$http_referer\" \"$http_user_agent\"';\n
\n
| \n Syntax:\n | \n\n open_log_file_cache \nopen_log_file_cache \n | \n
|---|---|
| \n Default:\n | \n\n open_log_file_cache off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a cache that stores the file descriptors of frequently used logs\nwhose names contain variables.\nThe directive has the following parameters:\n
maxinactivemin_usesinactive parameter\nto let the descriptor stay open in a cache;\nby default, 1\nvalidoff\n
\nUsage example:\n
\nopen_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;\n
\n
\n\n| Example Configuration Directives map map_hash_bucket_size map_hash_max_size |
\nThe ngx_http_map_module module creates variables\nwhose values depend on values of other variables.\n
\n
\nmap $http_host $name {\n hostnames;\n\n default 0;\n\n example.com 1;\n *.example.com 1;\n example.org 2;\n *.example.org 2;\n .example.net 3;\n wap.* 4;\n}\n\nmap $http_user_agent $mobile {\n default 0;\n \"~Opera Mini\" 1;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n map \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nCreates a new variable whose value\ndepends on values of one or more of the source variables\nspecified in the first parameter.\n
\nBefore version 0.9.0 only a single variable could be\nspecified in the first parameter.\n
\n
\n
\nSince variables are evaluated only when they are used, the mere declaration\neven of a large number of “map” variables\ndoes not add any extra costs to request processing.\n\n
\nParameters inside the map block specify a mapping\nbetween source and resulting values.\n
\nSource values are specified as strings or regular expressions (0.9.6).\n
\nStrings are matched ignoring the case.\n
\nA regular expression should either start from the “~”\nsymbol for a case-sensitive matching, or from the “~*”\nsymbols (1.0.4) for case-insensitive matching.\nA regular expression can contain named and positional captures\nthat can later be used in other directives along with the\nresulting variable.\n
\nIf a source value matches one of the names of special parameters\ndescribed below, it should be prefixed with the “\\” symbol.\n
\nThe resulting value can contain text,\nvariable (0.9.0), and their combination (1.11.0).\n
\nThe following special parameters are also supported:\n
default valuedefault is not specified, the default\nresulting value will be an empty string.\nhostnames\nThe following two records\n\n*.example.com 1;\nexample.* 1;\n
\ncan be combined:\n\nexample.com 1;\n*.example.com 1;\n
\nThis parameter should be specified before the list of values.\n\n.example.com 1;\n
include filevolatile\n
\nThe search is performed in the following order of priority\nand terminates on the first matching variant:\n
*.example.com”\nmail.*”\n\n
| \n Syntax:\n | \n\n map_hash_bucket_size \n | \n
|---|---|
| \n Default:\n | \n\n map_hash_bucket_size 32|64|128;\n | \n
| \n Context:\n | \n\n http\n | \n
\nSets the bucket size for the map variables hash tables.\nDefault value depends on the processor’s cache line size.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
| \n Syntax:\n | \n\n map_hash_max_size \n | \n
|---|---|
| \n Default:\n | \n\n map_hash_max_size 2048;\n | \n
| \n Context:\n | \n\n http\n | \n
\nSets the maximum size of the map variables\nhash tables.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
\nThe ngx_http_memcached_module module is used to obtain\nresponses from a memcached server.\nThe key is set in the $memcached_key variable.\nA response should be put in memcached in advance by means\nexternal to nginx.\n
\n
\nserver {\n location / {\n set $memcached_key \"$uri?$args\";\n memcached_pass host:11211;\n error_page 404 502 504 = @fallback;\n }\n\n location @fallback {\n proxy_pass http://backend;\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n memcached_allow_upstream \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nDefines conditions under which access to a memcached server\nis allowed or denied.\nIf all string parameters are not empty\nand not equal to “0” then the access is allowed.\nThe conditions are evaluated each time\nbefore a connection to a memcached server is established.\nParameter values can contain variables:\n
\ngeo $upstream_last_addr $allow {\n volatile;\n 10.10.0.0/24 1;\n}\n\nserver {\n listen 127.0.0.1:8080;\n\n location / {\n memcached_pass host:11211;\n memcached_allow_upstream $allow;\n ...\n }\n}\n\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n memcached_bind \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.8.22.\n
\nMakes outgoing connections to a memcached server originate\nfrom the specified local IP address with an optional port (1.11.2).\nParameter value can contain variables (1.3.12).\nThe special value off (1.3.12) cancels the effect\nof the memcached_bind directive\ninherited from the previous configuration level, which allows the\nsystem to auto-assign the local IP address and port.\n
\nThe transparent parameter (1.11.0) allows\noutgoing connections to a memcached server originate\nfrom a non-local IP address,\nfor example, from a real IP address of a client:\n
\nmemcached_bind $remote_addr transparent;\n
\nIn order for this parameter to work,\nit is usually necessary to run nginx worker processes with the\nsuperuser privileges.\nOn Linux it is not required (1.13.8) as if\nthe transparent parameter is specified, worker processes\ninherit the CAP_NET_RAW capability from the master process.\nIt is also necessary to configure kernel routing table\nto intercept network traffic from the memcached server.\n
| \n Syntax:\n | \n\n memcached_bind_dynamic \n | \n
|---|---|
| \n Default:\n | \n\n memcached_bind_dynamic off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nWhen enabled, makes the bind operation\nat each connection attempt.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n memcached_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n memcached_buffer_size 4k|8k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the size of the buffer used for reading the response\nreceived from the memcached server.\nThe response is passed to the client synchronously, as soon as it is received.\n
| \n Syntax:\n | \n\n memcached_connect_timeout \n | \n
|---|---|
| \n Default:\n | \n\n memcached_connect_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a timeout for establishing a connection with a memcached server.\nIt should be noted that this timeout cannot usually exceed 75 seconds.\n
| \n Syntax:\n | \n\n memcached_gzip_flag \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.3.6.\n
\nEnables the test for the flag presence in the memcached\nserver response and sets the “Content-Encoding”\nresponse header field to “gzip”\nif the flag is set.\n
| \n Syntax:\n | \n\n memcached_next_upstream \n \n | \n
|---|---|
| \n Default:\n | \n\n memcached_next_upstream error timeout;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies in which cases a request should be passed to the next server:\n
errortimeoutdenied\n
\nThis parameter is available as part of our\ncommercial subscription.\n
\n
\ninvalid_responsenot_foundoff\n
\nOne should bear in mind that passing a request to the next server is\nonly possible if nothing has been sent to a client yet.\nThat is, if an error or timeout occurs in the middle of the\ntransferring of a response, fixing this is impossible.\n
\nThe directive also defines what is considered an\nunsuccessful\nattempt of communication with a server.\nThe cases of error, timeout,\ndenied and\ninvalid_response are always considered unsuccessful attempts,\neven if they are not specified in the directive.\nThe case of not_found\nis never considered an unsuccessful attempt.\n
\nPassing a request to the next server can be limited by\nthe number of tries\nand by time.\n
| \n Syntax:\n | \n\n memcached_next_upstream_timeout \n | \n
|---|---|
| \n Default:\n | \n\n memcached_next_upstream_timeout 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.5.\n
\nLimits the time during which a request can be passed to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n memcached_next_upstream_tries \n | \n
|---|---|
| \n Default:\n | \n\n memcached_next_upstream_tries 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.5.\n
\nLimits the number of possible tries for passing a request to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n memcached_pass \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location, if in location\n | \n
\nSets the memcached server address.\nThe address can be specified as a domain name or IP address,\nand a port:\n
\nmemcached_pass localhost:11211;\n
\nor as a UNIX-domain socket path:\n
\nmemcached_pass unix:/tmp/memcached.socket;\n
\n
\nIf a domain name resolves to several addresses, all of them will be\nused in a round-robin fashion.\nIn addition, an address can be specified as a\nserver group.\n
| \n Syntax:\n | \n\n memcached_read_timeout \n | \n
|---|---|
| \n Default:\n | \n\n memcached_read_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a timeout for reading a response from the memcached server.\nThe timeout is set only between two successive read operations,\nnot for the transmission of the whole response.\nIf the memcached server does not transmit anything within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n memcached_send_timeout \n | \n
|---|---|
| \n Default:\n | \n\n memcached_send_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a timeout for transmitting a request to the memcached server.\nThe timeout is set only between two successive write operations,\nnot for the transmission of the whole request.\nIf the memcached server does not receive anything within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n memcached_socket_keepalive \n | \n
|---|---|
| \n Default:\n | \n\n memcached_socket_keepalive off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.15.6.\n
\nConfigures the “TCP keepalive” behavior\nfor outgoing connections to a memcached server.\nBy default, the operating system’s settings are in effect for the socket.\nIf the directive is set to the value “on”, the\nSO_KEEPALIVE socket option is turned on for the socket.\n
\n
$memcached_key\n
\n\n| Example Configuration Directives mirror mirror_request_body |
\nThe ngx_http_mirror_module module (1.13.4) implements\nmirroring of an original request\nby creating background mirror subrequests.\nResponses to mirror subrequests are ignored.\n
\n
\nlocation / {\n mirror /mirror;\n proxy_pass http://backend;\n}\n\nlocation = /mirror {\n internal;\n proxy_pass http://test_backend$request_uri;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n mirror \n | \n
|---|---|
| \n Default:\n | \n\n mirror off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the URI to which an original request will be mirrored.\nSeveral mirrors can be specified on the same configuration level.\n
| \n Syntax:\n | \n\n mirror_request_body \n | \n
|---|---|
| \n Default:\n | \n\n mirror_request_body on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIndicates whether the client request body is mirrored.\nWhen enabled, the client request body will be read\nprior to creating mirror subrequests.\nIn this case, unbuffered client request body proxying\nset by the\nproxy_request_buffering,\nfastcgi_request_buffering,\nscgi_request_buffering,\nand\nuwsgi_request_buffering\ndirectives will be disabled.\n
\nlocation / {\n mirror /mirror;\n mirror_request_body off;\n proxy_pass http://backend;\n}\n\nlocation = /mirror {\n internal;\n proxy_pass http://log_backend;\n proxy_pass_request_body off;\n proxy_set_header Content-Length \"\";\n proxy_set_header X-Original-URI $request_uri;\n}\n\n
\n\n| Example Configuration Directives mp4 mp4_buffer_size mp4_max_buffer_size mp4_limit_rate mp4_limit_rate_after mp4_start_key_frame |
\nThe ngx_http_mp4_module module provides pseudo-streaming\nserver-side support for MP4 files.\nSuch files typically have the .mp4, .m4v,\nor .m4a filename extensions.\n
\nPseudo-streaming works in alliance with a compatible media player.\nThe player sends an HTTP request to the server with the start time\nspecified in the query string argument (named simply\nstart\nand specified in seconds), and the server responds with the stream\nsuch that its start position corresponds to the requested time,\nfor example:\n
\nhttp://example.com/elephants_dream.mp4?start=238.88\n
\nThis allows performing a random seeking at any time, or starting playback\nin the middle of the timeline.\n
\nTo support seeking, H.264-based formats store metadata\nin a so-called “moov atom”.\nIt is a part of the file that holds the index information for the\nwhole file.\n
\nTo start playback, the player first needs to read metadata.\nThis is done by sending a special request with the\nstart=0 argument.\nA lot of encoding software insert the metadata at\nthe end of the file.\nThis is suboptimal for pseudo-streaming, because the player\nhas to download the entire file before starting playback.\nIf the metadata are located at the beginning of the file,\nit is enough for nginx to simply start sending back the file contents.\nIf the metadata are located at the end of the file,\nnginx must read the entire file and prepare a new stream so that\nthe metadata come before the media data.\nThis involves some CPU, memory, and disk I/O overhead,\nso it is a good idea to\n\nprepare an original file for pseudo-streaming in advance,\nrather than having nginx do this on every such request.\n
\nThe module also supports the end argument of an HTTP request\n(1.5.13) which sets the end point of playback.\nThe end argument can be specified with the\nstart argument\nor separately:\n
\nhttp://example.com/elephants_dream.mp4?start=238.88&end=555.55\n
\n
\nFor a matching request with a non-zero\nstart or end\nargument, nginx will read the metadata from the file, prepare the\nstream with the requested time range, and send it to the client.\nThis has the same overhead as described above.\n
\nIf the start argument points to\na non-key video frame,\nthe beginning of such video will be broken.\nTo fix this issue, the video\ncan be prepended with\nthe key frame before start point\nand with all intermediate frames between them.\nThese frames will be hidden from playback\nusing an edit list (1.21.4).\n
\nIf a matching request does not include the\nstart and end\narguments, there is no overhead, and the file is sent simply as a static\nresource.\nSome players also support byte-range requests, and thus do not require\nthis module.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_mp4_module\nconfiguration parameter.\n
\nIf a third-party mp4 module was previously used, it should be disabled.\n
\n
\nA similar pseudo-streaming support for FLV files is provided by the\nngx_http_flv_module module.\n
\n\n\n\n
\nlocation /video/ {\n mp4;\n mp4_buffer_size 1m;\n mp4_max_buffer_size 5m;\n mp4_limit_rate on;\n mp4_limit_rate_after 30s;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n mp4;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nTurns on module processing in a surrounding location.\n
| \n Syntax:\n | \n\n mp4_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n mp4_buffer_size 512K;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the initial size of the buffer used for\nprocessing MP4 files.\n
| \n Syntax:\n | \n\n mp4_max_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n mp4_max_buffer_size 10M;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDuring metadata processing, a larger buffer may become necessary.\nIts size cannot exceed the specified size,\nor else nginx will return the\n500 (Internal Server Error) server error,\nand log the following message:\n
\n\"/some/movie/file.mp4\" mp4 moov atom is too large:\n12583268, you may want to increase mp4_max_buffer_size\n
\n
| \n Syntax:\n | \n\n mp4_limit_rate \n \n | \n
|---|---|
| \n Default:\n | \n\n mp4_limit_rate off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nLimits the rate of response transmission to a client.\nThe rate is limited based on the average bitrate of the\nMP4 file served.\nTo calculate the rate, the bitrate is multiplied by the specified\nfactor.\nThe special value “on” corresponds to the factor of 1.1.\nThe special value “off” disables rate limiting.\nThe limit is set per a request, and so if a client simultaneously opens\ntwo connections, the overall rate will be twice as much\nas the specified limit.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n mp4_limit_rate_after \n | \n
|---|---|
| \n Default:\n | \n\n mp4_limit_rate_after 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the initial amount of media data (measured in playback time)\nafter which the further transmission of the response to a client\nwill be rate limited.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n mp4_start_key_frame \n | \n
|---|---|
| \n Default:\n | \n\n mp4_start_key_frame off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.21.4.\n
\nForces output video to always start with a key video frame.\nIf the start argument does not point to a key frame,\ninitial frames are hidden using an mp4 edit list.\nEdit lists are supported by major players and browsers such as\nChrome, Safari, QuickTime and ffmpeg,\npartially supported by Firefox.\n
| Example Configuration Directives num_map |
\nThe ngx_http_num_map_module module (1.29.3)\ncreates variables whose values depend on numeric values\nor numeric value ranges.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nnum_map $remote_port $port_allow {\n default 0;\n\n 80 1;\n 443 1;\n <=1023 0;\n 8080-8090 1;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n num_map \n [\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nDescribes how the values of the specified variable depend on numeric values\nor numeric value ranges.\n
\n
\nSince variables are evaluated only when used, the mere existence\nof even a large number of declared “num_map” variables\ndoes not cause any extra costs for request processing.\n\n
\nParameters inside the num_map block specify a mapping\nbetween source and resulting values.\n
\nSource values are specified as numbers or as numeric ranges.\n
\nThe following special parameters are also supported:\n
defaultdefault is not specified, the default\nresulting value will be an empty string.\nincludevolatile\n
\n\n\nThe ngx_http_oidc_module module (1.27.4)\nimplements authentication as a Relying Party in OpenID Connect using the\n\nAuthorization Code Flow.\n
\nThe module expects the OpenID Provider's configuration to be available via\n\nmetadata and requires dynamic\nresolver.\n
\nThe module can be combined with other access modules\nvia the satisfy directive.\nNote that the module may still block requests even with\nsatisfy any;\nas an OpenID Provider might not redirect the user back to nginx.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nhttp {\n resolver 10.0.0.1;\n\n oidc_provider my_idp {\n issuer \"https://provider.domain\";\n client_id \"unique_id\";\n client_secret \"unique_secret\";\n }\n\n server {\n location / {\n auth_oidc my_idp;\n\n proxy_set_header username $oidc_claim_sub;\n proxy_pass http://backend;\n }\n }\n}\n \nThe example assumes that the\n“https://<nginx-host>/oidc_callback”\nRedirection URI is configured on the OpenID Provider's side.\nThe path can be customized with the redirect_uri directive.\n
| \n Syntax:\n | \n\n oidc_provider \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nDefines an OpenID Provider for use with the auth_oidc directive.\n
| \n Syntax:\n | \n\n auth_oidc \n | \n
|---|---|
| \n Default:\n | \n\n auth_oidc off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables end user authentication with the\nspecified OpenID Provider.\n
\nParameter value can contain variables (1.29.0).\n
\nThe special value off cancels the effect\nof the auth_oidc directive\ninherited from the previous configuration level.\n
| \n Syntax:\n | \n\n issuer \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
\nSets the Issuer Identifier URL of the OpenID Provider;\nrequired directive.\nThe URL must exactly match the value of “issuer”\nin the OpenID Provider metadata\nand requires the “https” scheme.\n
| \n Syntax:\n | \n\n client_id \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
\nSpecifies the client ID of the Relying Party;\nrequired directive.\n
| \n Syntax:\n | \n\n client_secret \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
\nSpecifies a secret value\nused to authenticate the Relying Party with the OpenID Provider.\nThe supported\nauthentication\nmethods are\nclient_secret_basic and\nclient_secret_post (1.29.3).\nThe method is selected based on the OpenID Provider metadata\nwith a preference to client_secret_basic.\n
| \n Syntax:\n | \n\n config_url \n | \n
|---|---|
| \n Default:\n | \n\n config_url <issuer>/.well-known/openid-configuration;\n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
\nSets a custom URL to retrieve the OpenID Provider metadata.\n
| \n Syntax:\n | \n\n cookie_name \n | \n
|---|---|
| \n Default:\n | \n\n cookie_name NGX_OIDC_SESSION;\n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
\nSets the name of a session cookie.\n
| \n Syntax:\n | \n\n extra_auth_args \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
\nSets additional query arguments for the\nauthentication\nrequest URL.\n
\nextra_auth_args \"display=page&prompt=login\";\n
\n
| \n Syntax:\n | \n\n frontchannel_logout_uri \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
This directive appeared in version 1.29.3.\n
\nDefines the URI path for triggering\nfront-channel\nlogout.\nFor the logout request to be associated with a user session,\nit must either include the module session cookie or provide\nboth the “iss” and “sid” arguments.\nIt is recommended to configure the OpenID Provider to set the\n“iss” and “sid” arguments\nwhen invoking this endpoint.\n
| \n Syntax:\n | \n\n pkce \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
This directive appeared in version 1.29.3.\n
\nExplicitly enables or disables PKCE.\nBy default, PKCE is automatically enabled\nbased on OpenID Provider metadata.\n
| \n Syntax:\n | \n\n redirect_uri \n | \n
|---|---|
| \n Default:\n | \n\n redirect_uri /oidc_callback;\n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
\nDefines the Redirection URI path for post-authentication redirects\nexpected by the module from the OpenID Provider.\nThe uri must match the configuration on the Provider's side.\n
\nAbsolute “https” URIs are supported since 1.29.0.\n
| \n Syntax:\n | \n\n logout_uri \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
This directive appeared in version 1.29.0.\n
\nDefines the URI path for initiating session logout.\nUpon session termination, the user is redirected to\nProvider's\nLogout Endpoint\nor to the post logout page.\nIf neither is configured, the built-in post logout page is displayed.\n
| \n Syntax:\n | \n\n post_logout_uri \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
This directive appeared in version 1.29.0.\n
\nDefines the path or absolute URI\nto redirect the user to after the logout.\nThe uri must match the configuration on the Provider's side.\nIf the post logout page is served by NGINX,\nthe OIDC module shouldn't be enabled for this location:\n
\nhttp {\n oidc_provider my_idp {\n ...\n\n logout_uri /logout;\n post_logout_uri /logged_out_page.html;\n }\n\n server {\n auth_oidc my_idp;\n\n location /logged_out_page.html {\n auth_oidc off;\n }\n }\n}\n\n
| \n Syntax:\n | \n\n logout_token_hint \n | \n
|---|---|
| \n Default:\n | \n\n logout_token_hint off;\n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
This directive appeared in version 1.29.0.\n
\nAdds the\nid_token_hint\nargument to the\nProvider's\nLogout Endpoint\nwhen redirecting user during logout.\nThis argument can be required by some OpenID Providers.\n
| \n Syntax:\n | \n\n scope \n | \n
|---|---|
| \n Default:\n | \n\n scope openid;\n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
\nSets requested scopes.\nThe openid scope is always required by OIDC.\n
| \n Syntax:\n | \n\n session_store \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
\nSpecifies a custom\nkey-value database\nthat stores session data.\nBy default, an 8-megabyte key-value database named \noidc_default_store_<provider name>\nis created automatically.\n
\nA separate key-value database should be configured for each Provider\nto prevent session reuse across providers.\n
\n
| \n Syntax:\n | \n\n session_timeout \n | \n
|---|---|
| \n Default:\n | \n\n session_timeout 8h;\n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
\nSets a timeout after which the session is deleted, unless it was\nrefreshed.\n
| \n Syntax:\n | \n\n ssl_crl \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
\nSpecifies a file with revoked certificates (CRL)\nin the PEM format used to verify\nthe certificates of the OpenID Provider endpoints.\nWhen using intermediate certificates, their CRLs should be\nspecified in the same file.\n
| \n Syntax:\n | \n\n ssl_trusted_certificate \n | \n
|---|---|
| \n Default:\n | \n\n ssl_trusted_certificate system CA bundle;\n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to verify\nthe certificates of the OpenID Provider endpoints.\n
| \n Syntax:\n | \n\n userinfo \n | \n
|---|---|
| \n Default:\n | \n\n userinfo off;\n | \n
| \n Context:\n | \n\n oidc_provider\n | \n
This directive appeared in version 1.29.0.\n
\nEnables downloading of the\nUserInfo\ndata and makes UserInfo claims available via the \n$oidc_claim_name variables.\n
\nThe ngx_http_oidc_module module supports embedded variables:\n
\n
$oidc_id_token$oidc_access_token$oidc_claim_name\nNested claims can be fetched with the\nauth_jwt module:\n
\nhttp {\n auth_jwt_claim_set $postal_code address postal_code;\n\n server {\n location / {\n auth_oidc my_idp;\n auth_jwt off token=$oidc_id_token;\n\n proxy_set_header x-postal_code $postal_code;\n proxy_pass http://backend;\n }\n }\n}\n\n
\n\n$oidc_userinfo\n
\n\n| Known Issues Example Configuration Directives perl perl_modules perl_require perl_set Calling Perl from SSI The $r Request Object Methods |
\nThe ngx_http_perl_module module is used to implement\nlocation and variable handlers in Perl and insert Perl calls into SSI.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_perl_module\nconfiguration parameter.\n
\nThis module requires\nPerl version 5.6.1 or higher.\nThe C compiler should be compatible with the one used to build Perl.\n
\n
\n\n\n\nThe module is experimental, caveat emptor applies.\n
\nIn order for Perl to recompile the modified modules during\nreconfiguration, it should be built with the\n-Dusemultiplicity=yes or\n-Dusethreads=yes parameters.\nAlso, to make Perl leak less memory at run time,\nit should be built with the\n-Dusemymalloc=no parameter.\nTo check the values of these parameters in an already built\nPerl (preferred values are specified in the example), run:\n
\n$ perl -V:usemultiplicity -V:usemymalloc\nusemultiplicity='define';\nusemymalloc='n';\n
\n
\nNote that after rebuilding Perl with the new\n-Dusemultiplicity=yes or\n-Dusethreads=yes parameters,\nall binary Perl modules will have to be rebuilt as well —\nthey will just stop working with the new Perl.\n
\nThere is a possibility that the main process and then worker processes will\ngrow in size after every reconfiguration.\nIf the main process grows to an unacceptable size, the\nlive upgrade\nprocedure can be applied without changing the executable file.\n
\nWhile the Perl module is performing a long-running operation, such as\nresolving a domain name, connecting to another server, or querying a database,\nother requests assigned to the current worker process will not be processed.\nIt is thus recommended to perform only such operations\nthat have predictable and short execution time, such as\naccessing the local file system.\n
\n\n\n\n
\nhttp {\n\n perl_modules perl/lib;\n perl_require hello.pm;\n\n perl_set $msie6 '\n\n sub {\n my $r = shift;\n my $ua = $r->header_in(\"User-Agent\");\n\n return \"\" if $ua =~ /Opera/;\n return \"1\" if $ua =~ / MSIE [6-9]\\.\\d+/;\n return \"\";\n }\n\n ';\n\n server {\n location / {\n perl hello::handler;\n }\n }\n\n
\nThe perl/lib/hello.pm module:\n
\npackage hello;\n\nuse nginx;\n\nsub handler {\n my $r = shift;\n\n $r->send_http_header(\"text/html\");\n return OK if $r->header_only;\n\n $r->print(\"hello!\\n<br/>\");\n\n if (-f $r->filename or -d _) {\n $r->print($r->uri, \" exists!\\n\");\n }\n\n return OK;\n}\n\n1;\n__END__\n\n
\n\n\n| \n Syntax:\n | \n\n perl \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location, limit_except\n | \n
\nSets a Perl handler for the given location.\n
| \n Syntax:\n | \n\n perl_modules \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nSets an additional path for Perl modules.\n
| \n Syntax:\n | \n\n perl_require \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nDefines the name of a module that will be loaded during each\nreconfiguration.\nSeveral perl_require directives can be present.\n
| \n Syntax:\n | \n\n perl_set \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nInstalls a Perl handler for the specified variable.\n
\n\n\n\nAn SSI command calling Perl has the following format:\n
\n<!--# perl sub=\"module::function\" arg=\"parameter1\" arg=\"parameter2\" ...\n-->\n
\n
\n\n\n\n
$r->args$r->filename$r->has_request_body(handler)\n\npackage hello;\n\nuse nginx;\n\nsub handler {\n my $r = shift;\n\n if ($r->request_method ne \"POST\") {\n return DECLINED;\n }\n\n if ($r->has_request_body(\\&post)) {\n return OK;\n }\n\n return HTTP_BAD_REQUEST;\n}\n\nsub post {\n my $r = shift;\n\n $r->send_http_header;\n\n $r->print(\"request_body: \\\"\", $r->request_body, \"\\\"<br/>\");\n $r->print(\"request_body_file: \\\"\", $r->request_body_file, \"\\\"<br/>\\n\");\n\n return OK;\n}\n\n1;\n\n__END__\n\n$r->allow_ranges$r->discard_request_body$r->header_in(field)$r->header_only$r->header_out(field,\n value)\n$r->internal_redirect(uri)\nuri.\nAn actual redirect happens after the Perl handler execution is completed.\n\nSince version 1.17.2, the method accepts escaped URIs and\nsupports redirections to named locations.\n\n
$r->log_error(errno,\nmessage)message into the\nerror_log.\nIf errno is non-zero, an error code and its description\nwill be appended to the message.\n$r->print(text, ...)$r->request_body$r->request_body_file$r->request_method$r->remote_addr$r->flush$r->sendfile(name[,\n offset[,\n length]])\n$r->send_http_header([type])\ntype parameter sets the value of\nthe “Content-Type” response header field.\nIf the value is an empty string, the “Content-Type”\nheader field will not be sent.\n$r->status(code)$r->sleep(milliseconds,\n handler)\n$r->variable() should be used.\nExample:\n\npackage hello;\n\nuse nginx;\n\nsub handler {\n my $r = shift;\n\n $r->discard_request_body;\n $r->variable(\"var\", \"OK\");\n $r->sleep(1000, \\&next);\n\n return OK;\n}\n\nsub next {\n my $r = shift;\n\n $r->send_http_header;\n $r->print($r->variable(\"var\"));\n\n return OK;\n}\n\n1;\n\n__END__\n\n$r->unescape(text)$r->uri$r->variable(name[,\n value])\n\n
\n\n\nThe ngx_http_proxy_module module allows passing\nrequests to another server.\n
\n
\nlocation / {\n proxy_pass http://localhost:8000;\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n proxy_allow_upstream \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nDefines conditions under which access to a proxied server\nis allowed or denied.\nIf all string parameters are not empty\nand not equal to “0” then the access is allowed.\nThe conditions are evaluated each time\nbefore a connection to a proxied server is established.\nParameter values can contain variables:\n
\ngeo $upstream_last_addr $allow {\n volatile;\n 10.10.0.0/24 1;\n}\n\nserver {\n listen 127.0.0.1:8080;\n\n location / {\n proxy_pass localhost:8000;\n proxy_allow_upstream $allow;\n ...\n }\n}\n\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n proxy_bind \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.8.22.\n
\nMakes outgoing connections to a proxied server originate\nfrom the specified local IP address with an optional port (1.11.2).\nParameter value can contain variables (1.3.12).\nThe special value off (1.3.12) cancels the effect\nof the proxy_bind directive\ninherited from the previous configuration level, which allows the\nsystem to auto-assign the local IP address and port.\n
\nThe transparent parameter (1.11.0) allows\noutgoing connections to a proxied server originate\nfrom a non-local IP address,\nfor example, from a real IP address of a client:\n
\nproxy_bind $remote_addr transparent;\n
\nIn order for this parameter to work,\nit is usually necessary to run nginx worker processes with the\nsuperuser privileges.\nOn Linux it is not required (1.13.8) as if\nthe transparent parameter is specified, worker processes\ninherit the CAP_NET_RAW capability from the master process.\nIt is also necessary to configure kernel routing table\nto intercept network traffic from the proxied server.\n
| \n Syntax:\n | \n\n proxy_bind_dynamic \n | \n
|---|---|
| \n Default:\n | \n\n proxy_bind_dynamic off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nWhen enabled, makes the bind operation\nat each connection attempt.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n proxy_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n proxy_buffer_size 4k|8k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the size of the buffer used for reading the first part\nof the response received from the proxied server.\nThis part usually contains a small response header;\nif it exceeds the buffer size, the response is considered\ninvalid.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\nIt can be made smaller, however.\n
| \n Syntax:\n | \n\n proxy_buffering \n | \n
|---|---|
| \n Default:\n | \n\n proxy_buffering on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables buffering of responses from the proxied server.\n
\nWhen buffering is enabled, nginx receives a response from the proxied server\nas soon as possible, saving it into the buffers set by the\nproxy_buffer_size and proxy_buffers directives.\nIf the whole response does not fit into memory, a part of it can be saved\nto a temporary file on the disk.\nWriting to temporary files is controlled by the\nproxy_max_temp_file_size and\nproxy_temp_file_write_size directives.\n
\nWhen buffering is disabled, the response is passed to a client synchronously,\nimmediately as it is received.\nnginx will not try to read the whole response from the proxied server.\nThe maximum size of the data that nginx can receive from the server\nat a time is set by the proxy_buffer_size directive.\n
\nBuffering can also be enabled or disabled by passing\n“yes” or “no” in the\n“X-Accel-Buffering” response header field.\nThis capability can be disabled using the\nproxy_ignore_headers directive.\n
| \n Syntax:\n | \n\n proxy_buffers \n | \n
|---|---|
| \n Default:\n | \n\n proxy_buffers 8 4k|8k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the number and size of the\nbuffers used for reading a response from the proxied server,\nfor a single connection.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\n
| \n Syntax:\n | \n\n proxy_busy_buffers_size \n | \n
|---|---|
| \n Default:\n | \n\n proxy_busy_buffers_size 8k|16k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nWhen buffering of responses from the proxied\nserver is enabled, limits the total size of buffers that\ncan be busy sending a response to the client while the response is not\nyet fully read.\nIn the meantime, the rest of the buffers can be used for reading the response\nand, if needed, buffering part of the response to a temporary file.\nBy default, size is limited by the size of two buffers set by the\nproxy_buffer_size and proxy_buffers directives.\n
| \n Syntax:\n | \n\n proxy_cache \n | \n
|---|---|
| \n Default:\n | \n\n proxy_cache off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a shared memory zone used for caching.\nThe same zone can be used in several places.\nParameter value can contain variables (1.7.9).\nThe off parameter disables caching inherited\nfrom the previous configuration level.\n
| \n Syntax:\n | \n\n proxy_cache_background_update \n | \n
|---|---|
| \n Default:\n | \n\n proxy_cache_background_update off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.11.10.\n
\nAllows starting a background subrequest\nto update an expired cache item,\nwhile a stale cached response is returned to the client.\nNote that it is necessary to\nallow\nthe usage of a stale cached response when it is being updated.\n
| \n Syntax:\n | \n\n proxy_cache_bypass \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines conditions under which the response will not be taken from a cache.\nIf at least one value of the string parameters is not empty and is not\nequal to “0” then the response will not be taken from the cache:\n
\nproxy_cache_bypass $cookie_nocache $arg_nocache$arg_comment;\nproxy_cache_bypass $http_pragma $http_authorization;\n
\nCan be used along with the proxy_no_cache directive.\n
| \n Syntax:\n | \n\n proxy_cache_convert_head \n | \n
|---|---|
| \n Default:\n | \n\n proxy_cache_convert_head on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.9.7.\n
\nEnables or disables the conversion of the “HEAD” method\nto “GET” for caching.\nWhen the conversion is disabled, the\ncache key should be configured\nto include the $request_method.\n
| \n Syntax:\n | \n\n proxy_cache_key \n | \n
|---|---|
| \n Default:\n | \n\n proxy_cache_key $scheme$proxy_host$request_uri;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a key for caching, for example\n
\nproxy_cache_key \"$host$request_uri $cookie_user\";\n
\nBy default, the directive’s value is close to the string\n
\nproxy_cache_key $scheme$proxy_host$uri$is_args$args;\n
\n
| \n Syntax:\n | \n\n proxy_cache_lock \n | \n
|---|---|
| \n Default:\n | \n\n proxy_cache_lock off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.12.\n
\nWhen enabled, only one request at a time will be allowed to populate\na new cache element identified according to the proxy_cache_key\ndirective by passing a request to a proxied server.\nOther requests of the same cache element will either wait\nfor a response to appear in the cache or the cache lock for\nthis element to be released, up to the time set by the\nproxy_cache_lock_timeout directive.\n
| \n Syntax:\n | \n\n proxy_cache_lock_age \n | \n
|---|---|
| \n Default:\n | \n\n proxy_cache_lock_age 5s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.8.\n
\nIf the last request passed to the proxied server\nfor populating a new cache element\nhas not completed for the specified time,\none more request may be passed to the proxied server.\n
| \n Syntax:\n | \n\n proxy_cache_lock_timeout \n | \n
|---|---|
| \n Default:\n | \n\n proxy_cache_lock_timeout 5s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.12.\n
\nSets a timeout for proxy_cache_lock.\nWhen the time expires,\nthe request will be passed to the proxied server,\nhowever, the response will not be cached.\n
\nBefore 1.7.8, the response could be cached.\n
\n
| \n Syntax:\n | \n\n proxy_cache_max_range_offset \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.11.6.\n
\nSets an offset in bytes for byte-range requests.\nIf the range is beyond the offset,\nthe range request will be passed to the proxied server\nand the response will not be cached.\n
| \n Syntax:\n | \n\n proxy_cache_methods \n \n | \n
|---|---|
| \n Default:\n | \n\n proxy_cache_methods GET HEAD;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 0.7.59.\n
\nIf the client request method is listed in this directive then\nthe response will be cached.\n“GET” and “HEAD” methods are always\nadded to the list, though it is recommended to specify them explicitly.\nSee also the proxy_no_cache directive.\n
| \n Syntax:\n | \n\n proxy_cache_min_uses \n | \n
|---|---|
| \n Default:\n | \n\n proxy_cache_min_uses 1;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the number of requests after which the response\nwill be cached.\n
| \n Syntax:\n | \n\n proxy_cache_path \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nSets the path and other parameters of a cache.\nCache data are stored in files.\nThe file name in a cache is a result of\napplying the MD5 function to the\ncache key.\nThe levels parameter defines hierarchy levels of a cache:\nfrom 1 to 3, each level accepts values 1 or 2.\nFor example, in the following configuration\n
\nproxy_cache_path /data/nginx/cache levels=1:2 keys_zone=one:10m;\n
\nfile names in a cache will look like this:\n
\n/data/nginx/cache/c/29/b7f54b2df7773722d382f4809d65029c\n
\n
\nA cached response is first written to a temporary file,\nand then the file is renamed.\nStarting from version 0.8.9, temporary files and the cache can be put on\ndifferent file systems.\nHowever, be aware that in this case a file is copied\nacross two file systems instead of the cheap renaming operation.\nIt is thus recommended that for any given location both cache and a directory\nholding temporary files\nare put on the same file system.\nThe directory for temporary files is set based on\nthe use_temp_path parameter (1.7.10).\nIf this parameter is omitted or set to the value on,\nthe directory set by the proxy_temp_path directive\nfor the given location will be used.\nIf the value is set to off,\ntemporary files will be put directly in the cache directory.\n
\nIn addition, all active keys and information about data are stored\nin a shared memory zone, whose name and size\nare configured by the keys_zone parameter.\nOne megabyte zone can store about 8 thousand keys.\n
\nAs part of\ncommercial subscription,\nthe shared memory zone also stores extended\ncache information,\nthus, it is required to specify a larger zone size for the same number of keys.\nFor example,\none megabyte zone can store about 4 thousand keys.\n
\n
\nCached data that are not accessed during the time specified by the\ninactive parameter get removed from the cache\nregardless of their freshness.\nBy default, inactive is set to 10 minutes.\n
\nThe special “cache manager” process monitors the maximum cache size set\nby the max_size parameter,\nand the minimum amount of free space set\nby the min_free (1.19.1) parameter\non the file system with cache.\nWhen the size is exceeded or there is not enough free space,\nit removes the least recently used data.\nThe data is removed in iterations configured by\nmanager_files,\nmanager_threshold, and\nmanager_sleep parameters (1.11.5).\nDuring one iteration no more than manager_files items\nare deleted (by default, 100).\nThe duration of one iteration is limited by the\nmanager_threshold parameter (by default, 200 milliseconds).\nBetween iterations, a pause configured by the manager_sleep\nparameter (by default, 50 milliseconds) is made.\n
\nA minute after the start the special “cache loader” process is activated.\nIt loads information about previously cached data stored on file system\ninto a cache zone.\nThe loading is also done in iterations.\nDuring one iteration no more than loader_files items\nare loaded (by default, 100).\nBesides, the duration of one iteration is limited by the\nloader_threshold parameter (by default, 200 milliseconds).\nBetween iterations, a pause configured by the loader_sleep\nparameter (by default, 50 milliseconds) is made.\n
\nAdditionally,\nthe following parameters are available as part of our\ncommercial subscription:\n
\n
purger=on|off\non\n(default is off)\nwill activate the “cache purger” process that\npermanently iterates through all cache entries\nand deletes the entries that match the wildcard key.\npurger_files=number\npurger_files is set to 10.\npurger_threshold=number\npurger_threshold is set to 50 milliseconds.\npurger_sleep=number\npurger_sleep is set to 50 milliseconds.\n\n
\n
\nIn versions 1.7.3, 1.7.7, and 1.11.10 cache header format has been changed.\nPreviously cached responses will be considered invalid\nafter upgrading to a newer nginx version.\n
\n
| \n Syntax:\n | \n\n proxy_cache_purge string ...;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.7.\n
\nDefines conditions under which the request will be considered a cache\npurge request.\nIf at least one value of the string parameters is not empty and is not equal\nto “0” then the cache entry with a corresponding\ncache key is removed.\nThe result of successful operation is indicated by returning\nthe 204 (No Content) response.\n
\nIf the cache key of a purge request ends\nwith an asterisk (“*”), all cache entries matching the\nwildcard key will be removed from the cache.\nHowever, these entries will remain on the disk until they are deleted\nfor either inactivity,\nor processed by the cache purger (1.7.12),\nor a client attempts to access them.\n
\nExample configuration:\n
\nproxy_cache_path /data/nginx/cache keys_zone=cache_zone:10m;\n\nmap $request_method $purge_method {\n PURGE 1;\n default 0;\n}\n\nserver {\n ...\n location / {\n proxy_pass http://backend;\n proxy_cache cache_zone;\n proxy_cache_key $uri;\n proxy_cache_purge $purge_method;\n }\n}\n\n
\nThis functionality is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n proxy_cache_revalidate \n | \n
|---|---|
| \n Default:\n | \n\n proxy_cache_revalidate off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.7.\n
\nEnables revalidation of expired cache items using conditional requests with\nthe “If-Modified-Since” and “If-None-Match”\nheader fields.\n
| \n Syntax:\n | \n\n proxy_cache_use_stale \n \n | \n
|---|---|
| \n Default:\n | \n\n proxy_cache_use_stale off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines in which cases a stale cached response can be used\nduring communication with the proxied server.\nThe directive’s parameters match the parameters of the\nproxy_next_upstream directive.\n
\nThe error parameter also permits\nusing a stale cached response if a proxied server to process a request\ncannot be selected.\n
\nAdditionally, the updating parameter permits\nusing a stale cached response if it is currently being updated.\nThis allows minimizing the number of accesses to proxied servers\nwhen updating cached data.\n
\nUsing a stale cached response\ncan also be enabled directly in the response header\nfor a specified number of seconds after the response became stale (1.11.10).\nThis has lower priority than using the directive parameters.\n
\n
\nTo minimize the number of accesses to proxied servers when\npopulating a new cache element, the proxy_cache_lock\ndirective can be used.\n
| \n Syntax:\n | \n\n proxy_cache_valid [\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets caching time for different response codes.\nFor example, the following directives\n
\nproxy_cache_valid 200 302 10m;\nproxy_cache_valid 404 1m;\n
\nset 10 minutes of caching for responses with codes 200 and 302\nand 1 minute for responses with code 404.\n
\nIf only caching time is specified\n
\nproxy_cache_valid 5m;\n
\nthen only 200, 301, and 302 responses are cached.\n
\nIn addition, the any parameter can be specified\nto cache any responses:\n
\nproxy_cache_valid 200 302 10m;\nproxy_cache_valid 301 1h;\nproxy_cache_valid any 1m;\n
\n
\nParameters of caching can also be set directly\nin the response header.\nThis has higher priority than setting of caching time using the directive.\n
@ prefix, it sets an absolute\ntime in seconds since Epoch, up to which the response may be cached.\n*”, such a\nresponse will not be cached (1.7.7).\nIf the header includes the “Vary” field\nwith another value, such a response will be cached\ntaking into account the corresponding request header fields (1.7.7).\n\nProcessing of one or more of these response header fields can be disabled\nusing the proxy_ignore_headers directive.\n
| \n Syntax:\n | \n\n proxy_connect_timeout \n | \n
|---|---|
| \n Default:\n | \n\n proxy_connect_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a timeout for establishing a connection with a proxied server.\nIt should be noted that this timeout cannot usually exceed 75 seconds.\n
| \n Syntax:\n | \n\n proxy_cookie_domain proxy_cookie_domain \n | \n
|---|---|
| \n Default:\n | \n\n proxy_cookie_domain off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.15.\n
\nSets a text that should be changed in the domain\nattribute of the “Set-Cookie” header fields of a\nproxied server response.\nSuppose a proxied server returned the “Set-Cookie”\nheader field with the attribute\n“domain=localhost”.\nThe directive\n
\nproxy_cookie_domain localhost example.org;\n
\nwill rewrite this attribute to\n“domain=example.org”.\n
\nA dot at the beginning of the domain and\nreplacement strings and the domain\nattribute is ignored.\nMatching is case-insensitive.\n
\nThe domain and replacement strings\ncan contain variables:\n
\nproxy_cookie_domain www.$host $host;\n
\n
\nThe directive can also be specified using regular expressions.\nIn this case, domain should start from\nthe “~” symbol.\nA regular expression can contain named and positional captures,\nand replacement can reference them:\n
\nproxy_cookie_domain ~\\.(?P<sl_domain>[-0-9a-z]+\\.[a-z]+)$ $sl_domain;\n
\n
\nSeveral proxy_cookie_domain directives\ncan be specified on the same level:\n
\nproxy_cookie_domain localhost example.org;\nproxy_cookie_domain ~\\.([a-z]+\\.[a-z]+)$ $1;\n
\nIf several directives can be applied to the cookie,\nthe first matching directive will be chosen.\n
\nThe off parameter cancels the effect\nof the proxy_cookie_domain directives\ninherited from the previous configuration level.\n
| \n Syntax:\n | \n\n proxy_cookie_flags \n \n | \n
|---|---|
| \n Default:\n | \n\n proxy_cookie_flags off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.19.3.\n
\nSets one or more flags for the cookie.\nThe cookie can contain text, variables, and their combinations.\nThe flag\ncan contain text, variables, and their combinations (1.19.8).\nThe\nsecure,\nhttponly,\nsamesite=strict,\nsamesite=lax,\nsamesite=none\nparameters add the corresponding flags.\nThe\nnosecure,\nnohttponly,\nnosamesite\nparameters remove the corresponding flags.\n
\nThe cookie can also be specified using regular expressions.\nIn this case, cookie should start from\nthe “~” symbol.\n
\nSeveral proxy_cookie_flags directives\ncan be specified on the same configuration level:\n
\nproxy_cookie_flags one httponly;\nproxy_cookie_flags ~ nosecure samesite=strict;\n
\nIf several directives can be applied to the cookie,\nthe first matching directive will be chosen.\nIn the example, the httponly flag\nis added to the cookie one,\nfor all other cookies\nthe samesite=strict flag is added and\nthe secure flag is deleted.\n
\nThe off parameter cancels the effect\nof the proxy_cookie_flags directives\ninherited from the previous configuration level.\n
| \n Syntax:\n | \n\n proxy_cookie_path proxy_cookie_path \n | \n
|---|---|
| \n Default:\n | \n\n proxy_cookie_path off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.15.\n
\nSets a text that should be changed in the path\nattribute of the “Set-Cookie” header fields of a\nproxied server response.\nSuppose a proxied server returned the “Set-Cookie”\nheader field with the attribute\n“path=/two/some/uri/”.\nThe directive\n
\nproxy_cookie_path /two/ /;\n
\nwill rewrite this attribute to\n“path=/some/uri/”.\n
\nThe path and replacement strings\ncan contain variables:\n
\nproxy_cookie_path $uri /some$uri;\n
\n
\nThe directive can also be specified using regular expressions.\nIn this case, path should either start from\nthe “~” symbol for a case-sensitive matching,\nor from the “~*” symbols for case-insensitive\nmatching.\nThe regular expression can contain named and positional captures,\nand replacement can reference them:\n
\nproxy_cookie_path ~*^/user/([^/]+) /u/$1;\n
\n
\nSeveral proxy_cookie_path directives\ncan be specified on the same level:\n
\nproxy_cookie_path /one/ /;\nproxy_cookie_path / /two/;\n
\nIf several directives can be applied to the cookie,\nthe first matching directive will be chosen.\n
\nThe off parameter cancels the effect\nof the proxy_cookie_path directives\ninherited from the previous configuration level.\n
| \n Syntax:\n | \n\n proxy_force_ranges \n | \n
|---|---|
| \n Default:\n | \n\n proxy_force_ranges off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.7.\n
\nEnables byte-range support\nfor both cached and uncached responses from the proxied server\nregardless of the “Accept-Ranges” field in these responses.\n
| \n Syntax:\n | \n\n proxy_headers_hash_bucket_size \n | \n
|---|---|
| \n Default:\n | \n\n proxy_headers_hash_bucket_size 64;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the bucket size for hash tables\nused by the proxy_hide_header and proxy_set_header\ndirectives.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
| \n Syntax:\n | \n\n proxy_headers_hash_max_size \n | \n
|---|---|
| \n Default:\n | \n\n proxy_headers_hash_max_size 512;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the maximum size of hash tables\nused by the proxy_hide_header and proxy_set_header\ndirectives.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
| \n Syntax:\n | \n\n proxy_hide_header \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nBy default,\nnginx does not pass the header fields “Date”,\n“Server”, “X-Pad”, and\n“X-Accel-...” from the response of a proxied\nserver to a client.\nThe proxy_hide_header directive sets additional fields\nthat will not be passed.\nIf, on the contrary, the passing of fields needs to be permitted,\nthe proxy_pass_header directive can be used.\n
| \n Syntax:\n | \n\n proxy_http_version \n \n | \n
|---|---|
| \n Default:\n | \n\n proxy_http_version 1.1;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.4.\n
\nSets the HTTP protocol version for proxying.\nSince 1.29.7, version 1.1 is used by default.\nBefore 1.29.7, version 1.0 was used by default.\nVersion 1.1 or 2 (1.29.4) is recommended for use with\nkeepalive\nconnections and\nNTLM authentication.\n
\nVersion 2 requires the\nngx_http_v2_module module.\n
\n
| \n Syntax:\n | \n\n proxy_ignore_client_abort \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ignore_client_abort off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines whether the connection with a proxied server should be\nclosed when a client closes the connection without waiting\nfor a response.\n
| \n Syntax:\n | \n\n proxy_ignore_headers \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDisables processing of certain response header fields from the proxied server.\nThe following fields can be ignored: “X-Accel-Redirect”,\n“X-Accel-Expires”, “X-Accel-Limit-Rate” (1.1.6),\n“X-Accel-Buffering” (1.1.6),\n“X-Accel-Charset” (1.1.6), “Expires”,\n“Cache-Control”, “Set-Cookie” (0.8.44),\nand “Vary” (1.7.7).\n
\nIf not disabled, processing of these header fields has the following\neffect:\n
\n
| \n Syntax:\n | \n\n proxy_intercept_errors \n | \n
|---|---|
| \n Default:\n | \n\n proxy_intercept_errors off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines whether proxied responses with codes greater than or equal\nto 300 should be passed to a client\nor be intercepted and redirected to nginx for processing\nwith the error_page directive.\n
| \n Syntax:\n | \n\n proxy_limit_rate \n | \n
|---|---|
| \n Default:\n | \n\n proxy_limit_rate 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.7.\n
\nLimits the speed of reading the response from the proxied server.\nThe rate is specified in bytes per second.\nThe zero value disables rate limiting.\nThe limit is set per a request, and so if nginx simultaneously opens\ntwo connections to the proxied server,\nthe overall rate will be twice as much as the specified limit.\nThe limitation works only if\nbuffering of responses from the proxied\nserver is enabled.\nParameter value can contain variables (1.27.0).\n
| \n Syntax:\n | \n\n proxy_max_temp_file_size \n | \n
|---|---|
| \n Default:\n | \n\n proxy_max_temp_file_size 1024m;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nWhen buffering of responses from the proxied\nserver is enabled, and the whole response does not fit into the buffers\nset by the proxy_buffer_size and proxy_buffers\ndirectives, a part of the response can be saved to a temporary file.\nThis directive sets the maximum size of the temporary file.\nThe size of data written to the temporary file at a time is set\nby the proxy_temp_file_write_size directive.\n
\nThe zero value disables buffering of responses to temporary files.\n
\n
\nThis restriction does not apply to responses\nthat will be cached\nor stored on disk.\n
\n
| \n Syntax:\n | \n\n proxy_method \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies the HTTP method to use in requests forwarded\nto the proxied server instead of the method from the client request.\nParameter value can contain variables (1.11.6).\n
| \n Syntax:\n | \n\n proxy_next_upstream \n \n | \n
|---|---|
| \n Default:\n | \n\n proxy_next_upstream error timeout;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies in which cases a request should be passed to the next server:\n
errortimeoutdenied\n
\nThis parameter is available as part of our\ncommercial subscription.\n
\n
\ninvalid_headerhttp_500http_502http_503http_504http_403http_404http_429non_idempotentPOST, LOCK, PATCH)\nare not passed to the next server\nif a request has been sent to an upstream server (1.9.13);\nenabling this option explicitly allows retrying such requests;\noff\n
\nOne should bear in mind that passing a request to the next server is\nonly possible if nothing has been sent to a client yet.\nThat is, if an error or timeout occurs in the middle of the\ntransferring of a response, fixing this is impossible.\n
\nThe directive also defines what is considered an\nunsuccessful\nattempt of communication with a server.\nThe cases of error, timeout,\ndenied and\ninvalid_header are always considered unsuccessful attempts,\neven if they are not specified in the directive.\nThe cases of http_500, http_502,\nhttp_503, http_504,\nand http_429 are\nconsidered unsuccessful attempts only if they are specified in the directive.\nThe cases of http_403 and http_404\nare never considered unsuccessful attempts.\n
\nPassing a request to the next server can be limited by\nthe number of tries\nand by time.\n
| \n Syntax:\n | \n\n proxy_next_upstream_timeout \n | \n
|---|---|
| \n Default:\n | \n\n proxy_next_upstream_timeout 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.5.\n
\nLimits the time during which a request can be passed to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n proxy_next_upstream_tries \n | \n
|---|---|
| \n Default:\n | \n\n proxy_next_upstream_tries 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.5.\n
\nLimits the number of possible tries for passing a request to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n proxy_no_cache \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines conditions under which the response will not be saved to a cache.\nIf at least one value of the string parameters is not empty and is not\nequal to “0” then the response will not be saved:\n
\nproxy_no_cache $cookie_nocache $arg_nocache$arg_comment;\nproxy_no_cache $http_pragma $http_authorization;\n
\nCan be used along with the proxy_cache_bypass directive.\n
| \n Syntax:\n | \n\n proxy_pass \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location, if in location, limit_except\n | \n
\nSets the protocol and address of a proxied server and an optional URI\nto which a location should be mapped.\nAs a protocol, “http” or “https”\ncan be specified.\nThe address can be specified as a domain name or IP address,\nand an optional port:\n
\nproxy_pass http://localhost:8000/uri/;\n
\nor as a UNIX-domain socket path specified after the word\n“unix” and enclosed in colons:\n
\nproxy_pass http://unix:/tmp/backend.socket:/uri/;\n
\n
\nIf a domain name resolves to several addresses, all of them will be\nused in a round-robin fashion.\nIn addition, an address can be specified as a\nserver group.\n
\nParameter value can contain variables.\nIn this case, if an address is specified as a domain name,\nthe name is searched among the described server groups,\nand, if not found, is determined using a\nresolver.\n
\nA request URI is passed to the server as follows:\n
proxy_pass directive is specified with a URI,\nthen when a request is passed to the server, the part of a\nnormalized\nrequest URI matching the location is replaced by a URI\nspecified in the directive:\n\nlocation /name/ {\n proxy_pass http://127.0.0.1/remote/;\n}\n\nproxy_pass is specified without a URI,\nthe request URI is passed to the server in the same form\nas sent by a client when the original request is processed,\nor the full normalized request URI is passed\nwhen processing the changed URI:\n\nlocation /some/path/ {\n proxy_pass http://127.0.0.1;\n}\n\n\nBefore version 1.1.12,\nif proxy_pass is specified without a URI,\nthe original request URI might be passed\ninstead of the changed URI in some cases.\n\n\n
\nIn some cases, the part of a request URI to be replaced cannot be determined:\n
\nIn these cases,\nproxy_pass should be specified without a URI.\n
break):\n\nlocation /name/ {\n rewrite /name/([^/]+) /users?name=$1 break;\n proxy_pass http://127.0.0.1;\n}\n\n\nIn this case, the URI specified in the directive is ignored and\nthe full changed request URI is passed to the server.\n
\nproxy_pass:\n\nlocation /name/ {\n proxy_pass http://127.0.0.1$request_uri;\n}\n\nIn this case, if URI is specified in the directive,\nit is passed to the server as is,\nreplacing the original request URI.\n\n
\nWebSocket proxying requires special\nconfiguration and is supported since version 1.3.13.\n
| \n Syntax:\n | \n\n proxy_pass_header \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nPermits passing otherwise disabled header\nfields from a proxied server to a client.\n
| \n Syntax:\n | \n\n proxy_pass_request_body \n | \n
|---|---|
| \n Default:\n | \n\n proxy_pass_request_body on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIndicates whether the original request body is passed\nto the proxied server.\n
\nlocation /x-accel-redirect-here/ {\n proxy_method GET;\n proxy_pass_request_body off;\n proxy_set_header Content-Length \"\";\n\n proxy_pass ...\n}\n\nSee also the proxy_set_header and\nproxy_pass_request_headers directives.\n
| \n Syntax:\n | \n\n proxy_pass_request_headers \n | \n
|---|---|
| \n Default:\n | \n\n proxy_pass_request_headers on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIndicates whether the header fields of the original request are passed\nto the proxied server.\n
\nlocation /x-accel-redirect-here/ {\n proxy_method GET;\n proxy_pass_request_headers off;\n proxy_pass_request_body off;\n\n proxy_pass ...\n}\n\nSee also the proxy_set_header and\nproxy_pass_request_body directives.\n
| \n Syntax:\n | \n\n proxy_pass_trailers \n | \n
|---|---|
| \n Default:\n | \n\n proxy_pass_trailers off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.27.2.\n
\nPermits passing trailer fields from a proxied server to a client.\n
\n
\nA trailer section should be\nexplicitly enabled:\n
\n
\nlocation / {\n # proxy_http_version 1.1; #for versions before 1.29.7\n proxy_set_header Connection \"te\";\n proxy_set_header TE \"trailers\";\n proxy_pass_trailers on;\n\n proxy_pass ...\n}\n\n
| \n Syntax:\n | \n\n proxy_read_timeout \n | \n
|---|---|
| \n Default:\n | \n\n proxy_read_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a timeout for reading a response from the proxied server.\nThe timeout is set only between two successive read operations,\nnot for the transmission of the whole response.\nIf the proxied server does not transmit anything within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n proxy_redirect proxy_redirect proxy_redirect \n | \n
|---|---|
| \n Default:\n | \n\n proxy_redirect default;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the text that should be changed in the “Location”\nand “Refresh” header fields of a proxied server response.\nSuppose a proxied server returned the header field\n“Location: http://localhost:8000/two/some/uri/”.\nThe directive\n
\nproxy_redirect http://localhost:8000/two/ http://frontend/one/;\n
\nwill rewrite this string to\n“Location: http://frontend/one/some/uri/”.\n
\nA server name may be omitted in the replacement string:\n
\nproxy_redirect http://localhost:8000/two/ /;\n
\nthen the primary server’s name and port, if different from 80,\nwill be inserted.\n
\nThe default replacement specified by the default parameter\nuses the parameters of the\nlocation and\nproxy_pass directives.\nHence, the two configurations below are equivalent:\n
\nlocation /one/ {\n proxy_pass http://upstream:port/two/;\n proxy_redirect default;\n\n\n
\nlocation /one/ {\n proxy_pass http://upstream:port/two/;\n proxy_redirect http://upstream:port/two/ /one/;\n \nThe default parameter is not permitted if\nproxy_pass is specified using variables.\n
\nA replacement string can contain variables:\n
\nproxy_redirect http://localhost:8000/ http://$host:$server_port/;\n
\n
\nA redirect can also contain (1.1.11) variables:\n
\nproxy_redirect http://$proxy_host:8000/ /;\n
\n
\nThe directive can be specified (1.1.11) using regular expressions.\nIn this case, redirect should either start with\nthe “~” symbol for a case-sensitive matching,\nor with the “~*” symbols for case-insensitive\nmatching.\nThe regular expression can contain named and positional captures,\nand replacement can reference them:\n
\nproxy_redirect ~^(http://[^:]+):\\d+(/.+)$ $1$2;\nproxy_redirect ~*/user/([^/]+)/(.+)$ http://$1.example.com/$2;\n
\n
\nSeveral proxy_redirect directives\ncan be specified on the same level:\n
\nproxy_redirect default;\nproxy_redirect http://localhost:8000/ /;\nproxy_redirect http://www.example.com/ /;\n
\nIf several directives can be applied to\nthe header fields of a proxied server response,\nthe first matching directive will be chosen.\n
\nThe off parameter cancels the effect\nof the proxy_redirect directives\ninherited from the previous configuration level.\n
\nUsing this directive, it is also possible to add host names to relative\nredirects issued by a proxied server:\n
\nproxy_redirect / /;\n
\n
| \n Syntax:\n | \n\n proxy_request_buffering \n | \n
|---|---|
| \n Default:\n | \n\n proxy_request_buffering on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.11.\n
\nEnables or disables buffering of a client request body.\n
\nWhen buffering is enabled, the entire request body is\nread\nfrom the client before sending the request to a proxied server.\n
\nWhen buffering is disabled, the request body is sent to the proxied server\nimmediately as it is received.\nIn this case, the request cannot be passed to the\nnext server\nif nginx already started sending the request body.\n
\nWhen HTTP/1.1 chunked transfer encoding is used\nto send the original request body,\nthe request body will be buffered regardless of the directive value unless\nHTTP/1.1 or HTTP/2 is enabled for proxying.\n
| \n Syntax:\n | \n\n proxy_request_dynamic \n | \n
|---|---|
| \n Default:\n | \n\n proxy_request_dynamic off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nEnables or disables creation of a separate request instance\nfor each proxied server.\nBy default, a single request is used for all proxied servers.\nIf enabled, a separate request instance is created,\nallowing per-server request customization.\nFor example, the server-specific “Host” request header field\ncan be set:\n
\nproxy_request_dynamic on;\nproxy_set_header Host $upstream_last_server_name;\n
\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n proxy_send_lowat \n | \n
|---|---|
| \n Default:\n | \n\n proxy_send_lowat 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIf the directive is set to a non-zero value, nginx will try to\nminimize the number\nof send operations on outgoing connections to a proxied server by using either\nNOTE_LOWAT flag of the\nkqueue method,\nor the SO_SNDLOWAT socket option,\nwith the specified size.\n
\nThis directive is ignored on Linux, Solaris, and Windows.\n
| \n Syntax:\n | \n\n proxy_send_timeout \n | \n
|---|---|
| \n Default:\n | \n\n proxy_send_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a timeout for transmitting a request to the proxied server.\nThe timeout is set only between two successive write operations,\nnot for the transmission of the whole request.\nIf the proxied server does not receive anything within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n proxy_set_body \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nAllows redefining the request body passed to the proxied server.\nThe value can contain text, variables, and their combination.\n
| \n Syntax:\n | \n\n proxy_set_header \n | \n
|---|---|
| \n Default:\n | \n\n proxy_set_header Host $proxy_host; proxy_set_header Connection close;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nAllows redefining or appending fields to the request header\npassed to the proxied server.\nThe value can contain text, variables, and their combinations.\nThese directives are inherited from the previous configuration level\nif and only if there are no proxy_set_header directives\ndefined on the current level.\n
\nBy default, the header fields\n“Host”\nand\n“Connection”\nfrom the original request are not passed to the proxied server.\nIf HTTP/1.0 or HTTP/1.1 is\nenabled for proxying,\nthese fields are redefined:\n
\nproxy_set_header Host $proxy_host;\nproxy_set_header Connection close;\n
\nFor HTTP/2, the\n“:authority”\npseudo-header field with the\n$proxy_host\nvalue is sent by default,\nunless it is replaced with an explicit “Host” header field.\n
\nIf caching is enabled, the header fields\n“If-Modified-Since”,\n“If-Unmodified-Since”,\n“If-None-Match”,\n“If-Match”,\n“Range”,\nand\n“If-Range”\nfrom the original request are not passed to the proxied server.\n
\nAn unchanged “Host” request header field can be passed like this:\n
\nproxy_set_header Host $http_host;\n
\n
\nHowever, if this field is not present in a client request header then\nnothing will be passed.\nIn such a case it is better to use the $host variable - its\nvalue equals the server name in the “Host” request header\nfield or the primary server name if this field is not present:\n
\nproxy_set_header Host $host;\n
\n
\nIn addition, the server name can be passed together with the port of the\nproxied server:\n
\nproxy_set_header Host $host:$proxy_port;\n
\n
\nIf the value of a header field is an empty string then this\nfield will not be passed to a proxied server:\n
\nproxy_set_header Accept-Encoding \"\";\n
\n
| \n Syntax:\n | \n\n proxy_socket_keepalive \n | \n
|---|---|
| \n Default:\n | \n\n proxy_socket_keepalive off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.15.6.\n
\nConfigures the “TCP keepalive” behavior\nfor outgoing connections to a proxied server.\nBy default, the operating system’s settings are in effect for the socket.\nIf the directive is set to the value “on”, the\nSO_KEEPALIVE socket option is turned on for the socket.\n
| \n Syntax:\n | \n\n proxy_ssl_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.8.\n
\nSpecifies a file with the certificate in the PEM format\nused for authentication to a proxied HTTPS server.\n
\nSince version 1.21.0, variables can be used in the file name.\n
| \n Syntax:\n | \n\n proxy_ssl_certificate_cache proxy_ssl_certificate_cache \n \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_certificate_cache off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.27.4.\n
\nDefines a cache that stores\nSSL certificates and\nsecret keys\nspecified with variables.\n
\nThe directive has the following parameters:\n
max\ninactive\nvalid\noff\n\n
\nExample:\n
\nproxy_ssl_certificate $proxy_ssl_server_name.crt;\nproxy_ssl_certificate_key $proxy_ssl_server_name.key;\nproxy_ssl_certificate_cache max=1000 inactive=20s valid=1m;\n
\n
| \n Syntax:\n | \n\n proxy_ssl_certificate_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.8.\n
\nSpecifies a file with the secret key in the PEM format\nused for authentication to a proxied HTTPS server.\n
\nThe value\nengine:name:id\ncan be specified instead of the file (1.7.9),\nwhich loads a secret key with a specified id\nfrom the OpenSSL engine name.\n
\nThe value\nstore:scheme:id\ncan be specified instead of the file (1.29.0),\nwhich is used to load a secret key with a specified id\nand OpenSSL provider registered URI scheme, such as\npkcs11.\n
\nSince version 1.21.0, variables can be used in the file name.\n
| \n Syntax:\n | \n\n proxy_ssl_ciphers \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_ciphers DEFAULT;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.6.\n
\nSpecifies the enabled ciphers for requests to a proxied HTTPS server.\nThe ciphers are specified in the format understood by the OpenSSL library.\n
\nThe full list can be viewed using the\n“openssl ciphers” command.\n
| \n Syntax:\n | \n\n proxy_ssl_conf_command \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.19.4.\n
\nSets arbitrary OpenSSL configuration\ncommands\nwhen establishing a connection with the proxied HTTPS server.\n
\nThe directive is supported when using OpenSSL 1.0.2 or higher.\n
\n
\nSeveral proxy_ssl_conf_command directives\ncan be specified on the same level.\nThese directives are inherited from the previous configuration level\nif and only if there are\nno proxy_ssl_conf_command directives\ndefined on the current level.\n
\n
\nNote that configuring OpenSSL directly\nmight result in unexpected behavior.\n
\n
| \n Syntax:\n | \n\n proxy_ssl_crl \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.0.\n
\nSpecifies a file with revoked certificates (CRL)\nin the PEM format used to verify\nthe certificate of the proxied HTTPS server.\nWhen using intermediate certificates, their CRLs should be\nspecified in the same file.\n
| \n Syntax:\n | \n\n proxy_ssl_key_log path;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.27.2.\n
\nEnables logging of proxied HTTPS server connection SSL keys\nand specifies the path to the key log file.\nKeys are logged in the\nSSLKEYLOGFILE\nformat compatible with Wireshark.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n proxy_ssl_name \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_name $proxy_host;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.0.\n
\nAllows overriding the server name used to\nverify\nthe certificate of the proxied HTTPS server and to be\npassed through SNI\nwhen establishing a connection with the proxied HTTPS server.\n
\nBy default, the host part of the proxy_pass URL is used.\n
| \n Syntax:\n | \n\n proxy_ssl_password_file \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.8.\n
\nSpecifies a file with passphrases for\nsecret keys\nwhere each passphrase is specified on a separate line.\nPassphrases are tried in turn when loading the key.\n
| \n Syntax:\n | \n\n proxy_ssl_protocols \n [\n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_protocols TLSv1.2 TLSv1.3;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.6.\n
\nEnables the specified protocols for requests to a proxied HTTPS server.\n
\n
\nThe TLSv1.3 parameter is used by default\nsince 1.23.4.\n\n
| \n Syntax:\n | \n\n proxy_ssl_server_name \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_server_name off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.0.\n
\nEnables or disables passing of the server name through\nTLS\nServer Name Indication extension (SNI, RFC 6066)\nwhen establishing a connection with the proxied HTTPS server.\n
| \n Syntax:\n | \n\n proxy_ssl_session_reuse \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_session_reuse on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines whether SSL sessions can be reused when working with\nthe proxied server.\nIf the errors\n“digest check failed”\nappear in the logs, try disabling session reuse.\n
| \n Syntax:\n | \n\n proxy_ssl_trusted_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.0.\n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to verify\nthe certificate of the proxied HTTPS server.\n
| \n Syntax:\n | \n\n proxy_ssl_verify \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_verify off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.0.\n
\nEnables or disables verification of the proxied HTTPS server certificate.\n
| \n Syntax:\n | \n\n proxy_ssl_verify_depth \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_verify_depth 1;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.0.\n
\nSets the verification depth in the proxied HTTPS server certificates chain.\n
| \n Syntax:\n | \n\n proxy_store \n \n | \n
|---|---|
| \n Default:\n | \n\n proxy_store off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables saving of files to a disk.\nThe on parameter saves files with paths\ncorresponding to the directives\nalias or\nroot.\nThe off parameter disables saving of files.\nIn addition, the file name can be set explicitly using the\nstring with variables:\n
\nproxy_store /data/www$original_uri;\n
\n
\nThe modification time of files is set according to the received\n“Last-Modified” response header field.\nThe response is first written to a temporary file,\nand then the file is renamed.\nStarting from version 0.8.9, temporary files and the persistent store\ncan be put on different file systems.\nHowever, be aware that in this case a file is copied\nacross two file systems instead of the cheap renaming operation.\nIt is thus recommended that for any given location both saved files and a\ndirectory holding temporary files, set by the proxy_temp_path\ndirective, are put on the same file system.\n
\nThis directive can be used to create local copies of static unchangeable\nfiles, e.g.:\n
\nlocation /images/ {\n root /data/www;\n error_page 404 = /fetch$uri;\n}\n\nlocation /fetch/ {\n internal;\n\n proxy_pass http://backend/;\n proxy_store on;\n proxy_store_access user:rw group:rw all:r;\n proxy_temp_path /data/temp;\n\n alias /data/www/;\n}\n\n
\nor like this:\n
\nlocation /images/ {\n root /data/www;\n error_page 404 = @fetch;\n}\n\nlocation @fetch {\n internal;\n\n proxy_pass http://backend;\n proxy_store on;\n proxy_store_access user:rw group:rw all:r;\n proxy_temp_path /data/temp;\n\n root /data/www;\n}\n\n
| \n Syntax:\n | \n\n proxy_store_access \n | \n
|---|---|
| \n Default:\n | \n\n proxy_store_access user:rw;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets access permissions for newly created files and directories, e.g.:\n
\nproxy_store_access user:rw group:rw all:r;\n
\n
\nIf any group or all access permissions\nare specified then user permissions may be omitted:\n
\nproxy_store_access group:rw all:r;\n
\n
| \n Syntax:\n | \n\n proxy_temp_file_write_size \n | \n
|---|---|
| \n Default:\n | \n\n proxy_temp_file_write_size 8k|16k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nLimits the size of data written to a temporary file\nat a time, when buffering of responses from the proxied server\nto temporary files is enabled.\nBy default, size is limited by two buffers set by the\nproxy_buffer_size and proxy_buffers directives.\nThe maximum size of a temporary file is set by the\nproxy_max_temp_file_size directive.\n
| \n Syntax:\n | \n\n proxy_temp_path \n \n | \n
|---|---|
| \n Default:\n | \n\n proxy_temp_path proxy_temp;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a directory for storing temporary files\nwith data received from proxied servers.\nUp to three-level subdirectory hierarchy can be used underneath the specified\ndirectory.\nFor example, in the following configuration\n
\nproxy_temp_path /spool/nginx/proxy_temp 1 2;\n
\na temporary file might look like this:\n
\n/spool/nginx/proxy_temp/7/45/00000123457\n
\n
\nSee also the use_temp_path parameter of the\nproxy_cache_path directive.\n
\nThe ngx_http_proxy_module module supports embedded variables\nthat can be used to compose headers using the\nproxy_set_header directive:\n
$proxy_host$proxy_port$proxy_add_x_forwarded_for$remote_addr variable appended to it, separated by a comma.\nIf the “X-Forwarded-For” field is not present in the client\nrequest header, the $proxy_add_x_forwarded_for variable is equal\nto the $remote_addr variable.\n
\n\n| Example Configuration Embedded Variables |
\nThe ngx_http_proxy_protocol_vendor_module module (1.23.3)\nallows obtaining additional information about a connection in\ncloud platforms from application-specific TLVs of the\nPROXY\nprotocol\nheader.\n
\nSupported cloud platforms:\n
\n
\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nproxy_set_header X-Conn-ID $proxy_protocol_tlv_gcp_conn_id;\n\nserver {\n listen 80 proxy_protocol;\n listen 443 ssl proxy_protocol;\n ...\n}\n\n
\n\n\n\n
$proxy_protocol_tlv_aws_vpce_id$proxy_protocol_tlv_azure_pel_id$proxy_protocol_tlv_gcp_conn_id\n
\n\n| Example Configuration Directives random_index |
\nThe ngx_http_random_index_module module processes requests\nending with the slash character (‘/’) and picks a random\nfile in a directory to serve as an index file.\nThe module is processed before the\nngx_http_index_module\nmodule.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_random_index_module\nconfiguration parameter.\n
\n
\nlocation / {\n random_index on;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n random_index \n | \n
|---|---|
| \n Default:\n | \n\n random_index off;\n | \n
| \n Context:\n | \n\n location\n | \n
\nEnables or disables module processing in a surrounding location.\n
\n\n| Example Configuration Directives set_real_ip_from real_ip_header real_ip_recursive Embedded Variables |
\nThe ngx_http_realip_module module is used\nto change the client address and optional port\nto those sent in the specified header field.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_realip_module\nconfiguration parameter.\n
\n
\nset_real_ip_from 192.168.1.0/24;\nset_real_ip_from 192.168.2.1;\nset_real_ip_from 2001:0db8::/32;\nreal_ip_header X-Forwarded-For;\nreal_ip_recursive on;\n
\n
\n\n\n| \n Syntax:\n | \n\n set_real_ip_from \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines trusted addresses that are known to send correct\nreplacement addresses.\nIf the special value unix: is specified,\nall UNIX-domain sockets will be trusted.\nTrusted addresses may also be specified using a hostname (1.13.1).\n
\nIPv6 addresses are supported starting from versions 1.3.0 and 1.2.1.\n
\n
| \n Syntax:\n | \n\n real_ip_header \n \n | \n
|---|---|
| \n Default:\n | \n\n real_ip_header X-Real-IP;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines the request header field\nwhose value will be used to replace the client address.\n
\nThe request header field value that contains an optional port\nis also used to replace the client port (1.11.0).\nThe address and port should be specified according to\nRFC 3986.\n
\nThe proxy_protocol parameter (1.5.12) changes\nthe client address to the one from the PROXY protocol header.\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
| \n Syntax:\n | \n\n real_ip_recursive \n | \n
|---|---|
| \n Default:\n | \n\n real_ip_recursive off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\n This directive appeared in versions 1.3.0 and 1.2.1.\n \n
\n\nIf recursive search is disabled, the original client address that\nmatches one of the trusted addresses is replaced by the last\naddress sent in the request header field defined by the\nreal_ip_header directive.\nIf recursive search is enabled, the original client address that\nmatches one of the trusted addresses is replaced by the last\nnon-trusted address sent in the request header field.\n
\n\n\n\n
$realip_remote_addr$realip_remote_port\n
\n\n| Example Configuration Directives referer_hash_bucket_size referer_hash_max_size valid_referers Embedded Variables |
\nThe ngx_http_referer_module module is used to block\naccess to a site for requests with invalid values in the\n“Referer” header field.\nIt should be kept in mind that fabricating a request with an appropriate\n“Referer” field value is quite easy, and so the intended\npurpose of this module is not to block such requests thoroughly but to block\nthe mass flow of requests sent by regular browsers.\nIt should also be taken into consideration that regular browsers may\nnot send the “Referer” field even for valid requests.\n
\n
\nvalid_referers none blocked server_names\n *.example.com example.* www.example.org/galleries/\n ~\\.google\\.;\n\nif ($invalid_referer) {\n return 403;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n referer_hash_bucket_size \n | \n
|---|---|
| \n Default:\n | \n\n referer_hash_bucket_size 64;\n | \n
| \n Context:\n | \n\n server, location\n | \n
This directive appeared in version 1.0.5.\n
\nSets the bucket size for the valid referers hash tables.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
| \n Syntax:\n | \n\n referer_hash_max_size \n | \n
|---|---|
| \n Default:\n | \n\n referer_hash_max_size 2048;\n | \n
| \n Context:\n | \n\n server, location\n | \n
This directive appeared in version 1.0.5.\n
\nSets the maximum size of the valid referers hash tables.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
| \n Syntax:\n | \n\n valid_referers \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server, location\n | \n
\nSpecifies the “Referer” request header field values\nthat will cause the embedded $invalid_referer variable to\nbe set to an empty string.\nOtherwise, the variable will be set to “1”.\nSearch for a match is case-insensitive.\n
\nParameters can be as follows:\n
noneblockedhttp://” or “https://”;\nserver_names*” at the beginning or end.\nDuring the checking, the server’s port in the “Referer” field\nis ignored;\n~”.\nIt should be noted that an expression will be matched against\nthe text starting after the “http://”\nor “https://”.\n\n
\nExample:\n
\nvalid_referers none blocked server_names\n *.example.com example.* www.example.org/galleries/\n ~\\.google\\.;\n
\n
\n\n\n\n
$invalid_referer1”.\n\n
\n\n| Directives break if return rewrite rewrite_log set uninitialized_variable_warn Internal Implementation |
\nThe ngx_http_rewrite_module module is used to\nchange request URI using PCRE regular expressions, return redirects, and\nconditionally select configurations.\n
\nThe break, if, return,\nrewrite, and set directives are\nprocessed in the following order:\n
\n
\n\n\n| \n Syntax:\n | \n\n break;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server, location, if\n | \n
\nStops processing the current set of\nngx_http_rewrite_module directives.\n
\nIf a directive is specified inside the\nlocation,\nfurther processing of the request continues in this location.\n
\nExample:\n
\nif ($slow) {\n limit_rate 10k;\n break;\n}\n\n
| \n Syntax:\n | \n\n if (\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server, location\n | \n
\nThe specified condition is evaluated.\nIf true, this module directives specified inside the braces are\nexecuted, and the request is assigned the configuration inside the\nif directive.\nConfigurations inside the if directives are\ninherited from the previous configuration level.\n
\nA condition may be any of the following:\n
0”;\n\nBefore version 1.0.1, any string starting with “0”\nwas considered a false value.\n\n=” and “!=” operators;\n~” (for case-sensitive matching) and\n“~*” (for case-insensitive matching) operators.\nRegular expressions can contain captures that are made available for\nlater reuse in the $1..$9 variables.\nNegative operators “!~” and “!~*”\nare also available.\nIf a regular expression includes the “}”\nor “;” characters, the whole expressions should be enclosed\nin single or double quotes.\n-f” and\n“!-f” operators;\n-d” and\n“!-d” operators;\n-e” and “!-e” operators;\n-x”\nand “!-x” operators.\n\n
\nExamples:\n
\nif ($http_user_agent ~ MSIE) {\n rewrite ^(.*)$ /msie/$1 break;\n}\n\nif ($http_cookie ~* \"id=([^;]+)(?:;|$)\") {\n set $id $1;\n}\n\nif ($request_method = POST) {\n return 405;\n}\n\nif ($slow) {\n limit_rate 10k;\n}\n\nif ($invalid_referer) {\n return 403;\n}\n\n
\nA value of the $invalid_referer embedded variable is set by the\nvalid_referers directive.\n\n
| \n Syntax:\n | \n\n return return return \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server, location, if\n | \n
\nStops processing and returns the specified code to a client.\nThe non-standard code 444 closes a connection without sending\na response header.\n
\nStarting from version 0.8.42, it is possible to specify\neither a redirect URL (for codes 301, 302, 303, 307, and 308)\nor the response body text (for other codes).\nA response body text and redirect URL can contain variables.\nAs a special case, a redirect URL can be specified as a URI\nlocal to this server, in which case the full redirect URL\nis formed according to the request scheme ($scheme) and the\nserver_name_in_redirect and\nport_in_redirect directives.\n
\nIn addition, a URL for temporary redirect with the code 302\ncan be specified as the sole parameter.\nSuch a parameter should start with the “http://”,\n“https://”, or “$scheme” string.\nA URL can contain variables.\n
\n
\nOnly the following codes could be returned before version 0.7.51:\n204, 400, 402 — 406, 408, 410, 411, 413, 416, and 500 — 504.\n
\n\n
\nThe code 307 was not treated as a redirect until versions 1.1.16 and 1.0.13.\n
\n\n
\nThe code 308 was not treated as a redirect until version 1.13.0.\n
\n
\nSee also the error_page directive.\n
| \n Syntax:\n | \n\n rewrite \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server, location, if\n | \n
\nIf the specified regular expression matches a request URI, URI is changed\nas specified in the replacement string.\nThe rewrite directives are executed sequentially\nin order of their appearance in the configuration file.\nIt is possible to terminate further processing of the directives using flags.\nIf a replacement string starts with “http://”,\n“https://”, or “$scheme”,\nthe processing stops and the redirect is returned to a client.\n
\nAn optional flag parameter can be one of:\n
lastngx_http_rewrite_module directives and starts\na search for a new location matching the changed URI;\nbreakngx_http_rewrite_module directives\nas with the break directive;\nredirecthttp://”, “https://”,\nor “$scheme”;\npermanent \nThe full redirect URL is formed according to the\nrequest scheme ($scheme) and the\nserver_name_in_redirect and\nport_in_redirect directives.\n
\nExample:\n
\nserver {\n ...\n rewrite ^(/download/.*)/media/(.*)\\..*$ $1/mp3/$2.mp3 last;\n rewrite ^(/download/.*)/audio/(.*)\\..*$ $1/mp3/$2.ra last;\n return 403;\n ...\n}\n\n
\nBut if these directives are put inside the “/download/”\nlocation, the last flag should be replaced by\nbreak, or otherwise nginx will make 10 cycles and\nreturn the 500 error:\n
\nlocation /download/ {\n rewrite ^(/download/.*)/media/(.*)\\..*$ $1/mp3/$2.mp3 break;\n rewrite ^(/download/.*)/audio/(.*)\\..*$ $1/mp3/$2.ra break;\n return 403;\n}\n\n
\nIf a replacement string includes the new request arguments,\nthe previous request arguments are appended after them.\nIf this is undesired, putting a question mark at the end of a replacement\nstring avoids having them appended, for example:\n
\nrewrite ^/users/(.*)$ /show?user=$1? last;\n
\n
\nIf a regular expression includes the “}”\nor “;” characters, the whole expressions should be enclosed\nin single or double quotes.\n
| \n Syntax:\n | \n\n rewrite_log \n | \n
|---|---|
| \n Default:\n | \n\n rewrite_log off;\n | \n
| \n Context:\n | \n\n http, server, location, if\n | \n
\nEnables or disables logging of ngx_http_rewrite_module\nmodule directives processing results\ninto the error_log at\nthe notice level.\n
| \n Syntax:\n | \n\n set \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server, location, if\n | \n
\nSets a value for the specified variable.\nThe value can contain text, variables, and their combination.\n
| \n Syntax:\n | \n\n uninitialized_variable_warn \n | \n
|---|---|
| \n Default:\n | \n\n uninitialized_variable_warn on;\n | \n
| \n Context:\n | \n\n http, server, location, if\n | \n
\nControls whether warnings about uninitialized variables are logged.\n
\n\n\n\nThe ngx_http_rewrite_module module directives\nare compiled at the configuration stage into internal instructions\nthat are interpreted during request processing.\nAn interpreter is a simple virtual stack machine.\n
\nFor example, the directives\n
\nlocation /download/ {\n if ($forbidden) {\n return 403;\n }\n\n if ($slow) {\n limit_rate 10k;\n }\n\n rewrite ^/(download/.*)/media/(.*)\\..*$ /$1/mp3/$2.mp3 break;\n}\n\nwill be translated into these instructions:\n
\nvariable $forbidden\ncheck against zero\n return 403\n end of code\nvariable $slow\ncheck against zero\nmatch of regular expression\ncopy \"/\"\ncopy $1\ncopy \"/mp3/\"\ncopy $2\ncopy \".mp3\"\nend of regular expression\nend of code\n
\n
\nNote that there are no instructions for the\nlimit_rate\ndirective above as it is unrelated to the\nngx_http_rewrite_module module.\nA separate configuration is created for the if block.\nIf the condition holds true, a request is assigned this configuration\nwhere limit_rate equals to 10k.\n
\nThe directive\n
\nrewrite ^/(download/.*)/media/(.*)\\..*$ /$1/mp3/$2.mp3 break;\n
\ncan be made smaller by one instruction if the first slash in the regular expression\nis put inside the parentheses:\n
\nrewrite ^(/download/.*)/media/(.*)\\..*$ $1/mp3/$2.mp3 break;\n
\nThe corresponding instructions will then look like this:\n
\nmatch of regular expression\ncopy $1\ncopy \"/mp3/\"\ncopy $2\ncopy \".mp3\"\nend of regular expression\nend of code\n
\n
\n\n\nThe ngx_http_scgi_module module allows passing\nrequests to an SCGI server.\n
\n
\nlocation / {\n include scgi_params;\n scgi_pass localhost:9000;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n scgi_allow_upstream \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nDefines conditions under which access to an SCGI server\nis allowed or denied.\nIf all string parameters are not empty\nand not equal to “0” then the access is allowed.\nThe conditions are evaluated each time\nbefore a connection to an SCGI server is established.\nParameter values can contain variables:\n
\ngeo $upstream_last_addr $allow {\n volatile;\n 10.10.0.0/24 1;\n}\n\nserver {\n listen 127.0.0.1:8080;\n\n location / {\n scgi_pass localhost:9000;\n scgi_allow_upstream $allow;\n ...\n }\n}\n\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n scgi_bind \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nMakes outgoing connections to an SCGI server originate\nfrom the specified local IP address with an optional port (1.11.2).\nParameter value can contain variables (1.3.12).\nThe special value off (1.3.12) cancels the effect\nof the scgi_bind directive\ninherited from the previous configuration level, which allows the\nsystem to auto-assign the local IP address and port.\n
\nThe transparent parameter (1.11.0) allows\noutgoing connections to an SCGI server originate\nfrom a non-local IP address,\nfor example, from a real IP address of a client:\n
\nscgi_bind $remote_addr transparent;\n
\nIn order for this parameter to work,\nit is usually necessary to run nginx worker processes with the\nsuperuser privileges.\nOn Linux it is not required (1.13.8) as if\nthe transparent parameter is specified, worker processes\ninherit the CAP_NET_RAW capability from the master process.\nIt is also necessary to configure kernel routing table\nto intercept network traffic from the SCGI server.\n
| \n Syntax:\n | \n\n scgi_bind_dynamic \n | \n
|---|---|
| \n Default:\n | \n\n scgi_bind_dynamic off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nWhen enabled, makes the bind operation\nat each connection attempt.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n scgi_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n scgi_buffer_size 4k|8k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the size of the buffer used for reading the first part\nof the response received from the SCGI server.\nThis part usually contains a small response header;\nif it exceeds the buffer size, the response is considered\ninvalid.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\nIt can be made smaller, however.\n
| \n Syntax:\n | \n\n scgi_buffering \n | \n
|---|---|
| \n Default:\n | \n\n scgi_buffering on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables buffering of responses from the SCGI server.\n
\nWhen buffering is enabled, nginx receives a response from the SCGI server\nas soon as possible, saving it into the buffers set by the\nscgi_buffer_size and scgi_buffers directives.\nIf the whole response does not fit into memory, a part of it can be saved\nto a temporary file on the disk.\nWriting to temporary files is controlled by the\nscgi_max_temp_file_size and\nscgi_temp_file_write_size directives.\n
\nWhen buffering is disabled, the response is passed to a client synchronously,\nimmediately as it is received.\nnginx will not try to read the whole response from the SCGI server.\nThe maximum size of the data that nginx can receive from the server\nat a time is set by the scgi_buffer_size directive.\n
\nBuffering can also be enabled or disabled by passing\n“yes” or “no” in the\n“X-Accel-Buffering” response header field.\nThis capability can be disabled using the\nscgi_ignore_headers directive.\n
| \n Syntax:\n | \n\n scgi_buffers \n | \n
|---|---|
| \n Default:\n | \n\n scgi_buffers 8 4k|8k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the number and size of the\nbuffers used for reading a response from the SCGI server,\nfor a single connection.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\n
| \n Syntax:\n | \n\n scgi_busy_buffers_size \n | \n
|---|---|
| \n Default:\n | \n\n scgi_busy_buffers_size 8k|16k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nWhen buffering of responses from the SCGI\nserver is enabled, limits the total size of buffers that\ncan be busy sending a response to the client while the response is not\nyet fully read.\nIn the meantime, the rest of the buffers can be used for reading the response\nand, if needed, buffering part of the response to a temporary file.\nBy default, size is limited by the size of two buffers set by the\nscgi_buffer_size and scgi_buffers directives.\n
| \n Syntax:\n | \n\n scgi_cache \n | \n
|---|---|
| \n Default:\n | \n\n scgi_cache off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a shared memory zone used for caching.\nThe same zone can be used in several places.\nParameter value can contain variables (1.7.9).\nThe off parameter disables caching inherited\nfrom the previous configuration level.\n
| \n Syntax:\n | \n\n scgi_cache_background_update \n | \n
|---|---|
| \n Default:\n | \n\n scgi_cache_background_update off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.11.10.\n
\nAllows starting a background subrequest\nto update an expired cache item,\nwhile a stale cached response is returned to the client.\nNote that it is necessary to\nallow\nthe usage of a stale cached response when it is being updated.\n
| \n Syntax:\n | \n\n scgi_cache_bypass \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines conditions under which the response will not be taken from a cache.\nIf at least one value of the string parameters is not empty and is not\nequal to “0” then the response will not be taken from the cache:\n
\nscgi_cache_bypass $cookie_nocache $arg_nocache$arg_comment;\nscgi_cache_bypass $http_pragma $http_authorization;\n
\nCan be used along with the scgi_no_cache directive.\n
| \n Syntax:\n | \n\n scgi_cache_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a key for caching, for example\n
\nscgi_cache_key localhost:9000$request_uri;\n
\n
| \n Syntax:\n | \n\n scgi_cache_lock \n | \n
|---|---|
| \n Default:\n | \n\n scgi_cache_lock off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.12.\n
\nWhen enabled, only one request at a time will be allowed to populate\na new cache element identified according to the scgi_cache_key\ndirective by passing a request to an SCGI server.\nOther requests of the same cache element will either wait\nfor a response to appear in the cache or the cache lock for\nthis element to be released, up to the time set by the\nscgi_cache_lock_timeout directive.\n
| \n Syntax:\n | \n\n scgi_cache_lock_age \n | \n
|---|---|
| \n Default:\n | \n\n scgi_cache_lock_age 5s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.8.\n
\nIf the last request passed to the SCGI server\nfor populating a new cache element\nhas not completed for the specified time,\none more request may be passed to the SCGI server.\n
| \n Syntax:\n | \n\n scgi_cache_lock_timeout \n | \n
|---|---|
| \n Default:\n | \n\n scgi_cache_lock_timeout 5s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.12.\n
\nSets a timeout for scgi_cache_lock.\nWhen the time expires,\nthe request will be passed to the SCGI server,\nhowever, the response will not be cached.\n
\nBefore 1.7.8, the response could be cached.\n
\n
| \n Syntax:\n | \n\n scgi_cache_max_range_offset \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.11.6.\n
\nSets an offset in bytes for byte-range requests.\nIf the range is beyond the offset,\nthe range request will be passed to the SCGI server\nand the response will not be cached.\n
| \n Syntax:\n | \n\n scgi_cache_methods \n \n | \n
|---|---|
| \n Default:\n | \n\n scgi_cache_methods GET HEAD;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIf the client request method is listed in this directive then\nthe response will be cached.\n“GET” and “HEAD” methods are always\nadded to the list, though it is recommended to specify them explicitly.\nSee also the scgi_no_cache directive.\n
| \n Syntax:\n | \n\n scgi_cache_min_uses \n | \n
|---|---|
| \n Default:\n | \n\n scgi_cache_min_uses 1;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the number of requests after which the response\nwill be cached.\n
| \n Syntax:\n | \n\n scgi_cache_path \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nSets the path and other parameters of a cache.\nCache data are stored in files.\nThe file name in a cache is a result of\napplying the MD5 function to the\ncache key.\nThe levels parameter defines hierarchy levels of a cache:\nfrom 1 to 3, each level accepts values 1 or 2.\nFor example, in the following configuration\n
\nscgi_cache_path /data/nginx/cache levels=1:2 keys_zone=one:10m;\n
\nfile names in a cache will look like this:\n
\n/data/nginx/cache/c/29/b7f54b2df7773722d382f4809d65029c\n
\n
\nA cached response is first written to a temporary file,\nand then the file is renamed.\nStarting from version 0.8.9, temporary files and the cache can be put on\ndifferent file systems.\nHowever, be aware that in this case a file is copied\nacross two file systems instead of the cheap renaming operation.\nIt is thus recommended that for any given location both cache and a directory\nholding temporary files\nare put on the same file system.\nA directory for temporary files is set based on\nthe use_temp_path parameter (1.7.10).\nIf this parameter is omitted or set to the value on,\nthe directory set by the scgi_temp_path directive\nfor the given location will be used.\nIf the value is set to off,\ntemporary files will be put directly in the cache directory.\n
\nIn addition, all active keys and information about data are stored\nin a shared memory zone, whose name and size\nare configured by the keys_zone parameter.\nOne megabyte zone can store about 8 thousand keys.\n
\nAs part of\ncommercial subscription,\nthe shared memory zone also stores extended\ncache information,\nthus, it is required to specify a larger zone size for the same number of keys.\nFor example,\none megabyte zone can store about 4 thousand keys.\n
\n
\nCached data that are not accessed during the time specified by the\ninactive parameter get removed from the cache\nregardless of their freshness.\nBy default, inactive is set to 10 minutes.\n
\nThe special “cache manager” process monitors the maximum cache size set\nby the max_size parameter,\nand the minimum amount of free space set\nby the min_free (1.19.1) parameter\non the file system with cache.\nWhen the size is exceeded or there is not enough free space,\nit removes the least recently used data.\nThe data is removed in iterations configured by\nmanager_files,\nmanager_threshold, and\nmanager_sleep parameters (1.11.5).\nDuring one iteration no more than manager_files items\nare deleted (by default, 100).\nThe duration of one iteration is limited by the\nmanager_threshold parameter (by default, 200 milliseconds).\nBetween iterations, a pause configured by the manager_sleep\nparameter (by default, 50 milliseconds) is made.\n
\nA minute after the start the special “cache loader” process is activated.\nIt loads information about previously cached data stored on file system\ninto a cache zone.\nThe loading is also done in iterations.\nDuring one iteration no more than loader_files items\nare loaded (by default, 100).\nBesides, the duration of one iteration is limited by the\nloader_threshold parameter (by default, 200 milliseconds).\nBetween iterations, a pause configured by the loader_sleep\nparameter (by default, 50 milliseconds) is made.\n
\nAdditionally,\nthe following parameters are available as part of our\ncommercial subscription:\n
\n
purger=on|off\non\n(default is off)\nwill activate the “cache purger” process that\npermanently iterates through all cache entries\nand deletes the entries that match the wildcard key.\npurger_files=number\npurger_files is set to 10.\npurger_threshold=number\npurger_threshold is set to 50 milliseconds.\npurger_sleep=number\npurger_sleep is set to 50 milliseconds.\n\n
\n
\nIn versions 1.7.3, 1.7.7, and 1.11.10 cache header format has been changed.\nPreviously cached responses will be considered invalid\nafter upgrading to a newer nginx version.\n
\n
| \n Syntax:\n | \n\n scgi_cache_purge string ...;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.7.\n
\nDefines conditions under which the request will be considered a cache\npurge request.\nIf at least one value of the string parameters is not empty and is not equal\nto “0” then the cache entry with a corresponding\ncache key is removed.\nThe result of successful operation is indicated by returning\nthe 204 (No Content) response.\n
\nIf the cache key of a purge request ends\nwith an asterisk (“*”), all cache entries matching the\nwildcard key will be removed from the cache.\nHowever, these entries will remain on the disk until they are deleted\nfor either inactivity,\nor processed by the cache purger (1.7.12),\nor a client attempts to access them.\n
\nExample configuration:\n
\nscgi_cache_path /data/nginx/cache keys_zone=cache_zone:10m;\n\nmap $request_method $purge_method {\n PURGE 1;\n default 0;\n}\n\nserver {\n ...\n location / {\n scgi_pass backend;\n scgi_cache cache_zone;\n scgi_cache_key $uri;\n scgi_cache_purge $purge_method;\n }\n}\n\n
\nThis functionality is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n scgi_cache_revalidate \n | \n
|---|---|
| \n Default:\n | \n\n scgi_cache_revalidate off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.7.\n
\nEnables revalidation of expired cache items using conditional requests with\nthe “If-Modified-Since” and “If-None-Match”\nheader fields.\n
| \n Syntax:\n | \n\n scgi_cache_use_stale \n \n | \n
|---|---|
| \n Default:\n | \n\n scgi_cache_use_stale off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines in which cases a stale cached response can be used\nwhen an error occurs during communication with the SCGI server.\nThe directive’s parameters match the parameters of the\nscgi_next_upstream directive.\n
\nThe error parameter also permits\nusing a stale cached response if an SCGI server to process a request\ncannot be selected.\n
\nAdditionally, the updating parameter permits\nusing a stale cached response if it is currently being updated.\nThis allows minimizing the number of accesses to SCGI servers\nwhen updating cached data.\n
\nUsing a stale cached response\ncan also be enabled directly in the response header\nfor a specified number of seconds after the response became stale (1.11.10).\nThis has lower priority than using the directive parameters.\n
\n
\nTo minimize the number of accesses to SCGI servers when\npopulating a new cache element, the scgi_cache_lock\ndirective can be used.\n
| \n Syntax:\n | \n\n scgi_cache_valid [\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets caching time for different response codes.\nFor example, the following directives\n
\nscgi_cache_valid 200 302 10m;\nscgi_cache_valid 404 1m;\n
\nset 10 minutes of caching for responses with codes 200 and 302\nand 1 minute for responses with code 404.\n
\nIf only caching time is specified\n
\nscgi_cache_valid 5m;\n
\nthen only 200, 301, and 302 responses are cached.\n
\nIn addition, the any parameter can be specified\nto cache any responses:\n
\nscgi_cache_valid 200 302 10m;\nscgi_cache_valid 301 1h;\nscgi_cache_valid any 1m;\n
\n
\nParameters of caching can also be set directly\nin the response header.\nThis has higher priority than setting of caching time using the directive.\n
@ prefix, it sets an absolute\ntime in seconds since Epoch, up to which the response may be cached.\n*”, such a\nresponse will not be cached (1.7.7).\nIf the header includes the “Vary” field\nwith another value, such a response will be cached\ntaking into account the corresponding request header fields (1.7.7).\n\nProcessing of one or more of these response header fields can be disabled\nusing the scgi_ignore_headers directive.\n
| \n Syntax:\n | \n\n scgi_connect_timeout \n | \n
|---|---|
| \n Default:\n | \n\n scgi_connect_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a timeout for establishing a connection with an SCGI server.\nIt should be noted that this timeout cannot usually exceed 75 seconds.\n
| \n Syntax:\n | \n\n scgi_force_ranges \n | \n
|---|---|
| \n Default:\n | \n\n scgi_force_ranges off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.7.\n
\nEnables byte-range support\nfor both cached and uncached responses from the SCGI server\nregardless of the “Accept-Ranges” field in these responses.\n
| \n Syntax:\n | \n\n scgi_hide_header \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nBy default,\nnginx does not pass the header fields “Status” and\n“X-Accel-...” from the response of an SCGI\nserver to a client.\nThe scgi_hide_header directive sets additional fields\nthat will not be passed.\nIf, on the contrary, the passing of fields needs to be permitted,\nthe scgi_pass_header directive can be used.\n
| \n Syntax:\n | \n\n scgi_ignore_client_abort \n | \n
|---|---|
| \n Default:\n | \n\n scgi_ignore_client_abort off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines whether the connection with an SCGI server should be\nclosed when a client closes the connection without waiting\nfor a response.\n
| \n Syntax:\n | \n\n scgi_ignore_headers \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDisables processing of certain response header fields from the SCGI server.\nThe following fields can be ignored: “X-Accel-Redirect”,\n“X-Accel-Expires”, “X-Accel-Limit-Rate” (1.1.6),\n“X-Accel-Buffering” (1.1.6),\n“X-Accel-Charset” (1.1.6), “Expires”,\n“Cache-Control”, “Set-Cookie” (0.8.44),\nand “Vary” (1.7.7).\n
\nIf not disabled, processing of these header fields has the following\neffect:\n
\n
| \n Syntax:\n | \n\n scgi_intercept_errors \n | \n
|---|---|
| \n Default:\n | \n\n scgi_intercept_errors off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines whether an SCGI server responses with codes greater than or equal\nto 300 should be passed to a client\nor be intercepted and redirected to nginx for processing\nwith the error_page directive.\n
| \n Syntax:\n | \n\n scgi_limit_rate \n | \n
|---|---|
| \n Default:\n | \n\n scgi_limit_rate 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.7.\n
\nLimits the speed of reading the response from the SCGI server.\nThe rate is specified in bytes per second.\nThe zero value disables rate limiting.\nThe limit is set per a request, and so if nginx simultaneously opens\ntwo connections to the SCGI server,\nthe overall rate will be twice as much as the specified limit.\nThe limitation works only if\nbuffering of responses from the SCGI\nserver is enabled.\nParameter value can contain variables (1.27.0).\n
| \n Syntax:\n | \n\n scgi_max_temp_file_size \n | \n
|---|---|
| \n Default:\n | \n\n scgi_max_temp_file_size 1024m;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nWhen buffering of responses from the SCGI\nserver is enabled, and the whole response does not fit into the buffers\nset by the scgi_buffer_size and scgi_buffers\ndirectives, a part of the response can be saved to a temporary file.\nThis directive sets the maximum size of the temporary file.\nThe size of data written to the temporary file at a time is set\nby the scgi_temp_file_write_size directive.\n
\nThe zero value disables buffering of responses to temporary files.\n
\n
\nThis restriction does not apply to responses\nthat will be cached\nor stored on disk.\n
\n
| \n Syntax:\n | \n\n scgi_next_upstream \n \n | \n
|---|---|
| \n Default:\n | \n\n scgi_next_upstream error timeout;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies in which cases a request should be passed to the next server:\n
errortimeoutdenied\n
\nThis parameter is available as part of our\ncommercial subscription.\n
\n
\ninvalid_headerhttp_500http_503http_403http_404http_429non_idempotentPOST, LOCK, PATCH)\nare not passed to the next server\nif a request has been sent to an upstream server (1.9.13);\nenabling this option explicitly allows retrying such requests;\noff\n
\nOne should bear in mind that passing a request to the next server is\nonly possible if nothing has been sent to a client yet.\nThat is, if an error or timeout occurs in the middle of the\ntransferring of a response, fixing this is impossible.\n
\nThe directive also defines what is considered an\nunsuccessful\nattempt of communication with a server.\nThe cases of error, timeout,\ndenied and\ninvalid_header are always considered unsuccessful attempts,\neven if they are not specified in the directive.\nThe cases of http_500, http_503,\nand http_429 are\nconsidered unsuccessful attempts only if they are specified in the directive.\nThe cases of http_403 and http_404\nare never considered unsuccessful attempts.\n
\nPassing a request to the next server can be limited by\nthe number of tries\nand by time.\n
| \n Syntax:\n | \n\n scgi_next_upstream_timeout \n | \n
|---|---|
| \n Default:\n | \n\n scgi_next_upstream_timeout 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.5.\n
\nLimits the time during which a request can be passed to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n scgi_next_upstream_tries \n | \n
|---|---|
| \n Default:\n | \n\n scgi_next_upstream_tries 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.5.\n
\nLimits the number of possible tries for passing a request to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n scgi_no_cache \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines conditions under which the response will not be saved to a cache.\nIf at least one value of the string parameters is not empty and is not\nequal to “0” then the response will not be saved:\n
\nscgi_no_cache $cookie_nocache $arg_nocache$arg_comment;\nscgi_no_cache $http_pragma $http_authorization;\n
\nCan be used along with the scgi_cache_bypass directive.\n
| \n Syntax:\n | \n\n scgi_param \n \n | \n
|---|---|
| \n Default:\n | \n\n scgi_param HTTP_HOST $host$is_request_port$request_port;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a parameter that should be passed to the SCGI server.\nThe value can contain text, variables, and their combination.\nThese directives are inherited from the previous configuration level\nif and only if there are no scgi_param directives\ndefined on the current level.\n
\nStandard\nCGI\nenvironment variables\nshould be provided as SCGI headers, see the scgi_params file\nprovided in the distribution:\n
\nlocation / {\n include scgi_params;\n ...\n}\n\n
\nIf the directive is specified with if_not_empty (1.1.11) then\nsuch a parameter will be passed to the server only if its value is not empty:\n
\nscgi_param HTTPS $https if_not_empty;\n
\n
| \n Syntax:\n | \n\n scgi_pass \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location, if in location\n | \n
\nSets the address of an SCGI server.\nThe address can be specified as a domain name or IP address,\nand a port:\n
\nscgi_pass localhost:9000;\n
\nor as a UNIX-domain socket path:\n
\nscgi_pass unix:/tmp/scgi.socket;\n
\n
\nIf a domain name resolves to several addresses, all of them will be\nused in a round-robin fashion.\nIn addition, an address can be specified as a\nserver group.\n
\nParameter value can contain variables.\nIn this case, if an address is specified as a domain name,\nthe name is searched among the described\nserver groups,\nand, if not found, is determined using a\nresolver.\n
| \n Syntax:\n | \n\n scgi_pass_header \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nPermits passing otherwise disabled header\nfields from an SCGI server to a client.\n
| \n Syntax:\n | \n\n scgi_pass_request_body \n | \n
|---|---|
| \n Default:\n | \n\n scgi_pass_request_body on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIndicates whether the original request body is passed\nto the SCGI server.\nSee also the scgi_pass_request_headers directive.\n
| \n Syntax:\n | \n\n scgi_pass_request_headers \n | \n
|---|---|
| \n Default:\n | \n\n scgi_pass_request_headers on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIndicates whether the header fields of the original request are passed\nto the SCGI server.\nSee also the scgi_pass_request_body directive.\n
| \n Syntax:\n | \n\n scgi_read_timeout \n | \n
|---|---|
| \n Default:\n | \n\n scgi_read_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a timeout for reading a response from the SCGI server.\nThe timeout is set only between two successive read operations,\nnot for the transmission of the whole response.\nIf the SCGI server does not transmit anything within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n scgi_request_buffering \n | \n
|---|---|
| \n Default:\n | \n\n scgi_request_buffering on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.11.\n
\nEnables or disables buffering of a client request body.\n
\nWhen buffering is enabled, the entire request body is\nread\nfrom the client before sending the request to an SCGI server.\n
\nWhen buffering is disabled, the request body is sent to the SCGI server\nimmediately as it is received.\nIn this case, the request cannot be passed to the\nnext server\nif nginx already started sending the request body.\n
\nWhen HTTP/1.1 chunked transfer encoding is used\nto send the original request body,\nthe request body will be buffered regardless of the directive value.\n
| \n Syntax:\n | \n\n scgi_request_dynamic \n | \n
|---|---|
| \n Default:\n | \n\n scgi_request_dynamic off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nEnables or disables creation of a separate request instance\nfor each SCGI server.\nBy default, a single request is used for all SCGI servers.\nIf enabled, a separate request instance is created,\nallowing per-server request customization.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n scgi_send_timeout \n | \n
|---|---|
| \n Default:\n | \n\n scgi_send_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a timeout for transmitting a request to the SCGI server.\nThe timeout is set only between two successive write operations,\nnot for the transmission of the whole request.\nIf the SCGI server does not receive anything within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n scgi_socket_keepalive \n | \n
|---|---|
| \n Default:\n | \n\n scgi_socket_keepalive off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.15.6.\n
\nConfigures the “TCP keepalive” behavior\nfor outgoing connections to an SCGI server.\nBy default, the operating system’s settings are in effect for the socket.\nIf the directive is set to the value “on”, the\nSO_KEEPALIVE socket option is turned on for the socket.\n
| \n Syntax:\n | \n\n scgi_store \n \n | \n
|---|---|
| \n Default:\n | \n\n scgi_store off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables saving of files to a disk.\nThe on parameter saves files with paths\ncorresponding to the directives\nalias or\nroot.\nThe off parameter disables saving of files.\nIn addition, the file name can be set explicitly using the\nstring with variables:\n
\nscgi_store /data/www$original_uri;\n
\n
\nThe modification time of files is set according to the received\n“Last-Modified” response header field.\nThe response is first written to a temporary file,\nand then the file is renamed.\nStarting from version 0.8.9, temporary files and the persistent store\ncan be put on different file systems.\nHowever, be aware that in this case a file is copied\nacross two file systems instead of the cheap renaming operation.\nIt is thus recommended that for any given location both saved files and a\ndirectory holding temporary files, set by the scgi_temp_path\ndirective, are put on the same file system.\n
\nThis directive can be used to create local copies of static unchangeable\nfiles, e.g.:\n
\nlocation /images/ {\n root /data/www;\n error_page 404 = /fetch$uri;\n}\n\nlocation /fetch/ {\n internal;\n\n scgi_pass backend:9000;\n ...\n\n scgi_store on;\n scgi_store_access user:rw group:rw all:r;\n scgi_temp_path /data/temp;\n\n alias /data/www/;\n}\n\n
| \n Syntax:\n | \n\n scgi_store_access \n | \n
|---|---|
| \n Default:\n | \n\n scgi_store_access user:rw;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets access permissions for newly created files and directories, e.g.:\n
\nscgi_store_access user:rw group:rw all:r;\n
\n
\nIf any group or all access permissions\nare specified then user permissions may be omitted:\n
\nscgi_store_access group:rw all:r;\n
\n
| \n Syntax:\n | \n\n scgi_temp_file_write_size \n | \n
|---|---|
| \n Default:\n | \n\n scgi_temp_file_write_size 8k|16k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nLimits the size of data written to a temporary file\nat a time, when buffering of responses from the SCGI server\nto temporary files is enabled.\nBy default, size is limited by two buffers set by the\nscgi_buffer_size and scgi_buffers directives.\nThe maximum size of a temporary file is set by the\nscgi_max_temp_file_size directive.\n
| \n Syntax:\n | \n\n scgi_temp_path \n \n | \n
|---|---|
| \n Default:\n | \n\n scgi_temp_path scgi_temp;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a directory for storing temporary files\nwith data received from SCGI servers.\nUp to three-level subdirectory hierarchy can be used underneath the specified\ndirectory.\nFor example, in the following configuration\n
\nscgi_temp_path /spool/nginx/scgi_temp 1 2;\n
\na temporary file might look like this:\n
\n/spool/nginx/scgi_temp/7/45/00000123457\n
\n
\nSee also the use_temp_path parameter of the\nscgi_cache_path directive.\n
| Directives secure_link secure_link_md5 secure_link_secret Embedded Variables |
\nThe ngx_http_secure_link_module module (0.7.18)\nis used to check authenticity of requested links,\nprotect resources from unauthorized access,\nand limit link lifetime.\n
\nThe authenticity of a requested link is verified by comparing the\nchecksum value passed in a request with the value computed\nfor the request.\nIf a link has a limited lifetime and the time has expired,\nthe link is considered outdated.\nThe status of these checks is made available in the\n$secure_link variable.\n
\nThe module provides two alternative operation modes.\nThe first mode is enabled by the secure_link_secret\ndirective and is used to check authenticity of requested links\nas well as protect resources from unauthorized access.\nThe second mode (0.8.50) is enabled by the\nsecure_link and secure_link_md5\ndirectives and is also used to limit lifetime of links.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_secure_link_module\nconfiguration parameter.\n
| \n Syntax:\n | \n\n secure_link \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a string with variables from which the\nchecksum value and lifetime of a link will be extracted.\n
\nVariables used in an expression are usually associated\nwith a request; see example below.\n
\nThe checksum value extracted from the string is compared with\nthe MD5 hash value of the expression defined by the\nsecure_link_md5 directive.\nIf the checksums are different, the $secure_link variable\nis set to an empty string.\nIf the checksums are the same, the link lifetime is checked.\nIf the link has a limited lifetime and the time has expired,\nthe $secure_link variable is set to “0”.\nOtherwise, it is set to “1”.\nThe MD5 hash value passed in a request is encoded in\nbase64url.\n
\nIf a link has a limited lifetime, the expiration time\nis set in seconds since Epoch (Thu, 01 Jan 1970 00:00:00 GMT).\nThe value is specified in the expression after the MD5 hash,\nand is separated by a comma.\nThe expiration time passed in a request is available through\nthe $secure_link_expires variable for a use in\nthe secure_link_md5 directive.\nIf the expiration time is not specified, a link has the unlimited\nlifetime.\n
| \n Syntax:\n | \n\n secure_link_md5 \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines an expression for which the MD5 hash value will\nbe computed and compared with the value passed in a request.\n
\nThe expression should contain the secured part of a link (resource)\nand a secret ingredient.\nIf the link has a limited lifetime,\nthe expression should also contain $secure_link_expires.\n
\nTo prevent unauthorized access, the expression may contain some\ninformation about the client, such as its address and browser version.\n
\nExample:\n
\nlocation /s/ {\n secure_link $arg_md5,$arg_expires;\n secure_link_md5 \"$secure_link_expires$uri$remote_addr secret\";\n\n if ($secure_link = \"\") {\n return 403;\n }\n\n if ($secure_link = \"0\") {\n return 410;\n }\n\n ...\n}\n \nThe\n“/s/link?md5=_e4Nc3iduzkWRm01TBBNYw&expires=2147483647”\nlink\nrestricts access to “/s/link” for the client with the\nIP address 127.0.0.1.\nThe link also has the limited lifetime until January 19, 2038 (GMT).\n
\nOn UNIX, the md5 request argument value can be obtained as:\n
\necho -n '2147483647/s/link127.0.0.1 secret' | \\\n openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d =\n
\n
| \n Syntax:\n | \n\n secure_link_secret \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nDefines a secret word used to check authenticity\nof requested links.\n
\nThe full URI of a requested link looks as follows:\n
\n/prefix/hash/link\n
\nwhere hash is a hexadecimal representation of the\nMD5 hash computed for the concatenation of the link and secret word,\nand prefix is an arbitrary string without slashes.\n
\nIf the requested link passes the authenticity check,\nthe $secure_link variable is set to the link\nextracted from the request URI.\nOtherwise, the $secure_link variable\nis set to an empty string.\n
\nExample:\n
\nlocation /p/ {\n secure_link_secret secret;\n\n if ($secure_link = \"\") {\n return 403;\n }\n\n rewrite ^ /secure/$secure_link;\n}\n\nlocation /secure/ {\n internal;\n}\n \nA request of “/p/5e814704a28d9bc1914ff19fa0c4a00a/link”\nwill be internally redirected to\n“/secure/link”.\n
\nOn UNIX, the hash value for this example can be obtained as:\n
\necho -n 'linksecret' | openssl md5 -hex\n
\n
\n\n\n\n
$secure_link$secure_link_expires\n\n
\n\n| Example Configuration Directives session_log session_log_format session_log_zone Embedded Variables |
\nThe ngx_http_session_log_module module enables logging\nsessions (that is, aggregates of multiple HTTP requests) instead of\nindividual HTTP requests.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\nThe following configuration sets up a session log and maps requests to\nsessions according to the request client address and “User-Agent”\nrequest header field:\n
\n session_log_zone /path/to/log format=combined\n zone=one:1m timeout=30s\n md5=$binary_remote_addr$http_user_agent;\n\n location /media/ {\n session_log one;\n }\n\n
\n\n\n| \n Syntax:\n | \n\n session_log \n | \n
|---|---|
| \n Default:\n | \n\n session_log off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables the use of the specified session log.\nThe special value off cancels the effect\nof the session_log directives\ninherited from the previous configuration level.\n
| \n Syntax:\n | \n\n session_log_format \n \n | \n
|---|---|
| \n Default:\n | \n\n session_log_format combined \"...\";\n | \n
| \n Context:\n | \n\n http\n | \n
\nSpecifies the output format of a log.\nThe value of the $body_bytes_sent variable is aggregated across\nall requests in a session.\nThe values of all other variables available for logging correspond to the\nfirst request in a session.\n
| \n Syntax:\n | \n\n session_log_zone \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nSets the path to a log file and configures the shared memory zone that is used\nto store currently active sessions.\n
\nA session is considered active for as long as the time elapsed since\nthe last request in the session does not exceed the specified\ntimeout (by default, 30 seconds).\nOnce a session is no longer active, it is written to the log.\n
\nThe id parameter identifies the\nsession to which a request is mapped.\nThe id parameter is set to the hexadecimal representation\nof an MD5 hash (for example, obtained from a cookie using variables).\nIf this parameter is not specified or does not represent the valid\nMD5 hash, nginx computes the MD5 hash from the value of\nthe md5 parameter and creates a new session using this hash.\nBoth the id and md5 parameters\ncan contain variables.\n
\nThe format parameter sets the custom session log\nformat configured by the session_log_format directive.\nIf format is not specified, the predefined\n“combined” format is used.\n
\nThe ngx_http_session_log_module module supports\ntwo embedded variables:\n\n
$session_log_id$session_log_binary_id\n\n
\n\n| Known Issues Example Configuration Directives slice Embedded Variables |
\nThe ngx_http_slice_module module (1.9.8) is a filter\nthat splits a request into subrequests,\neach returning a certain range of response.\nThe filter provides more effective caching of big responses.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_slice_module\nconfiguration parameter.\n
\nCurrently, the module does not work as expected in subrequests such as\n\nbackground cache update.\nIn this case, a request is constructed without byte-range support.\n
\n\n\n\n
\nlocation / {\n slice 1m;\n proxy_cache cache;\n proxy_cache_key $uri$is_args$args$slice_range;\n proxy_set_header Range $slice_range;\n proxy_cache_valid 200 206 1h;\n proxy_pass http://localhost:8000;\n}\n\nIn this example,\nthe response is split into 1-megabyte cacheable slices.\n
\n\n\n| \n Syntax:\n | \n\n slice \n | \n
|---|---|
| \n Default:\n | \n\n slice 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the size of the slice.\nThe zero value disables splitting responses into slices.\nNote that a too low value may result in excessive memory usage\nand opening a large number of files.\n
\nIn order for a subrequest to return the required range,\nthe $slice_range variable should be\npassed to\nthe proxied server as the Range request header field.\nIf\ncaching\nis enabled, $slice_range should be added to the\ncache key\nand caching of responses with 206 status code should be\nenabled.\n
\nThe ngx_http_slice_module module\nsupports the following embedded variables:\n
$slice_rangebytes=0-1048575.\n\n
\n\n| Example Configuration Directives split_clients |
\nThe ngx_http_split_clients_module module creates\nvariables suitable for A/B testing, also known as split testing.\n
\n
\nhttp {\n split_clients \"${remote_addr}AAA\" $variant {\n 0.5% .one;\n 2.0% .two;\n * \"\";\n }\n\n server {\n location / {\n index index${variant}.html;\n\n
\n\n\n| \n Syntax:\n | \n\n split_clients \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nCreates a variable for A/B testing, for example:\n
\nsplit_clients \"${remote_addr}AAA\" $variant {\n 0.5% .one;\n 2.0% .two;\n * \"\";\n}\n \nThe value of the original string is hashed using MurmurHash2.\nIn the example given, hash values from 0 to 21474835 (0.5%)\ncorrespond to the\nvalue \".one\" of the $variant variable,\nhash values from 21474836 to 107374180 (2%) correspond to\nthe value \".two\",\nand hash values from 107374181 to 4294967295 correspond to\nthe value \"\" (an empty string).\n
| Example Configuration Directives ssi ssi_last_modified ssi_min_file_chunk ssi_silent_errors ssi_types ssi_value_length SSI Commands Embedded Variables |
\nThe ngx_http_ssi_module module is a filter\nthat processes SSI (Server Side Includes) commands in responses\npassing through it.\nCurrently, the list of supported SSI commands is incomplete.\n
\n
\nlocation / {\n ssi on;\n ...\n}\n\n
\n\n\n| \n Syntax:\n | \n\n ssi \n | \n
|---|---|
| \n Default:\n | \n\n ssi off;\n | \n
| \n Context:\n | \n\n http, server, location, if in location\n | \n
\nEnables or disables processing of SSI commands in responses.\n
| \n Syntax:\n | \n\n ssi_last_modified \n | \n
|---|---|
| \n Default:\n | \n\n ssi_last_modified off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.1.\n
\nAllows preserving the “Last-Modified” header field\nfrom the original response during SSI processing\nto facilitate response caching.\n
\nBy default, the header field is removed as contents of the response\nare modified during processing and may contain dynamically generated elements\nor parts that are changed independently of the original response.\n
| \n Syntax:\n | \n\n ssi_min_file_chunk \n | \n
|---|---|
| \n Default:\n | \n\n ssi_min_file_chunk 1k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the minimum size for parts of a response stored on disk,\nstarting from which it makes sense to send them using\nsendfile.\n
| \n Syntax:\n | \n\n ssi_silent_errors \n | \n
|---|---|
| \n Default:\n | \n\n ssi_silent_errors off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIf enabled, suppresses the output of the\n“[an error occurred while processing the directive]”\nstring if an error occurred during SSI processing.\n
| \n Syntax:\n | \n\n ssi_types \n | \n
|---|---|
| \n Default:\n | \n\n ssi_types text/html;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables processing of SSI commands in responses with the specified MIME types\nin addition to “text/html”.\nThe special value “*” matches any MIME type (0.8.29).\n
| \n Syntax:\n | \n\n ssi_value_length \n | \n
|---|---|
| \n Default:\n | \n\n ssi_value_length 256;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the maximum length of parameter values in SSI commands.\n
\n\n\n\nSSI commands have the following generic format:\n
\n<!--# command parameter1=value1 parameter2=value2 ... -->\n
\n
\nThe following commands are supported:\n
blockinclude command.\nThe block can contain other SSI commands.\nThe command has the following parameter:\n\nname\n\n\n<!--# block name=\"one\" -->\nstub\n<!--# endblock -->\n
configerrmsg\n\n[an error occurred while processing the directive]\n
timefmtstrftime() function\nused to output date and time.\nBy default, the following format is used:\n\nThe “\n\"%A, %d-%b-%Y %H:%M:%S %Z\"\n
%s” format is suitable to output time in seconds.\nechovarencodingnone, url, and\nentity.\nBy default, entity is used.\ndefault(none)” is output.\nThe command\n\nreplaces the following sequence of commands:\n\n<!--# echo var=\"name\" default=\"no\" -->\n
\n\n<!--# if expr=\"$name\" --><!--# echo var=\"name\" --><!--#\n else -->no<!--# endif -->\n
if\nOnly one level of nesting is currently supported.\nThe command has the following parameter:\n\n\n<!--# if expr=\"...\" -->\n...\n<!--# elif expr=\"...\" -->\n...\n<!--# else -->\n...\n<!--# endif -->\n
expr\n\n<!--# if expr=\"$name\" -->\n
\n\n<!--# if expr=\"$name =text\" -->\n<!--# if expr=\"$name !=text\" -->\n
\n\n<!--# if expr=\"$name = /text/\" -->\n<!--# if expr=\"$name != /text/\" -->\n
text contains variables,\ntheir values are substituted.\nA regular expression can contain positional and named captures\nthat can later be used through variables, for example:\n\n\n<!--# if expr=\"$name = /(.+)@(?P<domain>.+)/\" -->\n <!--# echo var=\"1\" -->\n <!--# echo var=\"domain\" -->\n<!--# endif -->\n
includefile\n\n<!--# include file=\"footer.html\" -->\n
virtual\nSeveral requests specified on one page and processed by proxied or\nFastCGI/uwsgi/SCGI/gRPC servers run in parallel.\nIf sequential processing is desired, the\n<!--# include virtual=\"/remote/body.php?argument=value\" -->\n
wait\nparameter should be used.\nstub\nThe replacement block content is processed in the included request context.\n\n<!--# block name=\"one\" --> <!--# endblock -->\n<!--# include virtual=\"/remote/body.php?argument=value\" stub=\"one\" -->\n
wait\n\n<!--# include virtual=\"/remote/body.php?argument=value\" wait=\"yes\" -->\n
set\nThe maximum size of the response is set by the\nsubrequest_output_buffer_size\ndirective (1.13.10):\n\n<!--# include virtual=\"/remote/body.php?argument=value\" set=\"one\" -->\n
\nlocation /remote/ {\n subrequest_output_buffer_size 64k;\n ...\n}\n\nPrior to version 1.13.10, only the results of responses obtained using the\nngx_http_proxy_module,\nngx_http_memcached_module,\nngx_http_fastcgi_module (1.5.6),\nngx_http_uwsgi_module (1.5.6),\nand ngx_http_scgi_module (1.5.6)\nmodules could be written into variables.\nThe maximum size of the response was set with the\nproxy_buffer_size,\nmemcached_buffer_size,\nfastcgi_buffer_size,\nuwsgi_buffer_size,\nand scgi_buffer_size\ndirectives.\nsetvarvalue\n
\n\n\n\nThe ngx_http_ssi_module module supports\ntwo embedded variables:\n
$date_localconfig command\nwith the timefmt parameter.\n$date_gmtconfig command\nwith the timefmt parameter.\n\n
\n\n\nThe ngx_http_ssl_module module provides the\nnecessary support for HTTPS.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_ssl_module\nconfiguration parameter.\n
\nThis module requires the\nOpenSSL library.\n
\n
\n\n\n\nTo reduce the processor load, it is recommended to\n
\n\n
\nworker_processes auto;\n\nhttp {\n\n ...\n\n server {\n listen 443 ssl;\n keepalive_timeout 70;\n\n ssl_protocols TLSv1.2 TLSv1.3;\n ssl_ciphers AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;\n ssl_certificate /usr/local/nginx/conf/cert.pem;\n ssl_certificate_key /usr/local/nginx/conf/cert.key;\n ssl_session_cache shared:SSL:10m;\n ssl_session_timeout 10m;\n\n ...\n }\n\n
\n\n\n| \n Syntax:\n | \n\n ssl \n | \n
|---|---|
| \n Default:\n | \n\n ssl off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nThis directive was made obsolete in version 1.15.0\nand was removed in version 1.25.1.\nThe ssl parameter\nof the listen directive\nshould be used instead.\n
| \n Syntax:\n | \n\n ssl_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n ssl_buffer_size 16k;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.5.9.\n
\nSets the size of the buffer used for sending data.\n
\nBy default, the buffer size is 16k, which corresponds to minimal\noverhead when sending big responses.\nTo minimize Time To First Byte it may be beneficial to use smaller values,\nfor example:\n
\nssl_buffer_size 4k;\n
\n
| \n Syntax:\n | \n\n ssl_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSpecifies a file with the certificate in the PEM format\nfor the given virtual server.\nIf intermediate certificates should be specified in addition to a primary\ncertificate, they should be specified in the same file in the following\norder: the primary certificate comes first, then the intermediate certificates.\nA secret key in the PEM format may be placed in the same file.\n
\nSince version 1.11.0,\nthis directive can be specified multiple times\nto load certificates of different types, for example, RSA and ECDSA:\n
\nserver {\n listen 443 ssl;\n server_name example.com;\n\n ssl_certificate example.com.rsa.crt;\n ssl_certificate_key example.com.rsa.key;\n\n ssl_certificate example.com.ecdsa.crt;\n ssl_certificate_key example.com.ecdsa.key;\n\n ...\n}\n\n
\nOnly OpenSSL 1.0.2 or higher supports separate\ncertificate chains\nfor different certificates.\nWith older versions, only one certificate chain can be used.\n
\n
\nSince version 1.15.9, variables can be used in the file name\nwhen using OpenSSL 1.0.2 or higher:\n
\nssl_certificate $ssl_server_name.crt;\nssl_certificate_key $ssl_server_name.key;\n
\nNote that using variables implies that\na certificate will be loaded for each SSL handshake,\nand this may have a negative impact on performance.\n
\nThe value\ndata:$variable\ncan be specified instead of the file (1.15.10),\nwhich loads a certificate from a variable\nwithout using intermediate files.\nNote that inappropriate use of this syntax may have its security implications,\nsuch as writing secret key data to\nerror log.\n
\nIt should be kept in mind that due to the SSL/TLS protocol limitations,\nfor maximum interoperability with clients that do not use\nSNI,\nvirtual servers with different certificates should listen on\ndifferent\nIP addresses.\n
| \n Syntax:\n | \n\n ssl_certificate_cache ssl_certificate_cache \n \n | \n
|---|---|
| \n Default:\n | \n\n ssl_certificate_cache off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.27.4.\n
\nDefines a cache that stores\nSSL certificates and\nsecret keys\nspecified with variables.\n
\nThe directive has the following parameters:\n
max\ninactive\nvalid\noff\n\n
\nExample:\n
\nssl_certificate $ssl_server_name.crt;\nssl_certificate_key $ssl_server_name.key;\nssl_certificate_cache max=1000 inactive=20s valid=1m;\n
\n
| \n Syntax:\n | \n\n ssl_certificate_compression \n | \n
|---|---|
| \n Default:\n | \n\n ssl_certificate_compression off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.29.1.\n
\nEnables TLS 1.3\ncompression\nof server certificates.\n
\nThe directive is supported when using OpenSSL 3.2 or higher;\nthe list of supported compression algorithms is provided by the library.\n
\n
\nThe directive is supported when using BoringSSL;\nthe list of supported compression algorithms includes\nzlib (1.29.3).\n\n
| \n Syntax:\n | \n\n ssl_certificate_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSpecifies a file with the secret key in the PEM format\nfor the given virtual server.\n
\nThe value\nengine:name:id\ncan be specified instead of the file (1.7.9),\nwhich loads a secret key with a specified id\nfrom the OpenSSL engine name.\n
\nThe value\nstore:scheme:id\ncan be specified instead of the file (1.29.0),\nwhich is used to load a secret key with a specified id\nand OpenSSL provider registered URI scheme, such as\npkcs11.\n
\nThe value\ndata:$variable\ncan be specified instead of the file (1.15.10),\nwhich loads a secret key from a variable without using intermediate files.\nNote that inappropriate use of this syntax may have its security implications,\nsuch as writing secret key data to\nerror log.\n
\nSince version 1.15.9, variables can be used in the file name\nwhen using OpenSSL 1.0.2 or higher.\n
| \n Syntax:\n | \n\n ssl_ciphers \n | \n
|---|---|
| \n Default:\n | \n\n ssl_ciphers HIGH:!aNULL:!MD5;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSpecifies the enabled ciphers.\nThe ciphers are specified in the format understood by the\nOpenSSL library, for example:\n
\nssl_ciphers ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;\n
\n
\nThe full list can be viewed using the\n“openssl ciphers” command.\n
\n
\nThe previous versions of nginx used\ndifferent\nciphers by default.\n
\n
| \n Syntax:\n | \n\n ssl_client_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to verify client certificates and\nOCSP responses if ssl_stapling is enabled.\n
\nThe list of certificates will be sent to clients.\nIf this is not desired, the ssl_trusted_certificate\ndirective can be used.\n
| \n Syntax:\n | \n\n ssl_conf_command \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.19.4.\n
\nSets arbitrary OpenSSL configuration\ncommands.\n
\nThe directive is supported when using OpenSSL 1.0.2 or higher.\n
\n
\nSeveral ssl_conf_command directives\ncan be specified on the same level:\n
\nssl_conf_command Options PrioritizeChaCha;\nssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;\n
\nThese directives are inherited from the previous configuration level\nif and only if there are no ssl_conf_command directives\ndefined on the current level.\n
\n
\nNote that configuring OpenSSL directly\nmight result in unexpected behavior.\n
\n
| \n Syntax:\n | \n\n ssl_crl \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 0.8.7.\n
\nSpecifies a file with revoked certificates (CRL)\nin the PEM format used to verify\nclient certificates.\nWhen using intermediate certificates, their CRLs should be\nspecified in the same file.\n
| \n Syntax:\n | \n\n ssl_dhparam \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 0.7.2.\n
\nSpecifies a file with DH parameters for DHE ciphers.\n
\nBy default no parameters are set,\nand therefore DHE ciphers will not be used.\n
\nPrior to version 1.11.0, builtin parameters were used by default.\n
\n
| \n Syntax:\n | \n\n ssl_early_data \n | \n
|---|---|
| \n Default:\n | \n\n ssl_early_data off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.15.3.\n
\nEnables or disables TLS 1.3\nearly data.\n
\nThe directive is supported when using OpenSSL 1.1.1 or higher (1.15.4) and\nBoringSSL.\n
\n
\n
\nRequests sent within early data are subject to\nreplay attacks.\nTo protect against such attacks at the application layer,\nthe $ssl_early_data variable\nshould be used.\n
\n
\nproxy_set_header Early-Data $ssl_early_data;\n
\n
\n
\nOpenSSL built-in replay protection is disabled,\nbecause it interferes with session resumption.\nIt can be turned back if deemed necessary.\n
\n
\nssl_conf_command Options AntiReplay;\n
\n
| \n Syntax:\n | \n\n ssl_ecdh_curve \n | \n
|---|---|
| \n Default:\n | \n\n ssl_ecdh_curve auto;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\n This directive appeared in versions 1.1.0 and 1.0.6.\n \n
\n\nSpecifies a curve for ECDHE ciphers.\n
\nWhen using OpenSSL 1.0.2 or higher,\nit is possible to specify multiple curves (1.11.0), for example:\n
\nssl_ecdh_curve prime256v1:secp384r1;\n
\n
\nThe special value auto (1.11.0) instructs nginx to use\na list built into the OpenSSL library when using OpenSSL 1.0.2 or higher,\nor prime256v1 with older versions.\n
\n
\nPrior to version 1.11.0,\nthe prime256v1 curve was used by default.\n\n
\n
\nWhen using OpenSSL 1.0.2 or higher,\nthis directive sets the list of curves supported by the server.\nThus, in order for ECDSA certificates to work,\nit is important to include the curves used in the certificates.\n
\n
| \n Syntax:\n | \n\n ssl_ech_file \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.29.4.\n
\nSpecifies a file with encrypted ClientHello configuration\n(ECHConfig) in the\nPEM\nformat used to enable TLS 1.3\nECH\nin shared mode.\n
\n
\nThe directive is currently supported only when using OpenSSL\nECH\nfeature branch.\n
\n
| \n Syntax:\n | \n\n ssl_key_log path;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.27.2.\n
\nEnables logging of client connection SSL keys\nand specifies the path to the key log file.\nKeys are logged in the\nSSLKEYLOGFILE\nformat compatible with Wireshark.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n ssl_ocsp \n | \n
|---|---|
| \n Default:\n | \n\n ssl_ocsp off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.19.0.\n
\nEnables OCSP validation of the client certificate chain.\nThe leaf parameter\nenables validation of the client certificate only.\n
\nFor the OCSP validation to work,\nthe ssl_verify_client directive should be set to\non or optional.\n
\nTo resolve the OCSP responder hostname,\nthe resolver directive\nshould also be specified.\n
\nExample:\n
\nssl_verify_client on;\nssl_ocsp on;\nresolver 192.0.2.1;\n
\n
| \n Syntax:\n | \n\n ssl_ocsp_cache \n \n | \n
|---|---|
| \n Default:\n | \n\n ssl_ocsp_cache off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.19.0.\n
\nSets name and size of the cache\nthat stores client certificates status for OCSP validation.\nThe cache is shared between all worker processes.\nA cache with the same name can be used in several\nvirtual servers.\n
\nThe off parameter prohibits the use of the cache.\n
| \n Syntax:\n | \n\n ssl_ocsp_responder \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.19.0.\n
\nOverrides the URL of the OCSP responder specified in the\n“Authority\nInformation Access” certificate extension\nfor validation of client certificates.\n
\nOnly “http://” OCSP responders are supported:\n
\nssl_ocsp_responder http://ocsp.example.com/;\n
\n
| \n Syntax:\n | \n\n ssl_password_file \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.7.3.\n
\nSpecifies a file with passphrases for\nsecret keys\nwhere each passphrase is specified on a separate line.\nPassphrases are tried in turn when loading the key.\n
\nExample:\n
\nhttp {\n ssl_password_file /etc/keys/global.pass;\n ...\n\n server {\n server_name www1.example.com;\n ssl_certificate_key /etc/keys/first.key;\n }\n\n server {\n server_name www2.example.com;\n\n # named pipe can also be used instead of a file\n ssl_password_file /etc/keys/fifo;\n ssl_certificate_key /etc/keys/second.key;\n }\n}\n\n
| \n Syntax:\n | \n\n ssl_prefer_server_ciphers \n | \n
|---|---|
| \n Default:\n | \n\n ssl_prefer_server_ciphers off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSpecifies that server ciphers should be preferred over client ciphers\nwhen the SSLv3 and TLS protocols are used.\n
| \n Syntax:\n | \n\n ssl_protocols \n [\n | \n
|---|---|
| \n Default:\n | \n\n ssl_protocols TLSv1.2 TLSv1.3;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nEnables the specified protocols.\n
\nIf the directive is specified\non the server level,\nthe value from the default server can be used.\nDetails are provided in the\n“Virtual\nserver selection” section.\n
\n
\nTheTLSv1.1andTLSv1.2parameters\n(1.1.13, 1.0.12) work only when OpenSSL 1.0.1 or higher is used.\n
\n
\nThe TLSv1.3 parameter (1.13.0) works only when\nOpenSSL 1.1.1 or higher is used.\n\n
\nThe TLSv1.3 parameter is used by default\nsince 1.23.4.\n\n
| \n Syntax:\n | \n\n ssl_reject_handshake \n | \n
|---|---|
| \n Default:\n | \n\n ssl_reject_handshake off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.19.4.\n
\nIf enabled, SSL handshakes in\nthe server block will be rejected.\n
\nFor example, in the following configuration, SSL handshakes with\nserver names other than example.com are rejected:\n
\nserver {\n listen 443 ssl default_server;\n ssl_reject_handshake on;\n}\n\nserver {\n listen 443 ssl;\n server_name example.com;\n ssl_certificate example.com.crt;\n ssl_certificate_key example.com.key;\n}\n\n
| \n Syntax:\n | \n\n ssl_session_cache \n \n | \n
|---|---|
| \n Default:\n | \n\n ssl_session_cache none;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSets the types and sizes of caches that store session parameters.\nA cache can be of any of the following types:\n
offnonebuiltin\n
\nBoth cache types can be used simultaneously, for example:\n
\nssl_session_cache builtin:1000 shared:SSL:10m;\n
\nbut using only shared cache without the built-in cache should\nbe more efficient.\n
| \n Syntax:\n | \n\n ssl_session_ticket_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.5.7.\n
\nSets a file with the secret key used to encrypt\nand decrypt TLS session tickets.\nThe directive is necessary if the same key has to be shared between\nmultiple servers.\nBy default, a randomly generated key is used.\n
\nIf several keys are specified, only the first key is\nused to encrypt TLS session tickets.\nThis allows configuring key rotation, for example:\n
\nssl_session_ticket_key current.key;\nssl_session_ticket_key previous.key;\n
\n
\nThe file must contain 80 or 48 bytes\nof random data and can be created using the following command:\n
\nopenssl rand 80 > ticket.key\n
\nDepending on the file size either AES256 (for 80-byte keys, 1.11.8)\nor AES128 (for 48-byte keys) is used for encryption.\n
| \n Syntax:\n | \n\n ssl_session_tickets \n | \n
|---|---|
| \n Default:\n | \n\n ssl_session_tickets on;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.5.9.\n
\nEnables or disables session resumption through\nTLS session tickets.\n
| \n Syntax:\n | \n\n ssl_session_timeout \n | \n
|---|---|
| \n Default:\n | \n\n ssl_session_timeout 5m;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSpecifies a time during which a client may reuse the\nsession parameters.\n
| \n Syntax:\n | \n\n ssl_stapling \n | \n
|---|---|
| \n Default:\n | \n\n ssl_stapling off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.3.7.\n
\nEnables or disables\nstapling\nof OCSP responses by the server.\nExample:\n
\nssl_stapling on;\nresolver 192.0.2.1;\n
\n
\nFor the OCSP stapling to work, the certificate of the server certificate\nissuer should be known.\nIf the ssl_certificate file does\nnot contain intermediate certificates,\nthe certificate of the server certificate issuer should be\npresent in the\nssl_trusted_certificate file.\n
\nFor a resolution of the OCSP responder hostname,\nthe resolver directive\nshould also be specified.\n
| \n Syntax:\n | \n\n ssl_stapling_file \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.3.7.\n
\nWhen set, the stapled OCSP response will be taken from the\nspecified file instead of querying\nthe OCSP responder specified in the server certificate.\n
\nThe file should be in the DER format as produced by the\n“openssl ocsp” command.\n
| \n Syntax:\n | \n\n ssl_stapling_responder \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.3.7.\n
\nOverrides the URL of the OCSP responder specified in the\n“Authority\nInformation Access” certificate extension.\n
\nOnly “http://” OCSP responders are supported:\n
\nssl_stapling_responder http://ocsp.example.com/;\n
\n
| \n Syntax:\n | \n\n ssl_stapling_verify \n | \n
|---|---|
| \n Default:\n | \n\n ssl_stapling_verify off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.3.7.\n
\nEnables or disables verification of OCSP responses by the server.\n
\nFor verification to work, the certificate of the server certificate\nissuer, the root certificate, and all intermediate certificates\nshould be configured as trusted using the\nssl_trusted_certificate directive.\n
| \n Syntax:\n | \n\n ssl_trusted_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.3.7.\n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to verify client certificates and\nOCSP responses if ssl_stapling is enabled.\n
\nIn contrast to the certificate set by ssl_client_certificate,\nthe list of these certificates will not be sent to clients.\n
| \n Syntax:\n | \n\n ssl_verify_client \n \n | \n
|---|---|
| \n Default:\n | \n\n ssl_verify_client off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nEnables verification of client certificates.\nThe verification result is stored in the\n$ssl_client_verify variable.\n
\nThe optional parameter (0.8.7+) requests the client\ncertificate and verifies it if the certificate is present.\n
\nThe optional_no_ca parameter (1.3.8, 1.2.5)\nrequests the client\ncertificate but does not require it to be signed by a trusted CA certificate.\nThis is intended for the use in cases when a service that is external to nginx\nperforms the actual certificate verification.\nThe contents of the certificate is accessible through the\n$ssl_client_cert variable.\n
| \n Syntax:\n | \n\n ssl_verify_depth \n | \n
|---|---|
| \n Default:\n | \n\n ssl_verify_depth 1;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSets the verification depth in the client certificates chain.\n
\n\n\n\nThe ngx_http_ssl_module module supports several\nnon-standard error codes that can be used for redirects using the\nerror_page directive:\n
\n
\nThe redirection happens after the request is fully parsed and\nthe variables, such as $request_uri,\n$uri, $args and others, are available.\n
\nThe ngx_http_ssl_module module supports\nembedded variables:\n
$ssl_alpn_protocol$ssl_cipher$ssl_ciphers\n\nAES128-SHA:AES256-SHA:0x00ff\n
\nThe variable is fully supported only when using OpenSSL version 1.0.2 or higher.\nWith older versions, the variable is available\nonly for new sessions and lists only known ciphers.\n\n
$ssl_client_escaped_cert$ssl_client_cert\nThe variable is deprecated,\nthe $ssl_client_escaped_cert variable should be used instead.\n\n$ssl_client_fingerprint$ssl_client_i_dn$ssl_client_i_dn_legacy\nPrior to version 1.11.6, the variable name was $ssl_client_i_dn.\n\n$ssl_client_raw_cert\n$ssl_client_s_dn$ssl_client_s_dn_legacy\nPrior to version 1.11.6, the variable name was $ssl_client_s_dn.\n\n$ssl_client_serial$ssl_client_sigalg\nThe variable is supported only when using OpenSSL version 3.5 or higher.\nWith older versions, the variable value will be an empty string.\n\n
\nThe variable is available only for new sessions.\n\n
$ssl_client_v_end$ssl_client_v_remain$ssl_client_v_start$ssl_client_verifySUCCESS”, “FAILED:reason”,\nand “NONE” if a certificate was not present;\n\nPrior to version 1.11.7, the “\nFAILED” result\ndid not contain thereasonstring.\n
$ssl_curve\n\nprime256v1\n
\nThe variable is supported only when using OpenSSL version 3.0 or higher.\nWith older versions, the variable value will be an empty string.\n\n
$ssl_curves\n\n0x001d:prime256v1:secp521r1:secp384r1\n
\nThe variable is supported only when using OpenSSL version 1.0.2 or higher.\nWith older versions, the variable value will be an empty string.\n\n
\nThe variable is available only for new sessions.\n\n
$ssl_early_data1” if\nTLS 1.3 early data is used\nand the handshake is not complete, otherwise “” (1.15.3).\n$ssl_ech_outer_server_name$ssl_ech_statusFAILED”,\n“BACKEND”,\n“GREASE”,\n“SUCCESS”, or\n“NOT_TRIED” (1.29.4);\n\nThe variable is currently supported only when using OpenSSL\nECH feature branch\nand is therefore subject to change.\nThe variable value will otherwise be an empty string.\n\n
$ssl_protocol$ssl_server_name$ssl_session_id$ssl_session_reusedr” if an SSL session was reused,\nor “.” otherwise (1.5.11).\n$ssl_sigalg\nThe variable is supported only when using OpenSSL version 3.5 or higher.\nWith older versions, the variable value will be an empty string.\n\n
\nThe variable is available only for new sessions.\n\n
\n
\n\n| Example Configuration Directives status status_format status_zone Data Compatibility |
\nThe ngx_http_status_module module provides\naccess to various status information.\n
\nThis module was available as part of our\ncommercial subscription\nuntil 1.13.10.\nIt was superseded by the\nngx_http_api_module module\nin 1.13.3.\n
\n
\n\n\n\n
\nhttp {\n upstream backend {\n zone http_backend 64k;\n\n server backend1.example.com weight=5;\n server backend2.example.com;\n }\n\n proxy_cache_path /data/nginx/cache_backend keys_zone=cache_backend:10m;\n\n server {\n server_name backend.example.com;\n\n location / {\n proxy_pass http://backend;\n proxy_cache cache_backend;\n\n health_check;\n }\n\n status_zone server_backend;\n }\n\n server {\n listen 127.0.0.1;\n\n location /upstream_conf {\n upstream_conf;\n }\n\n location /status {\n status;\n }\n\n location = /status.html {\n }\n }\n}\n\nstream {\n upstream backend {\n zone stream_backend 64k;\n\n server backend1.example.com:12345 weight=5;\n server backend2.example.com:12345;\n }\n\n server {\n listen 127.0.0.1:12345;\n proxy_pass backend;\n status_zone server_backend;\n health_check;\n }\n}\n\n
\nExamples of status requests with this configuration:\n
\nhttp://127.0.0.1/status\nhttp://127.0.0.1/status/nginx_version\nhttp://127.0.0.1/status/caches/cache_backend\nhttp://127.0.0.1/status/upstreams\nhttp://127.0.0.1/status/upstreams/backend\nhttp://127.0.0.1/status/upstreams/backend/peers/1\nhttp://127.0.0.1/status/upstreams/backend/peers/1/weight\nhttp://127.0.0.1/status/stream\nhttp://127.0.0.1/status/stream/upstreams\nhttp://127.0.0.1/status/stream/upstreams/backend\nhttp://127.0.0.1/status/stream/upstreams/backend/peers/1\nhttp://127.0.0.1/status/stream/upstreams/backend/peers/1/weight\n
\n
\nThe simple monitoring page is shipped with this distribution,\naccessible as “/status.html” in the default configuration.\nIt requires the locations “/status” and\n“/status.html” to be configured as shown above.\n
| \n Syntax:\n | \n\n status;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nThe status information will be accessible from the surrounding location.\nAccess to this location should be\nlimited.\n
| \n Syntax:\n | \n\n status_format status_format \n | \n
|---|---|
| \n Default:\n | \n\n status_format json;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nBy default, status information is output in the JSON format.\n
\nAlternatively, data may be output as JSONP.\nThe callback parameter specifies the name of a callback function.\nParameter value can contain variables.\nIf parameter is omitted, or the computed value is an empty string,\nthen “ngx_status_jsonp_callback” is used.\n
| \n Syntax:\n | \n\n status_zone \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server\n | \n
\nEnables collection of virtual\nhttp\nor\nstream\n(1.7.11) server status information in the specified zone.\nSeveral servers may share the same zone.\n
\nThe following status information is provided:\n
versionnginx_versionnginx_buildaddressgenerationload_timestamptimestamppidppidprocessesrespawnedconnectionsaccepteddroppedactiveidlesslhandshakeshandshakes_failedsession_reusesrequeststotalcurrentserver_zonesprocessingrequestsresponsestotal1xx,\n2xx,\n3xx,\n4xx,\n5xx\ndiscardedreceivedsentslabspagesusedfreeslotsusedfreereqsfailsupstreamspeersidservernameservicebackupweightstateup”,\n“draining”,\n“down”,\n“unavail”,\n“checking”,\nor\n“unhealthy”.\nactivemax_connsrequestsresponsestotal1xx,\n2xx,\n3xx,\n4xx,\n5xx\nsentreceivedfailsunavailunavail”)\ndue to the number of unsuccessful attempts reaching the\nmax_fails\nthreshold.\nhealth_checkschecksfailsunhealthyunhealthy”).\nlast_passeddowntimeunavail”,\n“checking”, and “unhealthy” states.\ndownstartunavail”,\n“checking”, or “unhealthy”.\nselectedheader_timeresponse_timekeepalivezombieszonequeuesizemax_sizeoverflowscachessizemax_sizecoldhit,\n stale,\n updating,\n revalidated\nresponsesbytesmiss,\n expired,\n bypass\nresponsesbytesresponses_writtenbytes_writtenstreamserver_zonesprocessingconnectionssessionstotal2xx,\n4xx,\n5xx\ndiscardedreceivedsentupstreamspeersidservernameservicebackupweightstateup”,\n“down”,\n“unavail”,\n“checking”,\nor\n“unhealthy”.\nactivemax_connsconnectionsconnect_timefirst_byte_timeresponse_timesentreceivedfailsunavailunavail”)\ndue to the number of unsuccessful attempts reaching the\nmax_fails\nthreshold.\nhealth_checkschecksfailsunhealthyunhealthy”).\nlast_passeddowntimeunavail”,\n“checking”, and “unhealthy” states.\ndownstartunavail”,\n“checking”, or “unhealthy”.\nselectedzombieszone\n
\n\n\n
keepalive field of an upstream server\nwas removed in version 5.\nrevalidated field in\ncaches\nwas added in version 3.\n\n
\n\n| Example Configuration Directives stub_status Data Embedded Variables |
\nThe ngx_http_stub_status_module module provides\naccess to basic status information.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_stub_status_module\nconfiguration parameter.\n
\n
\nlocation = /basic_status {\n stub_status;\n}\n\nThis configuration creates a simple web page\nwith basic status data which may look like as follows:\n
\nActive connections: 291\nserver accepts handled requests\n 16630948 16630948 31070465\nReading: 6 Writing: 179 Waiting: 106\n
\n
\n\n\n| \n Syntax:\n | \n\n stub_status;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server, location\n | \n
\nThe basic status information will be accessible from the surrounding location.\n
\n
\nIn versions prior to 1.7.5,\nthe directive syntax required an arbitrary argument, for example,\n“stub_status on”.\n\n
\n\n\n\nThe following status information is provided:\n
Active connectionsWaiting connections.\nacceptshandledaccepts\nunless some resource limits have been reached\n(for example, the\nworker_connections limit).\nrequestsReadingWritingWaiting\n
\n\n\n\nThe ngx_http_stub_status_module module\nsupports the following embedded variables (1.3.14):\n
$connections_activeActive connections value;\n$connections_readingReading value;\n$connections_writingWriting value;\n$connections_waitingWaiting value.\n\n
\n\n| Example Configuration Directives sub_filter sub_filter_last_modified sub_filter_once sub_filter_types |
\nThe ngx_http_sub_module module is a filter\nthat modifies a response by replacing one specified string by another.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_sub_module\nconfiguration parameter.\n
\n
\nlocation / {\n sub_filter '<a href=\"http://127.0.0.1:8080/' '<a href=\"https://$host/';\n sub_filter '<img src=\"http://127.0.0.1:8080/' '<img src=\"https://$host/';\n sub_filter_once on;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n sub_filter \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a string to replace and a replacement string.\nThe string to replace is matched ignoring the case.\nThe string to replace (1.9.4) and replacement string can contain variables.\nSeveral sub_filter directives\ncan be specified on the same configuration level (1.9.4).\nThese directives are inherited from the previous configuration level\nif and only if there are no sub_filter directives\ndefined on the current level.\n
| \n Syntax:\n | \n\n sub_filter_last_modified \n | \n
|---|---|
| \n Default:\n | \n\n sub_filter_last_modified off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.1.\n
\nAllows preserving the “Last-Modified” header field\nfrom the original response during replacement\nto facilitate response caching.\n
\nBy default, the header field is removed as contents of the response\nare modified during processing.\n
| \n Syntax:\n | \n\n sub_filter_once \n | \n
|---|---|
| \n Default:\n | \n\n sub_filter_once on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIndicates whether to look for each string to replace\nonce or repeatedly.\n
| \n Syntax:\n | \n\n sub_filter_types \n | \n
|---|---|
| \n Default:\n | \n\n sub_filter_types text/html;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables string replacement in responses with the specified MIME types\nin addition to “text/html”.\nThe special value “*” matches any MIME type (0.8.29).\n
\nThe ngx_http_tunnel_module (1.31.0) handles HTTP/1.1\nCONNECT\nrequests and establishes an end-to-end virtual connection.\n
\n
\nhttp {\n\n map $request_port $allow_port {\n 443 1;\n }\n\n map $host $allow_host {\n hostnames;\n\n example.org 1;\n *.example.org 1;\n }\n\n server {\n listen 8000;\n\n resolver dns.example.com;\n\n if ($allow_port != 1) {\n return 502;\n }\n\n if ($allow_host != 1) {\n return 502;\n }\n\n tunnel_pass;\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n tunnel_allow_upstream \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines conditions under which access to the backend server\nis allowed or denied.\nIf all string parameters are not empty\nand not equal to “0” then the access is allowed.\nThe conditions are evaluated each time\nbefore a connection to a backend server is established.\nParameter values can contain variables:\n
\ngeo $upstream_last_addr $allow {\n volatile;\n 10.10.0.0/24 1;\n}\n\nserver {\n listen 127.0.0.1:8080;\n\n tunnel_pass;\n tunnel_allow_upstream $allow;\n}\n\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n tunnel_bind \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nMakes outgoing connections to a backend server originate\nfrom the specified local IP address with an optional port.\nParameter value can contain variables.\nThe special value off cancels the effect\nof the tunnel_bind directive\ninherited from the previous configuration level, which allows the\nsystem to auto-assign the local IP address and port.\n
| \n Syntax:\n | \n\n tunnel_bind_dynamic \n | \n
|---|---|
| \n Default:\n | \n\n tunnel_bind_dynamic off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nWhen enabled, makes the tunnel_bind operation\nat each connection attempt:\n
\ngeo $upstream_last_addr $bind_addr {\n volatile;\n 10.0.0.0/24 10.0.0.1;\n 192.168.0.0/24 192.168.0.1;\n}\n\ntunnel_bind $bind_addr;\ntunnel_bind_dynamic on;\n\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n tunnel_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n tunnel_buffer_size 16k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the size of the buffer used for reading data\nfrom the backend server.\nAlso sets the size of the buffer used for reading data\nfrom the client.\n
| \n Syntax:\n | \n\n tunnel_connect_timeout \n | \n
|---|---|
| \n Default:\n | \n\n tunnel_connect_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a timeout for establishing a connection with a backend server.\nIt should be noted that this timeout cannot usually exceed 75 seconds.\n
| \n Syntax:\n | \n\n tunnel_next_upstream \n \n | \n
|---|---|
| \n Default:\n | \n\n tunnel_next_upstream error timeout;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies in which cases a request should be passed to the next server:\n
errortimeoutdenied\n
\nThis parameter is available as part of our\ncommercial subscription.\n
\n
\noff\n
\nOne should bear in mind that passing a request to the next server is\nonly possible if nothing has been sent to a client yet.\nThat is, if an error or timeout occurs in the middle of the\ntransferring of a response, fixing this is impossible.\n
\nThe directive also defines what is considered an\nunsuccessful\nattempt of communication with a server.\nThe cases of error, timeout,\nand denied\nare always considered unsuccessful attempts,\neven if they are not specified in the directive.\n
\nPassing a request to the next server can be limited by\nthe number of tries\nand by time.\n
| \n Syntax:\n | \n\n tunnel_next_upstream_timeout \n | \n
|---|---|
| \n Default:\n | \n\n tunnel_next_upstream_timeout 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nLimits the time during which a request can be passed to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n tunnel_next_upstream_tries \n | \n
|---|---|
| \n Default:\n | \n\n tunnel_next_upstream_tries 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nLimits the number of possible tries for passing a request to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n tunnel_pass [\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server, location, if in location\n | \n
\nEnables handling of CONNECT requests and sets the address of a backend server.\nBy default, the address is\n$host:$request_port and is taken from the client request.\nIn most cases, tunnel_pass does not require\nconfiguring any arguments.\n
\nThe address can be specified as a domain name or IP address,\nand a port:\n
\ntunnel_pass localhost:9000;\n
\nor as a UNIX-domain socket path:\n
\ntunnel_pass unix:/tmp/backend.socket;\n
\n
\nIf a domain name resolves to several addresses, all of them will be\nused in a round-robin fashion.\nIn addition, an address can be specified as a\nserver group.\n
\nParameter value can contain variables.\nIn this case, if an address is specified as a domain name,\nthe name is searched among the described\nserver groups,\nand, if not found, is determined using a\nresolver.\n
| \n Syntax:\n | \n\n tunnel_read_timeout \n | \n
|---|---|
| \n Default:\n | \n\n tunnel_read_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the timeout between two successive read or write operations\non client or backend server connections. \nIf no data is transmitted within this time, the connection is closed.\n
| \n Syntax:\n | \n\n tunnel_send_lowat \n | \n
|---|---|
| \n Default:\n | \n\n tunnel_send_lowat 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIf the directive is set to a non-zero value, nginx will try to\nminimize the number\nof send operations on outgoing connections to a backend server by using either\nNOTE_LOWAT flag of the\nkqueue method,\nor the SO_SNDLOWAT socket option,\nwith the specified size.\n
\nThis directive is ignored on Linux, Solaris, and Windows.\n
| \n Syntax:\n | \n\n tunnel_send_timeout \n | \n
|---|---|
| \n Default:\n | \n\n tunnel_send_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a timeout for transmitting a request to the backend server.\nThe timeout is set only between two successive write operations,\nnot for the transmission of the whole request.\nIf the backend server does not receive anything within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n tunnel_socket_keepalive \n | \n
|---|---|
| \n Default:\n | \n\n tunnel_socket_keepalive off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nConfigures the “TCP keepalive” behavior\nfor outgoing connections to a backend server.\nBy default, the operating system’s settings are in effect for the socket.\nIf the directive is set to the value “on”, the\nSO_KEEPALIVE socket option is turned on for the socket.\n
| Example Configuration Directives upstream_conf |
\nThe ngx_http_upstream_conf_module module\nallows configuring upstream server groups on-the-fly\nvia a simple HTTP interface without the need of restarting nginx.\nThe\nhttp\nor\nstream\nserver group must reside in the shared memory.\n
\nThis module was available as part of our\ncommercial subscription\nuntil 1.13.10.\nIt was superseded by the\nngx_http_api_module module\nin 1.13.3.\n
\n
\n\n\n\n
\nupstream backend {\n zone upstream_backend 64k;\n\n ...\n}\n\nserver {\n location /upstream_conf {\n upstream_conf;\n allow 127.0.0.1;\n deny all;\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n upstream_conf;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nTurns on the HTTP interface of upstream configuration in the surrounding\nlocation.\nAccess to this location should be\nlimited.\n
\nConfiguration commands can be used to:\n
\n
\nSince addresses in a group are not required to be unique, specific\nservers in a group are referenced by their IDs.\nIDs are assigned automatically and shown when adding a new server\nor viewing the group configuration.\n
\n
\nA configuration command consists of parameters passed as request arguments,\nfor example:\n
\nhttp://127.0.0.1/upstream_conf?upstream=backend\n
\n
\nThe following parameters are supported:\n\n
stream=upstream=nameid=numberremove=add=backup=\nBefore version 1.7.2, backup=\nwas also required to view, modify, or remove existing backup servers.\n\nserver=addressaddress” parameter\nof the\nhttp\nor\nstream\nupstream server.\n\nWhen adding a server, it is possible to specify it as a domain name.\nIn this case, changes of the IP addresses that correspond to a domain name\nwill be monitored and automatically applied to the upstream\nconfiguration without the need of restarting nginx (1.7.2).\nThis requires the “resolver” directive in the\nhttp\nor\nstream\nblock.\nSee also the “resolve” parameter\nof the\nhttp\nor\nstream\nupstream server.\n
service=nameservice” parameter\nof the\nhttp\nor\nstream\nupstream server (1.9.13).\nweight=numberweight” parameter\nof the\nhttp\nor\nstream\nupstream server.\nmax_conns=numbermax_conns” parameter\nof the\nhttp\nor\nstream\nupstream server.\nmax_fails=numbermax_fails” parameter\nof the\nhttp\nor\nstream\nupstream server.\nfail_timeout=timefail_timeout” parameter\nof the\nhttp\nor\nstream\nupstream server.\nslow_start=timeslow_start” parameter\nof the\nhttp\nor\nstream\nupstream server.\ndown=down” parameter\nof the\nhttp\nor\nstream\nupstream server.\ndrain=up=down” parameter\nof the\nhttp\nor\nstream\nupstream server.\nroute=stringroute” parameter of the\nhttp\nupstream server.\n\n\nThe first three parameters select an object.\nThis can be either the whole http or stream upstream server group,\nor a specific server.\nWithout other parameters, the configuration of the selected\ngroup or server is shown.\n
\nFor example, to view the configuration of the whole group, send:\n
\nhttp://127.0.0.1/upstream_conf?upstream=backend\n
\n\nTo view the configuration of a specific server, also specify its ID:\n
\nhttp://127.0.0.1/upstream_conf?upstream=backend&id=42\n
\n
\nTo add a new server,\nspecify its address in the “server=” parameter.\nWithout other parameters specified, a server will be added with other\nparameters set to their default values (see the\nhttp\nor\nstream\n“server” directive).\n
\nFor example, to add a new primary server, send:\n
\nhttp://127.0.0.1/upstream_conf?add=&upstream=backend&server=127.0.0.1:8080\n
\n\nTo add a new backup server, send:\n
\nhttp://127.0.0.1/upstream_conf?add=&upstream=backend&backup=&server=127.0.0.1:8080\n
\n\nTo add a new primary server,\nset its parameters to non-default values\nand mark it as “down”, send:\n
\nhttp://127.0.0.1/upstream_conf?add=&upstream=backend&server=127.0.0.1:8080&weight=2&down=\n
\n\nTo remove a server, specify its ID:\n
\nhttp://127.0.0.1/upstream_conf?remove=&upstream=backend&id=42\n
\n\nTo mark an existing server as “down”, send:\n
\nhttp://127.0.0.1/upstream_conf?upstream=backend&id=42&down=\n
\n\nTo modify the address of an existing server, send:\n
\nhttp://127.0.0.1/upstream_conf?upstream=backend&id=42&server=192.0.2.3:8123\n
\n\nTo modify other parameters of an existing server, send:\n
\nhttp://127.0.0.1/upstream_conf?upstream=backend&id=42&max_fails=3&weight=4\n
\n\nThe above examples are for an\nhttp\nupstream server group.\nSimilar examples for a\nstream\nupstream server group require the “stream=” parameter.\n
| Example Configuration Directives health_check match |
\nThe ngx_http_upstream_hc_module module\nallows enabling periodic health checks of the servers in a\ngroup\nreferenced in the surrounding location.\nThe server group must reside in the\nshared memory.\n
\nIf a health check fails,\nthe server will be considered unhealthy.\nIf several health checks are defined for the same group of servers,\na single failure of any check will make the corresponding server be\nconsidered unhealthy.\nClient requests are not passed to unhealthy servers\nand servers in the “checking” state.\n
\n
\nPlease note that most of the variables will have empty values\nwhen used with health checks.\n
\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nupstream dynamic {\n zone upstream_dynamic 64k;\n\n server backend1.example.com weight=5;\n server backend2.example.com:8080 fail_timeout=5s slow_start=30s;\n server 192.0.2.1 max_fails=3;\n\n server backup1.example.com:8080 backup;\n server backup2.example.com:8080 backup;\n}\n\nserver {\n location / {\n proxy_pass http://dynamic;\n health_check;\n }\n}\n \nWith this configuration, nginx will send “/” requests to each\nserver in the backend group every five seconds.\nIf any communication error or timeout occurs, or a\nproxied server responds with the status code other than\n2xx or 3xx, the health check will fail, and the server will\nbe considered unhealthy.\n
\nHealth checks can be configured to test the status code of a response,\npresence of certain header fields and their values,\nand the body contents.\nTests are configured separately using the match directive\nand referenced in the match parameter\nof the health_check directive:\n
\nhttp {\n server {\n ...\n location / {\n proxy_pass http://backend;\n health_check match=welcome;\n }\n }\n\n match welcome {\n status 200;\n header Content-Type = text/html;\n body ~ \"Welcome to nginx!\";\n }\n}\n \nThis configuration shows that in order for a health check to pass, the response\nto a health check request should succeed, have status 200,\nand contain “Welcome to nginx!” in the body.\n
| \n Syntax:\n | \n\n health_check [\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nEnables periodic health checks of the servers in a\ngroup\nreferenced in the surrounding location.\n
\nThe following optional parameters are supported:\n
interval=time\njitter=time\nfails=number\npasses=number\nuri=uri\n/”.\nmandatory [persistent]\n\nsets the initial “checking” state for a server\nuntil the first health check is completed (1.11.7).\nClient requests are not passed to servers in the “checking” state.\nIf the parameter is not specified,\nthe server will be initially considered healthy.\n
\n\n\nThe persistent parameter (1.19.7)\nsets the initial “up” state for a server after reload\nif the server was considered healthy before reload.\n
match=name\nmatch block configuring the tests that a\nresponse should pass in order for a health check to pass.\nBy default, the response should have status code 2xx or 3xx.\nport=number\ntype=grpc\n[grpc_service=name]\n[grpc_status=code]\ngrpc_service parameter (1.19.5).\nIf the server does not support the gRPC Health Checking Protocol,\nthe optional grpc_status parameter can be used\nto specify non-zero gRPC\nstatus\n(for example,\nstatus code “12” / “UNIMPLEMENTED”)\nthat will be treated as healthy:\n\nThe\nhealth_check mandatory type=grpc grpc_status=12;\n
type=grpc parameter\nmust be specified after all other directive parameters,\ngrpc_service and grpc_status\nmust follow type=grpc.\nThe parameter is not compatible with\nuri or\nmatch parameters.\nkeepalive_time=time\n\n
| \n Syntax:\n | \n\n match \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nDefines the named test set used to verify responses to health check requests.\n
\nThe following items can be tested in a response:\n
status 200;status ! 500;status 200 204;status ! 301 302;status 200-399;status ! 400-599;status 301-303 307;\n\n
header Content-Type = text/html;text/html\nheader Content-Type != text/html;text/html\nheader Connection ~ close;close\nheader Connection !~ close;close\nheader Host;header ! X-Accel-Redirect;\n\n
body ~ \"Welcome to nginx!\";Welcome to nginx!”\nbody !~ \"Welcome to nginx!\";Welcome to nginx!”\n\n\n
require\n $variable\n ...;\n
\nIf several tests are specified,\nthe response matches only if it matches all tests.\n
\nOnly the first 256k of the response body are examined.\n
\n
\nExamples:\n
\n# status is 200, content type is \"text/html\",\n# and body contains \"Welcome to nginx!\"\nmatch welcome {\n status 200;\n header Content-Type = text/html;\n body ~ \"Welcome to nginx!\";\n}\n\n\n
\n# status is not one of 301, 302, 303, or 307, and header does not have \"Refresh:\"\nmatch not_redirect {\n status ! 301-303 307;\n header ! Refresh;\n}\n\n\n
\n# status ok and not in maintenance mode\nmatch server_ok {\n status 200-399;\n body !~ \"maintenance mode\";\n}\n\n\n
\n# status is 200 or 204\nmap $upstream_status $good_status {\n 200 1;\n 204 1;\n}\n\nmatch server_ok {\n require $good_status;\n}\n\n\n
\n\n\nThe ngx_http_upstream_module module\nis used to define groups of servers that can be referenced\nby the proxy_pass,\nfastcgi_pass,\nuwsgi_pass,\nscgi_pass,\nmemcached_pass, and\ngrpc_pass directives.\n
\n
\nupstream backend {\n server backend1.example.com weight=5;\n server backend2.example.com:8080;\n server unix:/tmp/backend3;\n\n server backup1.example.com:8080 backup;\n server backup2.example.com:8080 backup;\n}\n\nserver {\n location / {\n proxy_pass http://backend;\n }\n}\n\n
\nDynamically configurable group with\nperiodic health checks is\navailable as part of our\ncommercial subscription:\n
\nresolver 10.0.0.1;\n\nupstream dynamic {\n zone upstream_dynamic 64k;\n\n server backend1.example.com weight=5;\n server backend2.example.com:8080 fail_timeout=5s slow_start=30s;\n server 192.0.2.1 max_fails=3;\n server backend3.example.com resolve;\n server backend4.example.com service=http resolve;\n\n server backup1.example.com:8080 backup;\n server backup2.example.com:8080 backup;\n}\n\nserver {\n location / {\n proxy_pass http://dynamic;\n health_check;\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n upstream \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nDefines a group of servers.\nServers can listen on different ports.\nIn addition, servers listening on TCP and UNIX-domain sockets\ncan be mixed.\n
\nExample:\n
\nupstream backend {\n server backend1.example.com weight=5;\n server 127.0.0.1:8080 max_fails=3 fail_timeout=30s;\n server unix:/tmp/backend3;\n\n server backup1.example.com backup;\n}\n\n
\nBy default, requests are distributed between the servers using a\nweighted round-robin balancing method.\nIn the above example, each 7 requests will be distributed as follows:\n5 requests go to backend1.example.com\nand one request to each of the second and third servers.\nIf an error occurs during communication with a server, the request will\nbe passed to the next server, and so on until all of the functioning\nservers will be tried.\nIf a successful response could not be obtained from any of the servers,\nthe client will receive the result of the communication with the last server.\n
| \n Syntax:\n | \n\n server \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
\nDefines the address and other parameters\nof a server.\nThe address can be specified as a domain name or IP address,\nwith an optional port, or as a UNIX-domain socket path\nspecified after the “unix:” prefix.\nIf a port is not specified, the port 80 is used.\nA domain name that resolves to several IP addresses defines\nmultiple servers at once.\n
\nThe following parameters can be defined:\n
weight=number\nmax_conns=number\nnumber of simultaneous active\nconnections to the proxied server (1.11.5).\nDefault value is zero, meaning there is no limit.\nIf the server group does not reside in the shared memory,\nthe limitation works per each worker process.\n\nIf idle keepalive connections,\nmultiple workers,\nand the shared memory are enabled,\nthe total number of active and idle connections to the proxied server\nmay exceed the max_conns value.\n\n\nSince version 1.5.9 and prior to version 1.11.5,\nthis parameter was available as part of our\ncommercial subscription.\n\n
max_fails=number\nfail_timeout\nparameter to consider the server unavailable for a duration also set by the\nfail_timeout parameter.\nBy default, the number of unsuccessful attempts is set to 1.\nThe zero value disables the accounting of attempts.\nWhat is considered an unsuccessful attempt is defined by the\nproxy_next_upstream,\nfastcgi_next_upstream,\nuwsgi_next_upstream,\nscgi_next_upstream,\nmemcached_next_upstream, and\ngrpc_next_upstream\ndirectives.\nfail_timeout=time\nbackup\n\nThe parameter cannot be used along with the\nhash, ip_hash, and random\nload balancing methods.\n\n
down\nresolve\n\nIn order for this parameter to work,\nthe resolver directive\nmust be specified in the\nhttp block\nor in the corresponding upstream block.\n
\n
\nPrior to version 1.27.3, this parameter was available only as part of our\ncommercial subscription.\n
\n
\nservice=name\nname (1.9.13).\nIn order for this parameter to work, it is necessary to specify\nthe resolve parameter for the server\nand specify a hostname without a port number.\n\nIf the service name does not contain a dot (“.”), then\nthe RFC-compliant name\nis constructed\nand the TCP protocol is added to the service prefix.\nFor example, to look up the\n_http._tcp.backend.example.com SRV record,\nit is necessary to specify the directive:\n
\nserver backend.example.com service=http resolve;\n
\nIf the service name contains one or more dots, then the name is constructed\nby joining the service prefix and the server name.\nFor example, to look up the _http._tcp.backend.example.com\nand server1.backend.example.com SRV records,\nit is necessary to specify the directives:\n
\nserver backend.example.com service=_http._tcp resolve;\nserver example.com service=server1.backend resolve;\n
\n
\n\n\nHighest-priority SRV records\n(records with the same lowest-number priority value)\nare resolved as primary servers,\nthe rest of SRV records are resolved as backup servers.\nIf the backup parameter is specified for the server,\nhigh-priority SRV records are resolved as backup servers,\nthe rest of SRV records are ignored.\n
\n\n\n
\nPrior to version 1.27.3, this parameter was available only as part of our\ncommercial subscription.\n
\n
\nroute=string\n\n
\nPrior to version 1.29.6,\nthis parameter was available only as part of our\ncommercial subscription.\n
\n
\ndrain\n\nPrior to version 1.13.6,\nthe parameter could be changed only with the\nAPI module.\n\n
\nPrior to version 1.29.6,\nthe parameter was available only as part of our\ncommercial subscription.\n\n
\n
\nAdditionally,\nthe following parameters are available as part of our\ncommercial subscription:\n
slow_start=time\ntime during which the server will recover its weight\nfrom zero to a nominal value, when unhealthy server becomes\nhealthy,\nor when the server becomes available after a period of time\nit was considered unavailable.\nDefault value is zero, i.e. slow start is disabled.\n\nThe parameter cannot be used along with the\nhash, ip_hash, and random\nload balancing methods.\n\n
\n
\n
\nIf there is only a single server in a group,max_fails,\nfail_timeoutandslow_startparameters\nare ignored, and such a server will never be considered unavailable.\n
\n
| \n Syntax:\n | \n\n zone \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.9.0.\n
\nDefines the name and size of the shared\nmemory zone that keeps the group’s configuration and run-time state that are\nshared between worker processes.\nSeveral groups may share the same zone.\nIn this case, it is enough to specify the size only once.\n
\nAdditionally,\nas part of our commercial subscription,\nsuch groups allow changing the group membership\nor modifying the settings of a particular server\nwithout the need of restarting nginx.\nThe configuration is accessible via the\nAPI module (1.13.3).\n
\nPrior to version 1.13.3,\nthe configuration was accessible only via a special location\nhandled by\nupstream_conf.\n
\n
| \n Syntax:\n | \n\n state \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.9.7.\n
\nSpecifies a file that keeps the state\nof the dynamically configurable group.\n
\nExamples:\n
\nstate /var/lib/nginx/state/servers.conf; # path for Linux\nstate /var/db/nginx/state/servers.conf; # path for FreeBSD\n
\n
\nThe state is currently limited to the list of servers with their parameters.\nThe file is read when parsing the configuration and is updated each time\nthe upstream configuration is\nchanged.\nChanging the file content directly should be avoided.\nThe directive cannot be used\nalong with the server directive.\n
\n
\nChanges made during\nconfiguration reload\nor binary upgrade\ncan be lost.\n
\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n hash \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.7.2.\n
\nSpecifies a load balancing method for a server group\nwhere the client-server mapping is based on the hashed key value.\nThe key can contain text, variables, and their combinations.\nNote that adding or removing a server from the group\nmay result in remapping most of the keys to different servers.\nThe method is compatible with the\nCache::Memcached\nPerl library.\n
\nIf the consistent parameter is specified,\nthe ketama\nconsistent hashing method will be used instead.\nThe method ensures that only a few keys\nwill be remapped to different servers\nwhen a server is added to or removed from the group.\nThis helps to achieve a higher cache hit ratio for caching servers.\nThe method is compatible with the\nCache::Memcached::Fast\nPerl library with the ketama_points parameter set to 160.\n
| \n Syntax:\n | \n\n ip_hash;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
\nSpecifies that a group should use a load balancing method where requests\nare distributed between servers based on client IP addresses.\nThe first three octets of the client IPv4 address, or the entire IPv6 address,\nare used as a hashing key.\nThe method ensures that requests from the same client will always be\npassed to the same server except when this server is unavailable.\nIn the latter case client requests will be passed to another server.\nMost probably, it will always be the same server as well.\n
\nIPv6 addresses are supported starting from versions 1.3.2 and 1.2.2.\n
\n
\nIf one of the servers needs to be temporarily removed, it should\nbe marked with the down parameter in\norder to preserve the current hashing of client IP addresses.\n
\nExample:\n
\nupstream backend {\n ip_hash;\n\n server backend1.example.com;\n server backend2.example.com;\n server backend3.example.com down;\n server backend4.example.com;\n}\n\n
\n
\nUntil versions 1.3.1 and 1.2.2, it was not possible to specify a weight for\nservers using the ip_hash load balancing method.\n\n
| \n Syntax:\n | \n\n keepalive \n | \n
|---|---|
| \n Default:\n | \n\n keepalive 32 local;\n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.1.4.\n
\nEnables or disables caching of keepalive connections to upstream servers.\nSince 1.29.7, by default the cache for connections is activated\nand these connections are not\nshared between different\nlocations.\n
\nThe local parameter (1.29.7) disables sharing of\ncached keepalive connections across different locations\neven if the upstream server address matches.\nIf the local parameter is not specified,\nany matching cached connection to the same upstream server\ncan be reused regardless of a location.\n
\nThe connections parameter sets the maximum number of\nidle keepalive connections to upstream servers that are preserved in\nthe cache of each worker process.\nWhen this number is exceeded, the least recently used connections\nare closed.\nThe zero value disables keepalive connections to upstream servers.\n
\nSince 1.29.7, keepalive connections are enabled by default, with a\ndefault limit of 32 connections per each worker process.\n\n
\nIt should be particularly noted that thekeepalivedirective\ndoes not limit the total number of connections to upstream servers\nthat an nginx worker process can open.\nTheconnectionsparameter should be set to a number small enough\nto let upstream servers process new incoming connections as well.\n
\n\n
\nBefore 1.29.7, when using load balancing methods other than the default\nround-robin method, it was necessary to activate them before\nthe keepalive directive.\n\n
\nExample configuration of memcached upstream with keepalive connections:\n
\nupstream memcached_backend {\n server 127.0.0.1:11211;\n server 10.0.0.2:11211;\n\n keepalive 32;\n}\n\nserver {\n ...\n\n location /memcached/ {\n set $memcached_key $uri;\n memcached_pass memcached_backend;\n }\n\n}\n\n
\nFor HTTP, the proxy_http_version\ndirective should be “1.1” (by default since 1.29.7)\nor set to “2”\nand the “Connection” header field should be cleared.\nThis example is for versions prior to 1.29.7:\n
\nupstream http_backend {\n server 127.0.0.1:8080;\n\n keepalive 16;\n}\n\nserver {\n ...\n\n location /http/ {\n proxy_pass http://http_backend;\n # proxy_http_version 1.1; # before version 1.29.7\n # proxy_set_header Connection \"\"; # before version 1.29.7\n ...\n }\n}\n\n
\n
\nAlternatively, HTTP/1.0 persistent connections can be used by passing the\n“Connection: Keep-Alive” header field to an upstream server,\nthough this method is not recommended.\n
\n
\nFor FastCGI servers, it is required to set\nfastcgi_keep_conn\nfor keepalive connections to work:\n
\nupstream fastcgi_backend {\n server 127.0.0.1:9000;\n\n keepalive 8;\n}\n\nserver {\n ...\n\n location /fastcgi/ {\n fastcgi_pass fastcgi_backend;\n fastcgi_keep_conn on;\n ...\n }\n}\n\n
\n
\nSCGI and uwsgi protocols do not have a notion of keepalive connections.\n
\n
| \n Syntax:\n | \n\n keepalive_requests \n | \n
|---|---|
| \n Default:\n | \n\n keepalive_requests 1000;\n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.15.3.\n
\nSets the maximum number of requests that can be\nserved through one keepalive connection.\nAfter the maximum number of requests is made, the connection is closed.\n
\nClosing connections periodically is necessary to free\nper-connection memory allocations.\nTherefore, using too high maximum number of requests\ncould result in excessive memory usage and not recommended.\n
\n
\nPrior to version 1.19.10, the default value was 100.\n
\n
| \n Syntax:\n | \n\n keepalive_time \n | \n
|---|---|
| \n Default:\n | \n\n keepalive_time 1h;\n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.19.10.\n
\nLimits the maximum time during which\nrequests can be processed through one keepalive connection.\nAfter this time is reached, the connection is closed\nfollowing the subsequent request processing.\n
| \n Syntax:\n | \n\n keepalive_timeout \n | \n
|---|---|
| \n Default:\n | \n\n keepalive_timeout 60s;\n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.15.3.\n
\nSets a timeout during which an idle keepalive\nconnection to an upstream server will stay open.\n
| \n Syntax:\n | \n\n ntlm;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.9.2.\n
\nAllows proxying requests with\nNTLM\nAuthentication.\nThe upstream connection is bound to the client connection\nonce the client sends a request with the “Authorization”\nheader field value\nstarting with “Negotiate” or “NTLM”.\nFurther client requests will be proxied through the same upstream connection,\nkeeping the authentication context.\n
\nIn order for NTLM authentication to work,\nit is necessary to enable keepalive connections to upstream servers.\nThe proxy_http_version\ndirective should be “1.1” (by default since 1.29.7)\nor set to “2”\nand the “Connection” header field should be cleared.\nThis example is for versions prior to 1.29.7:\n
\nupstream http_backend {\n server 127.0.0.1:8080;\n\n ntlm;\n}\n\nserver {\n ...\n\n location /http/ {\n proxy_pass http://http_backend;\n # proxy_http_version 1.1; # before version 1.29.7\n # proxy_set_header Connection \"\"; # before version 1.29.7\n ...\n }\n}\n\n
\n
\nWhen using load balancer methods other than the default\nround-robin method, it is necessary to activate them before\nthe ntlm directive.\n\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n least_conn;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
\n This directive appeared in versions 1.3.1 and 1.2.2.\n \n
\n\nSpecifies that a group should use a load balancing method where a request\nis passed to the server with the least number of active connections,\ntaking into account weights of servers.\nIf there are several such servers, they are tried in turn using a\nweighted round-robin balancing method.\n
| \n Syntax:\n | \n\n least_time \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.7.10.\n
\nSpecifies that a group should use a load balancing method where a request\nis passed to the server with the least average response time and\nleast number of active connections, taking into account weights of servers.\nIf there are several such servers, they are tried in turn using a\nweighted round-robin balancing method.\n
\nIf the header parameter is specified,\ntime to receive the\nresponse header is used.\nIf the last_byte parameter is specified,\ntime to receive the full response\nis used.\nIf the inflight parameter is specified (1.11.6),\nincomplete requests are also taken into account.\n
\nPrior to version 1.11.6, incomplete requests were taken into account by default.\n
\n
\n
\nPrior to version 1.31.0,\nthis directive was available only as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n queue \n\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.5.12.\n
\nIf an upstream server cannot be selected immediately\nwhile processing a request,\nthe request will be placed into the queue.\nThe directive specifies the maximum number of requests\nthat can be in the queue at the same time.\nIf the queue is filled up,\nor the server to pass the request to cannot be selected within\nthe time period specified in the timeout parameter,\nthe 502 (Bad Gateway)\nerror will be returned to the client.\n
\nThe default value of the timeout parameter is 60 seconds.\n
\n
\nWhen using load balancer methods other than the default\nround-robin method, it is necessary to activate them before\nthe queue directive.\n\n\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n random [\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.15.1.\n
\nSpecifies that a group should use a load balancing method where a request\nis passed to a randomly selected server, taking into account weights\nof servers.\n
\nThe optional two parameter\ninstructs nginx to randomly select\ntwo\nservers and then choose a server\nusing the specified method.\nThe default method is least_conn\nwhich passes a request to a server\nwith the least number of active connections.\n
\nThe least_time method passes a request to a server\nwith the least average response time and least number of active connections.\nIf least_time=header is specified, the time to receive the\nresponse header is used.\nIf least_time=last_byte is specified, the time to receive the\nfull response is used.\n
\nThe least_time method is available as a part of our\ncommercial subscription.\n\n
| \n Syntax:\n | \n\n resolver \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.27.3.\n
\nConfigures name servers used to resolve names of upstream servers\ninto addresses, for example:\n
\nresolver 127.0.0.1 [::1]:5353;\n
\nThe address can be specified as a domain name or IP address,\nwith an optional port.\nIf port is not specified, the port 53 is used.\nName servers are queried in a round-robin fashion.\n
\nBy default, nginx will look up both IPv4 and IPv6 addresses while resolving.\nIf looking up of IPv4 or IPv6 addresses is not desired,\nthe ipv4=off (1.23.1) or\nthe ipv6=off parameter can be specified.\n
\nBy default, nginx caches answers using the TTL value of a response.\nAn optional valid parameter allows overriding it:\n
\nresolver 127.0.0.1 [::1]:5353 valid=30s;\n
\n
\nTo prevent DNS spoofing, it is recommended\nconfiguring DNS servers in a properly secured trusted local network.\n
\n
\nThe optional status_zone parameter (1.17.5)\nenables\ncollection\nof DNS server statistics of requests and responses\nin the specified zone.\nThe parameter is available as part of our\ncommercial subscription.\n
\n
\nSince version 1.17.5 and prior to version 1.27.3,\nthis directive was available only as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n resolver_timeout \n | \n
|---|---|
| \n Default:\n | \n\n resolver_timeout 30s;\n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.27.3.\n
\nSets a timeout for name resolution, for example:\n
\nresolver_timeout 5s;\n
\n
\n
\nSince version 1.17.5 and prior to version 1.27.3,\nthis directive was available only as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n sticky \n sticky \n sticky \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.5.7.\n
\nEnables session affinity, which causes requests from the same client to be\npassed to the same server in a group of servers.\nThree methods are available:\n
\nWhen the cookie method is used, information about the\ndesignated server is passed in an HTTP cookie generated by nginx:\n
\nupstream backend {\n server backend1.example.com;\n server backend2.example.com;\n\n sticky cookie srv_id expires=1h domain=.example.com path=/;\n}\n\n
\n\n\nA request that comes from a client not yet bound to a particular server\nis passed to the server selected by the configured balancing method.\nFurther requests with this cookie will be passed to the designated server.\nIf the designated server cannot process a request, the new server is\nselected as if the client has not been bound yet.\n\n
\nAs a load balancing method always tries to evenly distribute the load\nconsidering already bound requests,\nthe server with a higher number of active bound requests\nhas less possibility of getting new unbound requests.\n
\n
\n\n\nThe first parameter sets the name of the cookie to be set or inspected.\nThe cookie value is\na hexadecimal representation of the MD5 hash of the IP address and port,\nor of the UNIX-domain socket path.\nHowever, if the “route” parameter of the\nserver directive is specified, the cookie value will be\nthe value of the “route” parameter:\n
\nupstream backend {\n server backend1.example.com route=a;\n server backend2.example.com route=b;\n\n sticky cookie srv_id expires=1h domain=.example.com path=/;\n}\n \nIn this case, the value of the “srv_id” cookie will be\neither a or b.\n
\nAdditional parameters may be as follows:\n
expires=timetime for which a browser should keep the cookie.\nThe special value max will cause the cookie to expire on\n“31 Dec 2037 23:55:55 GMT”.\nIf the parameter is not specified, it will cause the cookie to expire at\nthe end of a browser session.\ndomain=domaindomain for which the cookie is set.\nParameter value can contain variables (1.11.5).\nhttponlyHttpOnly attribute to the cookie (1.7.11).\nsamesite=strict |\nlax | none | $variableSameSite (1.19.4) attribute to the cookie\nwith one of the following values:\nStrict,\nLax,\nNone, or\nusing variables (1.23.3).\nIn the latter case, if the variable value is empty,\nthe SameSite attribute will not be added to the cookie,\nif the value is resolved to\nStrict,\nLax, or\nNone,\nthe corresponding value will be assigned,\notherwise the Strict value will be assigned.\nsecureSecure attribute to the cookie (1.7.11).\npath=pathpath for which the cookie is set.\n\nIf any parameters are omitted, the corresponding cookie fields are not set.\n
\nroute\nWhen the route method is used, proxied server assigns\nclient a route on receipt of the first request.\nAll subsequent requests from this client will carry routing information\nin a cookie or URI.\nThis information is compared with the “route” parameter\nof the server directive to identify the server to which the\nrequest should be proxied.\nIf the “route” parameter is not specified, the route name\nwill be a hexadecimal representation of the MD5 hash of the IP address and port,\nor of the UNIX-domain socket path.\nIf the designated server cannot process a request, the new server is\nselected by the configured balancing method as if there is no routing\ninformation in the request.\n
\nThe parameters of the route method specify variables that\nmay contain routing information.\nThe first non-empty variable is used to find the matching server.\n
\nExample:\n
\nmap $cookie_jsessionid $route_cookie {\n ~.+\\.(?P<route>\\w+)$ $route;\n}\n\nmap $request_uri $route_uri {\n ~jsessionid=.+\\.(?P<route>\\w+)$ $route;\n}\n\nupstream backend {\n server backend1.example.com route=a;\n server backend2.example.com route=b;\n\n sticky route $route_cookie $route_uri;\n}\n \nHere, the route is taken from the “JSESSIONID” cookie\nif present in a request.\nOtherwise, the route from the URI is used.\n
learn\nWhen the learn method (1.7.1) is used, nginx\nanalyzes upstream server responses and learns server-initiated sessions\nusually passed in an HTTP cookie.\n
\nupstream backend {\n server backend1.example.com:8080;\n server backend2.example.com:8081;\n\n sticky learn\n create=$upstream_cookie_examplecookie\n lookup=$cookie_examplecookie\n zone=client_sessions:1m;\n}\n \n\nIn the example, the upstream server creates a session by setting the\ncookie “EXAMPLECOOKIE” in the response.\nFurther requests with this cookie will be passed to the same server.\nIf the server cannot process the request, the new server is\nselected as if the client has not been bound yet.\n
\nThe parameters create and lookup\nspecify variables that indicate how new sessions are created and existing\nsessions are searched, respectively.\nBoth parameters may be specified more than once, in which case the first\nnon-empty variable is used.\n
\nSessions are stored in a shared memory zone, whose name and\nsize are configured by the zone parameter.\nOne megabyte zone can store about 4000 sessions on the 64-bit platform.\nThe sessions that are not accessed during the time specified by the\ntimeout parameter get removed from the zone.\nBy default, timeout is set to 10 minutes.\n
\nThe header parameter (1.13.1) allows creating a session\nright after receiving response headers from the upstream server.\n
\nThe sync parameter (1.13.8) enables\nsynchronization\nof the shared memory zone.\nThe parameter is available as part of our\ncommercial subscription.\n
\n
\n
\nPrior to version 1.29.6,\nthis directive was available only as part of our\ncommercial subscription.\n
\n
\n\n\n\nThe ngx_http_upstream_module module\nsupports the following embedded variables:\n
$upstream_addr192.168.1.1:80, 192.168.1.2:80, unix:/tmp/sock”.\nIf an internal redirect from one server group to another happens,\ninitiated by\n“X-Accel-Redirect” or\nerror_page,\nthen the server addresses from different groups are separated by colons, e.g.\n“192.168.1.1:80, 192.168.1.2:80, unix:/tmp/sock : 192.168.10.1:80, 192.168.10.2:80”.\nIf a server cannot be selected,\nthe variable keeps the name of the server group.\n$upstream_bytes_received$upstream_bytes_sent$upstream_cache_status\nMISS”,\n“BYPASS”, “EXPIRED”,\n“STALE”, “UPDATING”,\n“REVALIDATED”, or “HIT”.\n$upstream_connect_time\nname sent by the upstream server\nin the “Set-Cookie” response header field (1.7.1).\nOnly the cookies from the response of the last server are saved.\n$upstream_header_time\n$upstream_http_name$upstream_http_server variable.\nThe rules of converting header field names to variable names are the same\nas for the variables that start with the\n“$http_” prefix.\nOnly the header fields from the response of the last server are saved.\n$upstream_last_addr\n
\nThis variable is available as part of our\ncommercial subscription.\n
\n
\n\n$upstream_last_server_name\n\n\nproxy_ssl_server_name on;\nproxy_ssl_name $upstream_last_server_name;\n
\n
\nThis variable is available as part of our\ncommercial subscription.\n
\n
\n\n$upstream_queue_time$upstream_response_length\n$upstream_response_time\n$upstream_status$upstream_trailer_name\n
\n\n| Example Configuration Directives userid userid_domain userid_expires userid_flags userid_mark userid_name userid_p3p userid_path userid_service Embedded Variables |
\nThe ngx_http_userid_module module sets cookies\nsuitable for client identification.\nReceived and set cookies can be logged using the embedded variables\n$uid_got and\n$uid_set.\nThis module is compatible with the\nmod_uid\nmodule for Apache.\n
\n
\nuserid on;\nuserid_name uid;\nuserid_domain example.com;\nuserid_path /;\nuserid_expires 365d;\nuserid_p3p 'policyref=\"/w3c/p3p.xml\", CP=\"CUR ADM OUR NOR STA NID\"';\n
\n
\n\n\n| \n Syntax:\n | \n\n userid \n \n | \n
|---|---|
| \n Default:\n | \n\n userid off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables setting cookies and logging the received cookies:\n
onv1logoff\n
| \n Syntax:\n | \n\n userid_domain \n | \n
|---|---|
| \n Default:\n | \n\n userid_domain none;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a domain for which the cookie is set.\nThe none parameter disables setting of a domain for the\ncookie.\n
| \n Syntax:\n | \n\n userid_expires \n | \n
|---|---|
| \n Default:\n | \n\n userid_expires off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a time during which a browser should keep the cookie.\nThe parameter max will cause the cookie to expire on\n“31 Dec 2037 23:55:55 GMT”.\nThe parameter off will cause the cookie to expire at\nthe end of a browser session.\n
| \n Syntax:\n | \n\n userid_flags \n \n | \n
|---|---|
| \n Default:\n | \n\n userid_flags off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.19.3.\n
\nIf the parameter is not off,\ndefines one or more additional flags for the cookie:\nsecure,\nhttponly,\nsamesite=strict,\nsamesite=lax,\nsamesite=none.\n
| \n Syntax:\n | \n\n userid_mark \n \n | \n
|---|---|
| \n Default:\n | \n\n userid_mark off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIf the parameter is not off, enables the cookie marking\nmechanism and sets the character used as a mark.\nThis mechanism is used to add or change\nuserid_p3p and/or a cookie expiration time while\npreserving the client identifier.\nA mark can be any letter of the English alphabet (case-sensitive),\ndigit, or the “=” character.\n
\nIf the mark is set, it is compared with the first padding symbol\nin the base64 representation of the client identifier passed in a cookie.\nIf they do not match, the cookie is resent with the specified mark,\nexpiration time, and “P3P” header.\n
| \n Syntax:\n | \n\n userid_name \n | \n
|---|---|
| \n Default:\n | \n\n userid_name uid;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the cookie name.\n
| \n Syntax:\n | \n\n userid_p3p \n | \n
|---|---|
| \n Default:\n | \n\n userid_p3p none;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a value for the “P3P” header field that will be\nsent along with the cookie.\nIf the directive is set to the special value none,\nthe “P3P” header will not be sent in a response.\n
| \n Syntax:\n | \n\n userid_path \n | \n
|---|---|
| \n Default:\n | \n\n userid_path /;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a path for which the cookie is set.\n
| \n Syntax:\n | \n\n userid_service \n | \n
|---|---|
| \n Default:\n | \n\n userid_service IP address of the server;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIf identifiers are issued by multiple servers (services),\neach service should be assigned its own number\nto ensure that client identifiers are unique.\nFor version 1 cookies, the default value is zero.\nFor version 2 cookies, the default value is the number composed from the last\nfour octets of the server’s IP address.\n
\nThe ngx_http_userid_module module\nsupports the following embedded variables:\n
$uid_got$uid_reset0”,\nthe client identifiers are reset.\nThe special value “log” additionally leads to the output of\nmessages about the reset identifiers to the\nerror_log.\n$uid_set\n
\n\n\nThe ngx_http_uwsgi_module module allows passing\nrequests to a uwsgi server.\n
\n
\nlocation / {\n include uwsgi_params;\n uwsgi_pass localhost:9000;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n uwsgi_allow_upstream \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nDefines conditions under which access to a uwsgi server\nis allowed or denied.\nIf all string parameters are not empty\nand not equal to “0” then the access is allowed.\nThe conditions are evaluated each time\nbefore a connection to a uwsgi server is established.\nParameter values can contain variables:\n
\ngeo $upstream_last_addr $allow {\n volatile;\n 10.10.0.0/24 1;\n}\n\nserver {\n listen 127.0.0.1:8080;\n\n location / {\n uwsgi_pass localhost:9000;\n uwsgi_allow_upstream $allow;\n ...\n }\n}\n\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n uwsgi_bind \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nMakes outgoing connections to a uwsgi server originate\nfrom the specified local IP address with an optional port (1.11.2).\nParameter value can contain variables (1.3.12).\nThe special value off (1.3.12) cancels the effect\nof the uwsgi_bind directive\ninherited from the previous configuration level, which allows the\nsystem to auto-assign the local IP address and port.\n
\nThe transparent parameter (1.11.0) allows\noutgoing connections to a uwsgi server originate\nfrom a non-local IP address,\nfor example, from a real IP address of a client:\n
\nuwsgi_bind $remote_addr transparent;\n
\nIn order for this parameter to work,\nit is usually necessary to run nginx worker processes with the\nsuperuser privileges.\nOn Linux it is not required (1.13.8) as if\nthe transparent parameter is specified, worker processes\ninherit the CAP_NET_RAW capability from the master process.\nIt is also necessary to configure kernel routing table\nto intercept network traffic from the uwsgi server.\n
| \n Syntax:\n | \n\n uwsgi_bind_dynamic \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_bind_dynamic off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nWhen enabled, makes the bind operation\nat each connection attempt.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n uwsgi_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_buffer_size 4k|8k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the size of the buffer used for reading the first part\nof the response received from the uwsgi server.\nThis part usually contains a small response header;\nif it exceeds the buffer size, the response is considered\ninvalid.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\nIt can be made smaller, however.\n
| \n Syntax:\n | \n\n uwsgi_buffering \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_buffering on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables or disables buffering of responses from the uwsgi server.\n
\nWhen buffering is enabled, nginx receives a response from the uwsgi server\nas soon as possible, saving it into the buffers set by the\nuwsgi_buffer_size and uwsgi_buffers directives.\nIf the whole response does not fit into memory, a part of it can be saved\nto a temporary file on the disk.\nWriting to temporary files is controlled by the\nuwsgi_max_temp_file_size and\nuwsgi_temp_file_write_size directives.\n
\nWhen buffering is disabled, the response is passed to a client synchronously,\nimmediately as it is received.\nnginx will not try to read the whole response from the uwsgi server.\nThe maximum size of the data that nginx can receive from the server\nat a time is set by the uwsgi_buffer_size directive.\n
\nBuffering can also be enabled or disabled by passing\n“yes” or “no” in the\n“X-Accel-Buffering” response header field.\nThis capability can be disabled using the\nuwsgi_ignore_headers directive.\n
| \n Syntax:\n | \n\n uwsgi_buffers \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_buffers 8 4k|8k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the number and size of the\nbuffers used for reading a response from the uwsgi server,\nfor a single connection.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\n
| \n Syntax:\n | \n\n uwsgi_busy_buffers_size \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_busy_buffers_size 8k|16k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nWhen buffering of responses from the uwsgi\nserver is enabled, limits the total size of buffers that\ncan be busy sending a response to the client while the response is not\nyet fully read.\nIn the meantime, the rest of the buffers can be used for reading the response\nand, if needed, buffering part of the response to a temporary file.\nBy default, size is limited by the size of two buffers set by the\nuwsgi_buffer_size and uwsgi_buffers directives.\n
| \n Syntax:\n | \n\n uwsgi_cache \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_cache off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a shared memory zone used for caching.\nThe same zone can be used in several places.\nParameter value can contain variables (1.7.9).\nThe off parameter disables caching inherited\nfrom the previous configuration level.\n
| \n Syntax:\n | \n\n uwsgi_cache_background_update \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_cache_background_update off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.11.10.\n
\nAllows starting a background subrequest\nto update an expired cache item,\nwhile a stale cached response is returned to the client.\nNote that it is necessary to\nallow\nthe usage of a stale cached response when it is being updated.\n
| \n Syntax:\n | \n\n uwsgi_cache_bypass \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines conditions under which the response will not be taken from a cache.\nIf at least one value of the string parameters is not empty and is not\nequal to “0” then the response will not be taken from the cache:\n
\nuwsgi_cache_bypass $cookie_nocache $arg_nocache$arg_comment;\nuwsgi_cache_bypass $http_pragma $http_authorization;\n
\nCan be used along with the uwsgi_no_cache directive.\n
| \n Syntax:\n | \n\n uwsgi_cache_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a key for caching, for example\n
\nuwsgi_cache_key localhost:9000$request_uri;\n
\n
| \n Syntax:\n | \n\n uwsgi_cache_lock \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_cache_lock off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.12.\n
\nWhen enabled, only one request at a time will be allowed to populate\na new cache element identified according to the uwsgi_cache_key\ndirective by passing a request to a uwsgi server.\nOther requests of the same cache element will either wait\nfor a response to appear in the cache or the cache lock for\nthis element to be released, up to the time set by the\nuwsgi_cache_lock_timeout directive.\n
| \n Syntax:\n | \n\n uwsgi_cache_lock_age \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_cache_lock_age 5s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.8.\n
\nIf the last request passed to the uwsgi server\nfor populating a new cache element\nhas not completed for the specified time,\none more request may be passed to the uwsgi server.\n
| \n Syntax:\n | \n\n uwsgi_cache_lock_timeout \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_cache_lock_timeout 5s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.12.\n
\nSets a timeout for uwsgi_cache_lock.\nWhen the time expires,\nthe request will be passed to the uwsgi server,\nhowever, the response will not be cached.\n
\nBefore 1.7.8, the response could be cached.\n
\n
| \n Syntax:\n | \n\n uwsgi_cache_max_range_offset \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.11.6.\n
\nSets an offset in bytes for byte-range requests.\nIf the range is beyond the offset,\nthe range request will be passed to the uwsgi server\nand the response will not be cached.\n
| \n Syntax:\n | \n\n uwsgi_cache_methods \n \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_cache_methods GET HEAD;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIf the client request method is listed in this directive then\nthe response will be cached.\n“GET” and “HEAD” methods are always\nadded to the list, though it is recommended to specify them explicitly.\nSee also the uwsgi_no_cache directive.\n
| \n Syntax:\n | \n\n uwsgi_cache_min_uses \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_cache_min_uses 1;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the number of requests after which the response\nwill be cached.\n
| \n Syntax:\n | \n\n uwsgi_cache_path \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http\n | \n
\nSets the path and other parameters of a cache.\nCache data are stored in files.\nThe file name in a cache is a result of\napplying the MD5 function to the\ncache key.\nThe levels parameter defines hierarchy levels of a cache:\nfrom 1 to 3, each level accepts values 1 or 2.\nFor example, in the following configuration\n
\nuwsgi_cache_path /data/nginx/cache levels=1:2 keys_zone=one:10m;\n
\nfile names in a cache will look like this:\n
\n/data/nginx/cache/c/29/b7f54b2df7773722d382f4809d65029c\n
\n
\nA cached response is first written to a temporary file,\nand then the file is renamed.\nStarting from version 0.8.9, temporary files and the cache can be put on\ndifferent file systems.\nHowever, be aware that in this case a file is copied\nacross two file systems instead of the cheap renaming operation.\nIt is thus recommended that for any given location both cache and a directory\nholding temporary files\nare put on the same file system.\nA directory for temporary files is set based on\nthe use_temp_path parameter (1.7.10).\nIf this parameter is omitted or set to the value on,\nthe directory set by the uwsgi_temp_path directive\nfor the given location will be used.\nIf the value is set to off,\ntemporary files will be put directly in the cache directory.\n
\nIn addition, all active keys and information about data are stored\nin a shared memory zone, whose name and size\nare configured by the keys_zone parameter.\nOne megabyte zone can store about 8 thousand keys.\n
\nAs part of\ncommercial subscription,\nthe shared memory zone also stores extended\ncache information,\nthus, it is required to specify a larger zone size for the same number of keys.\nFor example,\none megabyte zone can store about 4 thousand keys.\n
\n
\nCached data that are not accessed during the time specified by the\ninactive parameter get removed from the cache\nregardless of their freshness.\nBy default, inactive is set to 10 minutes.\n
\nThe special “cache manager” process monitors the maximum cache size set\nby the max_size parameter,\nand the minimum amount of free space set\nby the min_free (1.19.1) parameter\non the file system with cache.\nWhen the size is exceeded or there is not enough free space,\nit removes the least recently used data.\nThe data is removed in iterations configured by\nmanager_files,\nmanager_threshold, and\nmanager_sleep parameters (1.11.5).\nDuring one iteration no more than manager_files items\nare deleted (by default, 100).\nThe duration of one iteration is limited by the\nmanager_threshold parameter (by default, 200 milliseconds).\nBetween iterations, a pause configured by the manager_sleep\nparameter (by default, 50 milliseconds) is made.\n
\nA minute after the start the special “cache loader” process is activated.\nIt loads information about previously cached data stored on file system\ninto a cache zone.\nThe loading is also done in iterations.\nDuring one iteration no more than loader_files items\nare loaded (by default, 100).\nBesides, the duration of one iteration is limited by the\nloader_threshold parameter (by default, 200 milliseconds).\nBetween iterations, a pause configured by the loader_sleep\nparameter (by default, 50 milliseconds) is made.\n
\nAdditionally,\nthe following parameters are available as part of our\ncommercial subscription:\n
\n
purger=on|off\non\n(default is off)\nwill activate the “cache purger” process that\npermanently iterates through all cache entries\nand deletes the entries that match the wildcard key.\npurger_files=number\npurger_files is set to 10.\npurger_threshold=number\npurger_threshold is set to 50 milliseconds.\npurger_sleep=number\npurger_sleep is set to 50 milliseconds.\n\n
\n
\nIn versions 1.7.3, 1.7.7, and 1.11.10 cache header format has been changed.\nPreviously cached responses will be considered invalid\nafter upgrading to a newer nginx version.\n
\n
| \n Syntax:\n | \n\n uwsgi_cache_purge string ...;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.7.\n
\nDefines conditions under which the request will be considered a cache\npurge request.\nIf at least one value of the string parameters is not empty and is not equal\nto “0” then the cache entry with a corresponding\ncache key is removed.\nThe result of successful operation is indicated by returning\nthe 204 (No Content) response.\n
\nIf the cache key of a purge request ends\nwith an asterisk (“*”), all cache entries matching the\nwildcard key will be removed from the cache.\nHowever, these entries will remain on the disk until they are deleted\nfor either inactivity,\nor processed by the cache purger (1.7.12),\nor a client attempts to access them.\n
\nExample configuration:\n
\nuwsgi_cache_path /data/nginx/cache keys_zone=cache_zone:10m;\n\nmap $request_method $purge_method {\n PURGE 1;\n default 0;\n}\n\nserver {\n ...\n location / {\n uwsgi_pass backend;\n uwsgi_cache cache_zone;\n uwsgi_cache_key $uri;\n uwsgi_cache_purge $purge_method;\n }\n}\n\n
\nThis functionality is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n uwsgi_cache_revalidate \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_cache_revalidate off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.7.\n
\nEnables revalidation of expired cache items using conditional requests with\nthe “If-Modified-Since” and “If-None-Match”\nheader fields.\n
| \n Syntax:\n | \n\n uwsgi_cache_use_stale \n \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_cache_use_stale off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines in which cases a stale cached response can be used\nwhen an error occurs during communication with the uwsgi server.\nThe directive’s parameters match the parameters of the\nuwsgi_next_upstream directive.\n
\nThe error parameter also permits\nusing a stale cached response if a uwsgi server to process a request\ncannot be selected.\n
\nAdditionally, the updating parameter permits\nusing a stale cached response if it is currently being updated.\nThis allows minimizing the number of accesses to uwsgi servers\nwhen updating cached data.\n
\nUsing a stale cached response\ncan also be enabled directly in the response header\nfor a specified number of seconds after the response became stale (1.11.10).\nThis has lower priority than using the directive parameters.\n
\n
\nTo minimize the number of accesses to uwsgi servers when\npopulating a new cache element, the uwsgi_cache_lock\ndirective can be used.\n
| \n Syntax:\n | \n\n uwsgi_cache_valid [\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets caching time for different response codes.\nFor example, the following directives\n
\nuwsgi_cache_valid 200 302 10m;\nuwsgi_cache_valid 404 1m;\n
\nset 10 minutes of caching for responses with codes 200 and 302\nand 1 minute for responses with code 404.\n
\nIf only caching time is specified\n
\nuwsgi_cache_valid 5m;\n
\nthen only 200, 301, and 302 responses are cached.\n
\nIn addition, the any parameter can be specified\nto cache any responses:\n
\nuwsgi_cache_valid 200 302 10m;\nuwsgi_cache_valid 301 1h;\nuwsgi_cache_valid any 1m;\n
\n
\nParameters of caching can also be set directly\nin the response header.\nThis has higher priority than setting of caching time using the directive.\n
@ prefix, it sets an absolute\ntime in seconds since Epoch, up to which the response may be cached.\n*”, such a\nresponse will not be cached (1.7.7).\nIf the header includes the “Vary” field\nwith another value, such a response will be cached\ntaking into account the corresponding request header fields (1.7.7).\n\nProcessing of one or more of these response header fields can be disabled\nusing the uwsgi_ignore_headers directive.\n
| \n Syntax:\n | \n\n uwsgi_connect_timeout \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_connect_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a timeout for establishing a connection with a uwsgi server.\nIt should be noted that this timeout cannot usually exceed 75 seconds.\n
| \n Syntax:\n | \n\n uwsgi_force_ranges \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_force_ranges off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.7.\n
\nEnables byte-range support\nfor both cached and uncached responses from the uwsgi server\nregardless of the “Accept-Ranges” field in these responses.\n
| \n Syntax:\n | \n\n uwsgi_hide_header \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nBy default,\nnginx does not pass the header fields “Status” and\n“X-Accel-...” from the response of a uwsgi\nserver to a client.\nThe uwsgi_hide_header directive sets additional fields\nthat will not be passed.\nIf, on the contrary, the passing of fields needs to be permitted,\nthe uwsgi_pass_header directive can be used.\n
| \n Syntax:\n | \n\n uwsgi_ignore_client_abort \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_ignore_client_abort off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines whether the connection with a uwsgi server should be\nclosed when a client closes the connection without waiting\nfor a response.\n
| \n Syntax:\n | \n\n uwsgi_ignore_headers \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDisables processing of certain response header fields from the uwsgi server.\nThe following fields can be ignored: “X-Accel-Redirect”,\n“X-Accel-Expires”, “X-Accel-Limit-Rate” (1.1.6),\n“X-Accel-Buffering” (1.1.6),\n“X-Accel-Charset” (1.1.6), “Expires”,\n“Cache-Control”, “Set-Cookie” (0.8.44),\nand “Vary” (1.7.7).\n
\nIf not disabled, processing of these header fields has the following\neffect:\n
\n
| \n Syntax:\n | \n\n uwsgi_intercept_errors \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_intercept_errors off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDetermines whether a uwsgi server responses with codes greater than or equal\nto 300 should be passed to a client\nor be intercepted and redirected to nginx for processing\nwith the error_page directive.\n
| \n Syntax:\n | \n\n uwsgi_limit_rate \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_limit_rate 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.7.\n
\nLimits the speed of reading the response from the uwsgi server.\nThe rate is specified in bytes per second.\nThe zero value disables rate limiting.\nThe limit is set per a request, and so if nginx simultaneously opens\ntwo connections to the uwsgi server,\nthe overall rate will be twice as much as the specified limit.\nThe limitation works only if\nbuffering of responses from the uwsgi\nserver is enabled.\nParameter value can contain variables (1.27.0).\n
| \n Syntax:\n | \n\n uwsgi_max_temp_file_size \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_max_temp_file_size 1024m;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nWhen buffering of responses from the uwsgi\nserver is enabled, and the whole response does not fit into the buffers\nset by the uwsgi_buffer_size and uwsgi_buffers\ndirectives, a part of the response can be saved to a temporary file.\nThis directive sets the maximum size of the temporary file.\nThe size of data written to the temporary file at a time is set\nby the uwsgi_temp_file_write_size directive.\n
\nThe zero value disables buffering of responses to temporary files.\n
\n
\nThis restriction does not apply to responses\nthat will be cached\nor stored on disk.\n
\n
| \n Syntax:\n | \n\n uwsgi_modifier1 \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_modifier1 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the value of the modifier1 field in the\nuwsgi\npacket header.\n
| \n Syntax:\n | \n\n uwsgi_modifier2 \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_modifier2 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the value of the modifier2 field in the\nuwsgi\npacket header.\n
| \n Syntax:\n | \n\n uwsgi_next_upstream \n \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_next_upstream error timeout;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies in which cases a request should be passed to the next server:\n
errortimeoutdenied\n
\nThis parameter is available as part of our\ncommercial subscription.\n
\n
\ninvalid_headerhttp_500http_503http_403http_404http_429non_idempotentPOST, LOCK, PATCH)\nare not passed to the next server\nif a request has been sent to an upstream server (1.9.13);\nenabling this option explicitly allows retrying such requests;\noff\n
\nOne should bear in mind that passing a request to the next server is\nonly possible if nothing has been sent to a client yet.\nThat is, if an error or timeout occurs in the middle of the\ntransferring of a response, fixing this is impossible.\n
\nThe directive also defines what is considered an\nunsuccessful\nattempt of communication with a server.\nThe cases of error, timeout,\ndenied and\ninvalid_header are always considered unsuccessful attempts,\neven if they are not specified in the directive.\nThe cases of http_500, http_503,\nand http_429 are\nconsidered unsuccessful attempts only if they are specified in the directive.\nThe cases of http_403 and http_404\nare never considered unsuccessful attempts.\n
\nPassing a request to the next server can be limited by\nthe number of tries\nand by time.\n
| \n Syntax:\n | \n\n uwsgi_next_upstream_timeout \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_next_upstream_timeout 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.5.\n
\nLimits the time during which a request can be passed to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n uwsgi_next_upstream_tries \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_next_upstream_tries 0;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.5.\n
\nLimits the number of possible tries for passing a request to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n uwsgi_no_cache \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines conditions under which the response will not be saved to a cache.\nIf at least one value of the string parameters is not empty and is not\nequal to “0” then the response will not be saved:\n
\nuwsgi_no_cache $cookie_nocache $arg_nocache$arg_comment;\nuwsgi_no_cache $http_pragma $http_authorization;\n
\nCan be used along with the uwsgi_cache_bypass directive.\n
| \n Syntax:\n | \n\n uwsgi_param \n \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_param HTTP_HOST $host$is_request_port$request_port;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a parameter that should be passed to the uwsgi server.\nThe value can contain text, variables, and their combination.\nThese directives are inherited from the previous configuration level\nif and only if there are no uwsgi_param directives\ndefined on the current level.\n
\nStandard\nCGI\nenvironment variables\nshould be provided as uwsgi headers, see the uwsgi_params file\nprovided in the distribution:\n
\nlocation / {\n include uwsgi_params;\n ...\n}\n\n
\nIf the directive is specified with if_not_empty (1.1.11) then\nsuch a parameter will be passed to the server only if its value is not empty:\n
\nuwsgi_param HTTPS $https if_not_empty;\n
\n
| \n Syntax:\n | \n\n uwsgi_pass [\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location, if in location\n | \n
\nSets the protocol and address of a uwsgi server.\nAs a protocol,\n“uwsgi” or “suwsgi”\n(secured uwsgi, uwsgi over SSL) can be specified.\nThe address can be specified as a domain name or IP address,\nand a port:\n
\nuwsgi_pass localhost:9000;\nuwsgi_pass uwsgi://localhost:9000;\nuwsgi_pass suwsgi://[2001:db8::1]:9090;\n
\nor as a UNIX-domain socket path:\n
\nuwsgi_pass unix:/tmp/uwsgi.socket;\n
\n
\nIf a domain name resolves to several addresses, all of them will be\nused in a round-robin fashion.\nIn addition, an address can be specified as a\nserver group.\n
\nParameter value can contain variables.\nIn this case, if an address is specified as a domain name,\nthe name is searched among the described\nserver groups,\nand, if not found, is determined using a\nresolver.\n
\n
\nSecured uwsgi protocol is supported since version 1.5.8.\n
\n
| \n Syntax:\n | \n\n uwsgi_pass_header \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nPermits passing otherwise disabled header\nfields from a uwsgi server to a client.\n
| \n Syntax:\n | \n\n uwsgi_pass_request_body \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_pass_request_body on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIndicates whether the original request body is passed\nto the uwsgi server.\nSee also the uwsgi_pass_request_headers directive.\n
| \n Syntax:\n | \n\n uwsgi_pass_request_headers \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_pass_request_headers on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nIndicates whether the header fields of the original request are passed\nto the uwsgi server.\nSee also the uwsgi_pass_request_body directive.\n
| \n Syntax:\n | \n\n uwsgi_read_timeout \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_read_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a timeout for reading a response from the uwsgi server.\nThe timeout is set only between two successive read operations,\nnot for the transmission of the whole response.\nIf the uwsgi server does not transmit anything within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n uwsgi_request_buffering \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_request_buffering on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.11.\n
\nEnables or disables buffering of a client request body.\n
\nWhen buffering is enabled, the entire request body is\nread\nfrom the client before sending the request to a uwsgi server.\n
\nWhen buffering is disabled, the request body is sent to the uwsgi server\nimmediately as it is received.\nIn this case, the request cannot be passed to the\nnext server\nif nginx already started sending the request body.\n
\nWhen HTTP/1.1 chunked transfer encoding is used\nto send the original request body,\nthe request body will be buffered regardless of the directive value.\n
| \n Syntax:\n | \n\n uwsgi_request_dynamic \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_request_dynamic off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.29.3.\n
\nEnables or disables creation of a separate request instance\nfor each uwsgi server.\nBy default, a single request is used for all uwsgi servers.\nIf enabled, a separate request instance is created,\nallowing per-server request customization.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n uwsgi_send_timeout \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_send_timeout 60s;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets a timeout for transmitting a request to the uwsgi server.\nThe timeout is set only between two successive write operations,\nnot for the transmission of the whole request.\nIf the uwsgi server does not receive anything within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n uwsgi_socket_keepalive \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_socket_keepalive off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.15.6.\n
\nConfigures the “TCP keepalive” behavior\nfor outgoing connections to a uwsgi server.\nBy default, the operating system’s settings are in effect for the socket.\nIf the directive is set to the value “on”, the\nSO_KEEPALIVE socket option is turned on for the socket.\n
| \n Syntax:\n | \n\n uwsgi_ssl_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.8.\n
\nSpecifies a file with the certificate in the PEM format\nused for authentication to a secured uwsgi server.\n
\nSince version 1.21.0, variables can be used in the file name.\n
| \n Syntax:\n | \n\n uwsgi_ssl_certificate_cache uwsgi_ssl_certificate_cache \n \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_ssl_certificate_cache off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.27.4.\n
\nDefines a cache that stores\nSSL certificates and\nsecret keys\nspecified with variables.\n
\nThe directive has the following parameters:\n
max\ninactive\nvalid\noff\n\n
\nExample:\n
\nuwsgi_ssl_certificate $uwsgi_ssl_server_name.crt;\nuwsgi_ssl_certificate_key $uwsgi_ssl_server_name.key;\nuwsgi_ssl_certificate_cache max=1000 inactive=20s valid=1m;\n
\n
| \n Syntax:\n | \n\n uwsgi_ssl_certificate_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.8.\n
\nSpecifies a file with the secret key in the PEM format\nused for authentication to a secured uwsgi server.\n
\nThe value\nengine:name:id\ncan be specified instead of the file (1.7.9),\nwhich loads a secret key with a specified id\nfrom the OpenSSL engine name.\n
\nThe value\nstore:scheme:id\ncan be specified instead of the file (1.29.0),\nwhich is used to load a secret key with a specified id\nand OpenSSL provider registered URI scheme, such as\npkcs11.\n
\nSince version 1.21.0, variables can be used in the file name.\n
| \n Syntax:\n | \n\n uwsgi_ssl_ciphers \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_ssl_ciphers DEFAULT;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.8.\n
\nSpecifies the enabled ciphers for requests to a secured uwsgi server.\nThe ciphers are specified in the format understood by the OpenSSL library.\n
\nThe full list can be viewed using the\n“openssl ciphers” command.\n
| \n Syntax:\n | \n\n uwsgi_ssl_conf_command \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.19.4.\n
\nSets arbitrary OpenSSL configuration\ncommands\nwhen establishing a connection with the secured uwsgi server.\n
\nThe directive is supported when using OpenSSL 1.0.2 or higher.\n
\n
\nSeveral uwsgi_ssl_conf_command directives\ncan be specified on the same level.\nThese directives are inherited from the previous configuration level\nif and only if there are\nno uwsgi_ssl_conf_command directives\ndefined on the current level.\n
\n
\nNote that configuring OpenSSL directly\nmight result in unexpected behavior.\n
\n
| \n Syntax:\n | \n\n uwsgi_ssl_crl \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.0.\n
\nSpecifies a file with revoked certificates (CRL)\nin the PEM format used to verify\nthe certificate of the secured uwsgi server.\nWhen using intermediate certificates, their CRLs should be\nspecified in the same file.\n
| \n Syntax:\n | \n\n uwsgi_ssl_key_log path;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.27.2.\n
\nEnables logging of secured uwsgi server connection SSL keys\nand specifies the path to the key log file.\nKeys are logged in the\nSSLKEYLOGFILE\nformat compatible with Wireshark.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n uwsgi_ssl_name \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_ssl_name host from uwsgi_pass;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.0.\n
\nAllows overriding the server name used to\nverify\nthe certificate of the secured uwsgi server and to be\npassed through SNI\nwhen establishing a connection with the secured uwsgi server.\n
\nBy default, the host part from uwsgi_pass is used.\n
| \n Syntax:\n | \n\n uwsgi_ssl_password_file \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.8.\n
\nSpecifies a file with passphrases for\nsecret keys\nwhere each passphrase is specified on a separate line.\nPassphrases are tried in turn when loading the key.\n
| \n Syntax:\n | \n\n uwsgi_ssl_protocols \n [\n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_ssl_protocols TLSv1.2 TLSv1.3;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.8.\n
\nEnables the specified protocols for requests to a secured uwsgi server.\n
\n
\nThe TLSv1.3 parameter is used by default\nsince 1.23.4.\n\n
| \n Syntax:\n | \n\n uwsgi_ssl_server_name \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_ssl_server_name off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.0.\n
\nEnables or disables passing of the server name through\nTLS\nServer Name Indication extension (SNI, RFC 6066)\nwhen establishing a connection with the secured uwsgi server.\n
| \n Syntax:\n | \n\n uwsgi_ssl_session_reuse \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_ssl_session_reuse on;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.8.\n
\nDetermines whether SSL sessions can be reused when working with\na secured uwsgi server.\nIf the errors\n“digest check failed”\nappear in the logs, try disabling session reuse.\n
| \n Syntax:\n | \n\n uwsgi_ssl_trusted_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.0.\n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to verify\nthe certificate of the secured uwsgi server.\n
| \n Syntax:\n | \n\n uwsgi_ssl_verify \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_ssl_verify off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.0.\n
\nEnables or disables verification of the secured uwsgi server certificate.\n
| \n Syntax:\n | \n\n uwsgi_ssl_verify_depth \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_ssl_verify_depth 1;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.7.0.\n
\nSets the verification depth in the secured uwsgi server certificates chain.\n
| \n Syntax:\n | \n\n uwsgi_store \n \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_store off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables saving of files to a disk.\nThe on parameter saves files with paths\ncorresponding to the directives\nalias or\nroot.\nThe off parameter disables saving of files.\nIn addition, the file name can be set explicitly using the\nstring with variables:\n
\nuwsgi_store /data/www$original_uri;\n
\n
\nThe modification time of files is set according to the received\n“Last-Modified” response header field.\nThe response is first written to a temporary file,\nand then the file is renamed.\nStarting from version 0.8.9, temporary files and the persistent store\ncan be put on different file systems.\nHowever, be aware that in this case a file is copied\nacross two file systems instead of the cheap renaming operation.\nIt is thus recommended that for any given location both saved files and a\ndirectory holding temporary files, set by the uwsgi_temp_path\ndirective, are put on the same file system.\n
\nThis directive can be used to create local copies of static unchangeable\nfiles, e.g.:\n
\nlocation /images/ {\n root /data/www;\n error_page 404 = /fetch$uri;\n}\n\nlocation /fetch/ {\n internal;\n\n uwsgi_pass backend:9000;\n ...\n\n uwsgi_store on;\n uwsgi_store_access user:rw group:rw all:r;\n uwsgi_temp_path /data/temp;\n\n alias /data/www/;\n}\n\n
| \n Syntax:\n | \n\n uwsgi_store_access \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_store_access user:rw;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets access permissions for newly created files and directories, e.g.:\n
\nuwsgi_store_access user:rw group:rw all:r;\n
\n
\nIf any group or all access permissions\nare specified then user permissions may be omitted:\n
\nuwsgi_store_access group:rw all:r;\n
\n
| \n Syntax:\n | \n\n uwsgi_temp_file_write_size \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_temp_file_write_size 8k|16k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nLimits the size of data written to a temporary file\nat a time, when buffering of responses from the uwsgi server\nto temporary files is enabled.\nBy default, size is limited by two buffers set by the\nuwsgi_buffer_size and uwsgi_buffers directives.\nThe maximum size of a temporary file is set by the\nuwsgi_max_temp_file_size directive.\n
| \n Syntax:\n | \n\n uwsgi_temp_path \n \n | \n
|---|---|
| \n Default:\n | \n\n uwsgi_temp_path uwsgi_temp;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nDefines a directory for storing temporary files\nwith data received from uwsgi servers.\nUp to three-level subdirectory hierarchy can be used underneath the specified\ndirectory.\nFor example, in the following configuration\n
\nuwsgi_temp_path /spool/nginx/uwsgi_temp 1 2;\n
\na temporary file might look like this:\n
\n/spool/nginx/uwsgi_temp/7/45/00000123457\n
\n
\nSee also the use_temp_path parameter of the\nuwsgi_cache_path directive.\n
\nThe ngx_http_v2_module module (1.9.5) provides\nsupport for\nHTTP/2.\n
\nThis module is not built by default, it should be enabled with\nthe --with-http_v2_module\nconfiguration parameter.\n
\nBefore version 1.9.14,\nbuffering of a client request body could not be disabled\nregardless of\nproxy_request_buffering,\nfastcgi_request_buffering,\nuwsgi_request_buffering, and\nscgi_request_buffering\ndirective values.\n
\nBefore version 1.19.1,\nthe lingering_close mechanism\nwas not used to control closing HTTP/2 connections.\n
\n\n\n\n
\nserver {\n listen 443 ssl;\n\n http2 on;\n\n ssl_certificate server.crt;\n ssl_certificate_key server.key;\n}\n\nNote that accepting HTTP/2 connections over TLS requires\nthe “Application-Layer Protocol Negotiation” (ALPN) TLS extension\nsupport, which is available since\nOpenSSL version 1.0.2.\n
\nAlso note that if the\nssl_prefer_server_ciphers directive\nis set to the value “on”,\nthe ciphers\nshould be configured to comply with\nRFC 9113, Appendix A\nblack list and supported by clients.\n
| \n Syntax:\n | \n\n http2 \n | \n
|---|---|
| \n Default:\n | \n\n http2 off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.25.1.\n
\nEnables\nthe HTTP/2\nprotocol.\n
| \n Syntax:\n | \n\n http2_body_preread_size \n | \n
|---|---|
| \n Default:\n | \n\n http2_body_preread_size 64k;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.11.0.\n
\nSets the size of the buffer per each request\nin which the request body may be saved\nbefore it is started to be processed.\n
| \n Syntax:\n | \n\n http2_chunk_size \n | \n
|---|---|
| \n Default:\n | \n\n http2_chunk_size 8k;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSets the maximum size of chunks\ninto which the response body is sliced.\nA too low value results in higher overhead.\nA too high value impairs prioritization due to\n\nHOL blocking.\n
| \n Syntax:\n | \n\n http2_idle_timeout \n | \n
|---|---|
| \n Default:\n | \n\n http2_idle_timeout 3m;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\n
\nThis directive is obsolete since version 1.19.7.\nThe keepalive_timeout\ndirective should be used instead.\n
\n
\nSets the timeout of inactivity after which the connection is closed.\n
| \n Syntax:\n | \n\n http2_max_concurrent_pushes \n | \n
|---|---|
| \n Default:\n | \n\n http2_max_concurrent_pushes 10;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.13.9.\n
\n
\nThis directive is obsolete since version 1.25.1.\n
\n
\nLimits the maximum number of concurrent\npush requests in a connection.\n
| \n Syntax:\n | \n\n http2_max_concurrent_streams \n | \n
|---|---|
| \n Default:\n | \n\n http2_max_concurrent_streams 128;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSets the maximum number of concurrent HTTP/2 streams\nin a connection.\n
| \n Syntax:\n | \n\n http2_max_field_size \n | \n
|---|---|
| \n Default:\n | \n\n http2_max_field_size 4k;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\n
\nThis directive is obsolete since version 1.19.7.\nThe large_client_header_buffers\ndirective should be used instead.\n
\n
\nLimits the maximum size of\nan HPACK-compressed\nrequest header field.\nThe limit applies equally to both name and value.\nNote that if Huffman encoding is applied,\nthe actual size of decompressed name and value strings may be larger.\nFor most requests, the default limit should be enough.\n
| \n Syntax:\n | \n\n http2_max_header_size \n | \n
|---|---|
| \n Default:\n | \n\n http2_max_header_size 16k;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\n
\nThis directive is obsolete since version 1.19.7.\nThe large_client_header_buffers\ndirective should be used instead.\n
\n
\nLimits the maximum size of the entire request header list after\nHPACK decompression.\nFor most requests, the default limit should be enough.\n
| \n Syntax:\n | \n\n http2_max_requests \n | \n
|---|---|
| \n Default:\n | \n\n http2_max_requests 1000;\n | \n
| \n Context:\n | \n\n http, server\n | \n
This directive appeared in version 1.11.6.\n
\n
\nThis directive is obsolete since version 1.19.7.\nThe keepalive_requests\ndirective should be used instead.\n
\n
\nSets the maximum number of requests (including\npush requests) that can be served\nthrough one HTTP/2 connection,\nafter which the next client request will lead to connection closing\nand the need of establishing a new connection.\n
\nClosing connections periodically is necessary to free\nper-connection memory allocations.\nTherefore, using too high maximum number of requests\ncould result in excessive memory usage and not recommended.\n
| \n Syntax:\n | \n\n http2_push \n | \n
|---|---|
| \n Default:\n | \n\n http2_push off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.13.9.\n
\n
\nThis directive is obsolete since version 1.25.1.\nThe early_hints\ndirective can be used instead.\n
\n
\nPre-emptively sends\n(pushes)\na request to the specified uri\nalong with the response to the original request.\nOnly relative URIs with absolute path will be processed,\nfor example:\n
\nhttp2_push /static/css/main.css;\n
\nThe uri value can contain variables.\n
\nSeveral http2_push directives\ncan be specified on the same configuration level.\nThe off parameter cancels the effect\nof the http2_push directives\ninherited from the previous configuration level.\n
| \n Syntax:\n | \n\n http2_push_preload \n | \n
|---|---|
| \n Default:\n | \n\n http2_push_preload off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.13.9.\n
\n
\nThis directive is obsolete since version 1.25.1.\n
\n
\nEnables automatic conversion of\npreload\nlinks\nspecified in the “Link” response header fields into\npush\nrequests.\n
| \n Syntax:\n | \n\n http2_recv_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n http2_recv_buffer_size 256k;\n | \n
| \n Context:\n | \n\n http\n | \n
\nSets the size of the per\nworker\ninput buffer.\n
| \n Syntax:\n | \n\n http2_recv_timeout \n | \n
|---|---|
| \n Default:\n | \n\n http2_recv_timeout 30s;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\n
\nThis directive is obsolete since version 1.19.7.\nThe client_header_timeout\ndirective should be used instead.\n
\n
\nSets the timeout for expecting more data from the client,\nafter which the connection is closed.\n
\n\n\n\nThe ngx_http_v2_module module\nsupports the following embedded variables:\n
$http2h2” for HTTP/2 over TLS,\n“h2c” for HTTP/2 over cleartext TCP,\nor an empty string otherwise.\n\n
\n\n\nThe ngx_http_v3_module module (1.25.0) provides\nexperimental support for\nHTTP/3.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_v3_module\nconfiguration parameter.\n
\nThis module requires the\nOpenSSL library\nversion 1.1.1 or higher.\n
\n
\n0-RTT support requires the\nOpenSSL library\nversion 3.5.1 or higher.\nAlternatively,\nBoringSSL,\nLibreSSL, or\nQuicTLS\nlibraries can be used to build and run this module.\n
\n
\n\n\n\nThe module is experimental, caveat emptor applies.\n
\nBefore version 1.29.1,\n0-RTT support could not be enabled with OpenSSL\nregardless of the\nssl_early_data\ndirective value.\n
\nThe module cannot be built on the Win32 platform.\n
\n\n\n\n
\nhttp {\n log_format quic '$remote_addr - $remote_user [$time_local] '\n '\"$request\" $status $body_bytes_sent '\n '\"$http_referer\" \"$http_user_agent\" \"$http3\"';\n\n access_log logs/access.log quic;\n\n server {\n # for better compatibility it's recommended\n # to use the same port for http/3 and https\n listen 8443 quic reuseport;\n listen 8443 ssl;\n\n ssl_certificate certs/example.com.crt;\n ssl_certificate_key certs/example.com.key;\n\n location / {\n # used to advertise the availability of HTTP/3\n add_header Alt-Svc 'h3=\":8443\"; ma=86400';\n }\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n http3 \n | \n
|---|---|
| \n Default:\n | \n\n http3 on;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nEnables\nHTTP/3\nprotocol negotiation.\n
| \n Syntax:\n | \n\n http3_hq \n | \n
|---|---|
| \n Default:\n | \n\n http3_hq off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nEnables HTTP/0.9 protocol negotiation\nused in\nQUIC\ninteroperability tests.\n
| \n Syntax:\n | \n\n http3_max_concurrent_streams \n | \n
|---|---|
| \n Default:\n | \n\n http3_max_concurrent_streams 128;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSets the maximum number of concurrent HTTP/3 request streams\nin a connection.\n
| \n Syntax:\n | \n\n http3_stream_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n http3_stream_buffer_size 64k;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSets the size of the buffer used for reading and writing of the\nQUIC streams.\n
| \n Syntax:\n | \n\n quic_active_connection_id_limit \n | \n
|---|---|
| \n Default:\n | \n\n quic_active_connection_id_limit 2;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSets the\nQUIC active_connection_id_limit transport parameter value.\nThis is the maximum number of client connection IDs\nwhich can be stored on the server.\n
| \n Syntax:\n | \n\n quic_bpf \n | \n
|---|---|
| \n Default:\n | \n\n quic_bpf off;\n | \n
| \n Context:\n | \n\n main\n | \n
\nEnables routing of QUIC packets using\neBPF.\nWhen enabled, this allows supporting QUIC connection migration.\n
\n
\nThe directive is only supported on Linux 5.7+.\n
\n
| \n Syntax:\n | \n\n quic_gso \n | \n
|---|---|
| \n Default:\n | \n\n quic_gso off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nEnables sending in optimized batch mode\nusing segmentation offloading.\n
\n
\nOptimized sending is supported only on Linux\nfeaturing UDP_SEGMENT.\n\n
| \n Syntax:\n | \n\n quic_host_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server\n | \n
\nSets a file with the secret key used to encrypt\nstateless reset and address validation tokens.\nBy default, a random key is generated on each reload.\nTokens generated with old keys are not accepted.\n
| \n Syntax:\n | \n\n quic_retry \n | \n
|---|---|
| \n Default:\n | \n\n quic_retry off;\n | \n
| \n Context:\n | \n\n http, server\n | \n
\nEnables the\nQUIC\nAddress Validation feature.\nThis includes sending a new token in a Retry packet\nor a NEW_TOKEN frame\nand\nvalidating a token received in the Initial packet.\n
\nThe ngx_http_v3_module module\nsupports the following embedded variables:\n
$http3h3” for HTTP/3 connections,\n“hq” for hq connections,\nor an empty string otherwise.\n\n
\n\n| Example Configuration Directives xml_entities xslt_last_modified xslt_param xslt_string_param xslt_stylesheet xslt_types |
\nThe ngx_http_xslt_module (0.7.8+) is a filter\nthat transforms XML responses using one or more XSLT stylesheets.\n
\nThis module is not built by default, it should be enabled with the\n--with-http_xslt_module\nconfiguration parameter.\n
\nThis module requires the\nlibxml2 and\nlibxslt libraries.\n
\n
\n\n\n\n
\nlocation / {\n xml_entities /site/dtd/entities.dtd;\n xslt_stylesheet /site/xslt/one.xslt param=value;\n xslt_stylesheet /site/xslt/two.xslt;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n xml_entities \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nSpecifies the DTD file that declares character entities.\nThis file is compiled at the configuration stage.\nFor technical reasons, the module is unable to use the\nexternal subset declared in the processed XML, so it is\nignored and a specially defined file is used instead.\nThis file should not describe the XML structure.\nIt is enough to declare just the required character entities, for example:\n
\n<!ENTITY nbsp \" \">\n
\n
| \n Syntax:\n | \n\n xslt_last_modified \n | \n
|---|---|
| \n Default:\n | \n\n xslt_last_modified off;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.5.1.\n
\nAllows preserving the “Last-Modified” header field\nfrom the original response during XSLT transformations\nto facilitate response caching.\n
\nBy default, the header field is removed as contents of the response\nare modified during transformations and may contain dynamically generated\nelements or parts that are changed independently of the original response.\n
| \n Syntax:\n | \n\n xslt_param \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.18.\n
\nDefines the parameters for XSLT stylesheets.\nThe value is treated as an XPath expression.\nThe value can contain variables.\nTo pass a string value to a stylesheet,\nthe xslt_string_param directive can be used.\n
\nThere could be several xslt_param directives.\nThese directives are inherited from the previous configuration level\nif and only if there are no xslt_param and\nxslt_string_param directives\ndefined on the current level.\n
| \n Syntax:\n | \n\n xslt_string_param \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n http, server, location\n | \n
This directive appeared in version 1.1.18.\n
\nDefines the string parameters for XSLT stylesheets.\nXPath expressions in the value are not interpreted.\nThe value can contain variables.\n
\nThere could be several xslt_string_param directives.\nThese directives are inherited from the previous configuration level\nif and only if there are no xslt_param and\nxslt_string_param directives\ndefined on the current level.\n
| \n Syntax:\n | \n\n xslt_stylesheet \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n location\n | \n
\nDefines the XSLT stylesheet and its optional parameters.\nA stylesheet is compiled at the configuration stage.\n
\nParameters can either be specified separately, or grouped in a\nsingle line using the “:” delimiter.\nIf a parameter includes the “:” character,\nit should be escaped as “%3A”.\nAlso, libxslt requires to enclose parameters\nthat contain non-alphanumeric characters into single or double quotes,\nfor example:\n
\nparam1='http%3A//www.example.com':param2=value2\n
\n
\nThe parameters description can contain variables, for example,\nthe whole line of parameters can be taken from a single variable:\n
\nlocation / {\n xslt_stylesheet /site/xslt/one.xslt\n $arg_xslt_params\n param1='$value1':param2=value2\n param3=value3;\n}\n\n
\nIt is possible to specify several stylesheets.\nThey will be applied sequentially in the specified order.\n
| \n Syntax:\n | \n\n xslt_types \n | \n
|---|---|
| \n Default:\n | \n\n xslt_types text/xml;\n | \n
| \n Context:\n | \n\n http, server, location\n | \n
\nEnables transformations in responses with the specified MIME types\nin addition to “text/xml”.\nThe special value “*” matches any MIME type (0.8.29).\nIf the transformation result is an HTML response, its MIME type\nis changed to “text/html”.\n
| How to prevent processing requests with undefined server names Mixed name-based and IP-based virtual servers A simple PHP site configuration |
\nnginx first decides which server should process the request.\nLet’s start with a simple configuration\nwhere all three virtual servers listen on port *:80:\n
\nserver {\n listen 80;\n server_name example.org www.example.org;\n ...\n}\n\nserver {\n listen 80;\n server_name example.net www.example.net;\n ...\n}\n\nserver {\n listen 80;\n server_name example.com www.example.com;\n ...\n}\n\n\n
\nIn this configuration nginx tests only the request’s header field\n“Host” to determine which server the request should be routed to.\nIf its value does not match any server name,\nor the request does not contain this header field at all,\nthen nginx will route the request to the default server for this port.\nIn the configuration above, the default server is the first\none — which is nginx’s standard default behaviour.\nIt can also be set explicitly which server should be default,\nwith the default_server parameter\nin the listen directive:\n
\nserver {\n listen 80 default_server;\n server_name example.net www.example.net;\n ...\n}\n\n\n
\nThedefault_serverparameter has been available since\nversion 0.8.21.\nIn earlier versions thedefaultparameter should be used\ninstead.\n
\nNote that the default server is a property of the listen port\nand not of the server name.\nMore about this later.\n
\nIf requests without the “Host” header field should not be\nallowed, a server that just drops the requests can be defined:\n
\nserver {\n listen 80;\n server_name \"\";\n return 444;\n}\n\nHere, the server name is set to an empty string that will match\nrequests without the “Host” header field,\nand a special nginx’s non-standard code 444\nis returned that closes the connection.\n
\nSince version 0.8.48, this is the default setting for the\nserver name, so the server_name \"\" can be omitted.\nIn earlier versions, the machine’s hostname was used as\na default server name.\n\n
\nLet’s look at a more complex configuration\nwhere some virtual servers listen on different addresses:\n
\nserver {\n listen 192.168.1.1:80;\n server_name example.org www.example.org;\n ...\n}\n\nserver {\n listen 192.168.1.1:80;\n server_name example.net www.example.net;\n ...\n}\n\nserver {\n listen 192.168.1.2:80;\n server_name example.com www.example.com;\n ...\n}\n \nIn this configuration, nginx first tests the IP address and port\nof the request against the\nlisten directives\nof the\nserver blocks.\nIt then tests the “Host”\nheader field of the request against the\nserver_name\nentries of the\nserver\nblocks that matched\nthe IP address and port.\nIf the server name is not found, the request will be processed by\nthe default server.\nFor example, a request for www.example.com received on\nthe 192.168.1.1:80 port will be handled by the default server\nof the 192.168.1.1:80 port, i.e., by the first server,\nsince there is no www.example.com defined for this port.\n
\nAs already stated, a default server is a property of the listen port,\nand different default servers may be defined for different ports:\n
\nserver {\n listen 192.168.1.1:80;\n server_name example.org www.example.org;\n ...\n}\n\nserver {\n listen 192.168.1.1:80 default_server;\n server_name example.net www.example.net;\n ...\n}\n\nserver {\n listen 192.168.1.2:80 default_server;\n server_name example.com www.example.com;\n ...\n}\n\n\n
\nNow let’s look at how nginx chooses a location to process a request\nfor a typical, simple PHP site:\n
\nserver {\n listen 80;\n server_name example.org www.example.org;\n root /data/www;\n\n location / {\n index index.html index.php;\n }\n\n location ~* \\.(gif|jpg|png)$ {\n expires 30d;\n }\n\n location ~ \\.php$ {\n fastcgi_pass localhost:9000;\n fastcgi_param SCRIPT_FILENAME\n $document_root$fastcgi_script_name;\n include fastcgi_params;\n }\n}\n\n\n
\nnginx first searches for the most specific prefix location given by\nliteral strings regardless of the listed order.\nIn the configuration above\nthe only prefix location is “/” and since it matches\nany request it will be used as a last resort.\nThen nginx checks locations given by\nregular expression in the order listed in the configuration file.\nThe first matching expression stops the search and nginx will use this\nlocation.\nIf no regular expression matches a request, then nginx uses\nthe most specific prefix location found earlier.\n
\nNote that locations of all types test only a URI part of request line\nwithout arguments.\nThis is done because arguments in the query string may be given in\nseveral ways, for example:\n
\n/index.php?user=john&page=1\n/index.php?page=1&user=john\n
\nBesides, anyone may request anything in the query string:\n
\n/index.php?page=1&something+else&user=john\n
\n\n
\nNow let’s look at how requests would be processed\nin the configuration above:\n
/logo.gif” is matched by the prefix location\n“/” first and then by the regular expression\n“\\.(gif|jpg|png)$”,\ntherefore, it is handled by the latter location.\nUsing the directive “root /data/www” the request\nis mapped to the file /data/www/logo.gif, and the file\nis sent to the client.\n/index.php” is also matched by the prefix location\n“/” first and then by the regular expression\n“\\.(php)$”.\nTherefore, it is handled by the latter location\nand the request is passed to a FastCGI server listening on localhost:9000.\nThe\nfastcgi_param\ndirective sets the FastCGI parameter\nSCRIPT_FILENAME to “/data/www/index.php”,\nand the FastCGI server executes the file.\nThe variable $document_root is equal to\nthe value of the\nroot\ndirective and the variable $fastcgi_script_name is equal to\nthe request URI, i.e. “/index.php”.\n/about.html” is matched by the prefix location\n“/” only, therefore, it is handled in this location.\nUsing the directive “root /data/www” the request is mapped\nto the file /data/www/about.html, and the file is sent\nto the client.\n/” is more complex.\nIt is matched by the prefix location “/” only,\ntherefore, it is handled by this location.\nThen the\nindex\ndirective tests for the existence\nof index files according to its parameters and\nthe “root /data/www” directive.\nIf the file /data/www/index.html does not exist,\nand the file /data/www/index.php exists,\nthen the directive does an internal redirect to “/index.php”,\nand nginx searches the locations again\nas if the request had been sent by a client.\nAs we saw before, the redirected request will eventually be handled\nby the FastCGI server.\n\n\n
| written by Igor Sysoev edited by Brian Mercer |
| Wildcard names Regular expressions names Miscellaneous names Internationalized names Virtual server selection Optimization Compatibility |
\nServer names are defined using the\nserver_name\ndirective\nand determine which server block\nis used for a given request.\nSee also “How nginx processes a request”.\nThey may be defined using exact names, wildcard names, or regular expressions:\n\n
\nserver {\n listen 80;\n server_name example.org www.example.org;\n ...\n}\n\nserver {\n listen 80;\n server_name *.example.org;\n ...\n}\n\nserver {\n listen 80;\n server_name mail.*;\n ...\n}\n\nserver {\n listen 80;\n server_name ~^(?<user>.+)\\.example\\.net$;\n ...\n}\n\n
\nThe search is performed in the following order of priority\nand terminates on the first matching variant:\n
*.example.org”\nmail.*”\n\n
\nA wildcard name may contain an asterisk only on the name’s start or end,\nand only on a dot border. The names “www.*.example.org”\nand “w*.example.org” are invalid.\nHowever, these names can be specified using regular expressions,\nfor example, “~^www\\..+\\.example\\.org$” and\n“~^w.*\\.example\\.org$”.\nAn asterisk can match several name parts.\nThe name “*.example.org” matches not only\nwww.example.org but www.sub.example.org as well.\n
\nA special wildcard name in the form “.example.org” can be\nused to match both the exact name “example.org”\nand the wildcard name ���*.example.org”.\n
\nThe regular expressions used by nginx are compatible with those used\nby the Perl programming language (PCRE).\nTo use a regular expression, the server name must start with the tilde\ncharacter:\n\n
\nserver_name ~^www\\d+\\.example\\.net$;\n
\n\notherwise it will be treated as an exact name, or if the expression contains\nan asterisk, as a wildcard name (and most likely as an invalid one).\nDo not forget to set “^” and “$” anchors.\nThey are not required syntactically, but logically.\nAlso note that domain name dots should be escaped with a backslash.\nA regular expression containing the characters “{”\nand “}” should be quoted:\n\n
\nserver_name \"~^(?<name>\\w\\d{1,3}+)\\.example\\.net$\";\n\n\notherwise nginx will fail to start and display the error message:\n\n
\ndirective \"server_name\" is not terminated by \";\" in ...\n
\n\nA named regular expression capture can be used later as a variable:\n\n
\nserver {\n server_name ~^(www\\.)?(?<domain>.+)$;\n\n location / {\n root /sites/$domain;\n }\n}\n\n\nThe PCRE library supports named captures using the following syntax:\n\n
\n\nIf nginx fails to start and displays the error message:\n\n\n\n
\n \n\n\n ?<name>Perl 5.10 compatible syntax, supported since PCRE-7.0 \n\n \n\n\n ?'name'Perl 5.10 compatible syntax, supported since PCRE-7.0 \n\n \n\n\n ?P<name>Python compatible syntax, supported since PCRE-4.0 \n
\npcre_compile() failed: unrecognized character after (?< in ...\n
\n\nthis means that the PCRE library is old and the syntax\n“?P<” should be tried instead.\nThe captures can also be used in digital form:\n\nname>
\nserver {\n server_name ~^(www\\.)?(.+)$;\n\n location / {\n root /sites/$2;\n }\n}\n\n\nHowever, such usage should be limited to simple cases (like the above),\nsince the digital references can easily be overwritten.\n
\nThere are some server names that are treated specially.\n
\nIf it is required to process requests without the “Host”\nheader field in a server\nblock which is not the default, an empty name should be specified:\n\n
\nserver {\n listen 80;\n server_name example.org www.example.org \"\";\n ...\n}\n\n
\nIf no\nserver_name\nis defined in a server block\nthen nginx uses the empty name as the server name.\n
\nnginx versions up to 0.8.48 used the machine’s hostname as the server name\nin this case.\n
\n
\nIf a server name is defined as “$hostname” (0.9.4), the\nmachine’s hostname is used.\n
\nIf someone makes a request using an IP address instead of a server name,\nthe “Host” request header field will contain the IP address\nand the request can be handled using the IP address as the server name:\n\n
\nserver {\n listen 80;\n server_name example.org\n www.example.org\n \"\"\n 192.168.1.1\n ;\n ...\n}\n\n
\nIn catch-all server examples the strange name “_” can\nbe seen:\n\n
\nserver {\n listen 80 default_server;\n server_name _;\n return 444;\n}\n \n\nThere is nothing special about this name, it is just one of a myriad\nof invalid domain names which never intersect with any real name.\nOther invalid names like “--” and “!@#”\nmay equally be used.\n
\nnginx versions up to 0.6.25 supported the special name “*”\nwhich was erroneously interpreted to be a catch-all name.\nIt never functioned as a catch-all or wildcard server name.\nInstead, it supplied the functionality that is now provided\nby the\nserver_name_in_redirect\ndirective.\nThe special name “*” is now deprecated\nand the\nserver_name_in_redirect\ndirective should be used.\nNote that there is no way to specify the catch-all name or\nthe default server using the\nserver_name\ndirective.\nThis is a property of the\nlisten\ndirective\nand not of the\nserver_name\ndirective.\nSee also “How nginx processes a request”.\nIt is possible to define servers listening on ports *:80 and *:8080,\nand direct that one will be the default server for port *:8080,\nwhile the other will be the default for port *:80:\n\n
\nserver {\n listen 80;\n listen 8080 default_server;\n server_name example.net;\n ...\n}\n\nserver {\n listen 80 default_server;\n listen 8080;\n server_name example.org;\n ...\n}\n\n
\nInternationalized domain names\n(IDNs)\nshould be specified using an ASCII (Punycode) representation\nin the server_name directive:\n
\nserver {\n listen 80;\n server_name xn--e1afmkfd.xn--80akhbyknj4f; # пример.испытание\n ...\n}\n\n
\nFirst, a connection is created in a default server context.\nThen, the server name can be determined\nin the following request processing stages,\neach involved in server configuration selection:\n\n
\nduring SSL handshake, in advance, according to\nSNI\n
\n\nafter processing the request line\n
\n\nafter processing the Host header field\n
\nif the server name was not determined after processing the request line or\nfrom the Host header field,\nnginx will use the empty name as the server name.\n
\n\nAt each of these stages, different server configurations can be applied.\nAs such, certain directives should be specified with caution:\n
Host header field;\n\n
\nExact names, wildcard names starting with an asterisk,\nand wildcard names ending with an asterisk are stored\nin three hash tables bound to the listen ports.\nThe sizes of hash tables are optimized at the configuration phase\nso that a name can be found with the fewest CPU cache misses.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
\nThe exact names hash table is searched first.\nIf a name is not found, the hash table with wildcard names\nstarting with an asterisk is searched.\nIf the name is not found there, the hash table with wildcard names\nending with an asterisk is searched.\n
\nSearching wildcard names hash table is slower than searching exact names hash\ntable because names are searched by domain parts.\nNote that the special wildcard form “.example.org”\nis stored in a wildcard names hash table and not in an exact names hash table.\n
\nRegular expressions are tested sequentially\nand therefore are the slowest method and are non-scalable.\n
\nFor these reasons, it is better to use exact names where possible.\nFor example, if the most frequently requested names of a server\nare example.org and www.example.org,\nit is more efficient to define them explicitly:\n\n
\nserver {\n listen 80;\n server_name example.org www.example.org *.example.org;\n ...\n}\n\n\nthan to use the simplified form:\n\n
\nserver {\n listen 80;\n server_name .example.org;\n ...\n}\n\n
\nIf a large number of server names are defined,\nor unusually long server names are defined, tuning\nthe server_names_hash_max_size\nand server_names_hash_bucket_size\ndirectives at the http level may become necessary.\nThe default value of the\nserver_names_hash_bucket_size\ndirective may be equal to 32, or 64, or another value,\ndepending on CPU cache line size.\nIf the default value is 32 and server name is defined as\n“too.long.server.name.example.org”\nthen nginx will fail to start and display the error message:\n\n
\ncould not build the server_names_hash,\nyou should increase server_names_hash_bucket_size: 32\n
\n\nIn this case, the directive value should be increased to the next power of two:\n\n
\nhttp {\n server_names_hash_bucket_size 64;\n ...\n\n\nIf a large number of server names are defined,\nanother error message will appear:\n\n
\ncould not build the server_names_hash,\nyou should increase either server_names_hash_max_size: 512\nor server_names_hash_bucket_size: 32\n
\n\nIn such a case, first try to set\nserver_names_hash_max_size\nto a number close to the number of server names.\nOnly if this does not help,\nor if nginx’s start time is unacceptably long, try to increase\nserver_names_hash_bucket_size.\n
\nIf a server is the only server for a listen port, then nginx will not test\nserver names at all (and will not build the hash tables for the listen port).\nHowever, there is one exception.\nIf a server name is a regular expression with captures,\nthen nginx has to execute the expression to get the captures.\n
\n
$hostname” has been supported\nsince 0.9.4.\nexample.* has been supported since 0.6.0.\n.example.org has been supported since 0.3.18.\n*.example.org has been supported since 0.1.13.\n\n
| written by Igor Sysoev edited by Brian Mercer |
\nTo turn a connection between a client and server from HTTP/1.1 into WebSocket,\nthe protocol\nswitch mechanism available in HTTP/1.1 is used.\n
\nThere is one subtlety however: since the “Upgrade” is a\nhop-by-hop\nheader, it is not passed from a client to proxied server.\nWith forward proxying, clients may use the CONNECT\nmethod to circumvent this issue.\nThis does not work with reverse proxying however,\nsince clients are not aware of any proxy servers,\nand special processing on a proxy server is required.\n
\nSince version 1.3.13,\nnginx implements special mode of operation\nthat allows setting up a tunnel between a client and proxied\nserver if the proxied server returned a response with the code\n101 (Switching Protocols),\nand the client asked for a protocol switch via the “Upgrade”\nheader in a request.\n
\nAs noted above, hop-by-hop headers including “Upgrade”\nand “Connection” are not passed from a client to proxied\nserver, therefore in order for the proxied server to know about the client’s\nintention to switch a protocol to WebSocket, these headers have to be\npassed explicitly:\n
\nlocation /chat/ {\n proxy_pass http://backend;\n # proxy_http_version 1.1; # before version 1.29.7\n proxy_set_header Upgrade $http_upgrade;\n proxy_set_header Connection \"upgrade\";\n}\n\nA more sophisticated example\nin which a value of the “Connection” header field\nin a request to the proxied server depends on the presence of\nthe “Upgrade” field in the client request header:\n
\nhttp {\n map $http_upgrade $connection_upgrade {\n default upgrade;\n '' close;\n }\n\n server {\n ...\n\n location /chat/ {\n proxy_pass http://backend;\n # proxy_http_version 1.1; # before version 1.29.7\n proxy_set_header Upgrade $http_upgrade;\n proxy_set_header Connection $connection_upgrade;\n }\n }\n\n
\nBy default, the connection will be closed\nif the proxied server does not transmit any data within 60 seconds.\nThis timeout can be increased with the\nproxy_read_timeout directive.\nAlternatively, the proxied server can be configured\nto periodically send WebSocket ping frames to reset the timeout\nand check if the connection is still alive.\n
| Directives auth_http auth_http_header auth_http_pass_client_cert auth_http_timeout Protocol |
| \n Syntax:\n | \n\n auth_http \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets the URL of the HTTP authentication server.\nThe protocol is described below.\n
| \n Syntax:\n | \n\n auth_http_header \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nAppends the specified header to requests sent to the authentication server.\nThis header can be used as the shared secret to verify\nthat the request comes from nginx.\nFor example:\n
\nauth_http_header X-Auth-Key \"secret_string\";\n
\n
| \n Syntax:\n | \n\n auth_http_pass_client_cert \n | \n
|---|---|
| \n Default:\n | \n\n auth_http_pass_client_cert off;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 1.7.11.\n
\nAppends the “Auth-SSL-Cert” header with the\nclient\ncertificate in the PEM format (urlencoded)\nto requests sent to the authentication server.\n
| \n Syntax:\n | \n\n auth_http_timeout \n | \n
|---|---|
| \n Default:\n | \n\n auth_http_timeout 60s;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets the timeout for communication with the authentication server.\n
\n\n\n\nThe HTTP protocol is used to communicate with the authentication server.\nThe data in the response body is ignored, the information is passed only in\nthe headers.\n
\nExamples of requests and responses:\n
\nRequest:\n
\nGET /auth HTTP/1.0\nHost: localhost\nAuth-Method: plain # plain/apop/cram-md5/external\nAuth-User: user\nAuth-Pass: password\nAuth-Protocol: imap # imap/pop3/smtp\nAuth-Login-Attempt: 1\nClient-IP: 192.0.2.42\nClient-Host: client.example.org\n
\nGood response:\n
\nHTTP/1.0 200 OK\nAuth-Status: OK\nAuth-Server: 198.51.100.1\nAuth-Port: 143\n
\nBad response:\n
\nHTTP/1.0 200 OK\nAuth-Status: Invalid login or password\nAuth-Wait: 3\n
\n
\nIf there is no “Auth-Wait” header,\nan error will be returned and the connection will be closed.\nThe current implementation allocates memory for each authentication attempt.\nThe memory is freed only at the end of a session.\nTherefore, the number of invalid authentication attempts in a single session\nmust be limited — the server must respond without\nthe “Auth-Wait” header after 10-20 attempts\n(the attempt number is passed in the “Auth-Login-Attempt”\nheader).\n
\nWhen the APOP or CRAM-MD5 are used, request-response will look as follows:\n
\nGET /auth HTTP/1.0\nHost: localhost\nAuth-Method: apop\nAuth-User: user\nAuth-Salt: <238188073.1163692009@mail.example.com>\nAuth-Pass: auth_response\nAuth-Protocol: imap\nAuth-Login-Attempt: 1\nClient-IP: 192.0.2.42\nClient-Host: client.example.org\n
\nGood response:\n
\nHTTP/1.0 200 OK\nAuth-Status: OK\nAuth-Server: 198.51.100.1\nAuth-Port: 143\nAuth-Pass: plain-text-pass\n
\n
\nIf the “Auth-User” header exists in the response,\nit overrides the username used to authenticate with the backend.\n
\nFor the SMTP, the response additionally takes into account\nthe “Auth-Error-Code” header — if exists, it is used\nas a response code in case of an error.\nOtherwise, the 535 5.7.0 code will be added to\nthe “Auth-Status” header.\n
\nFor example, if the following response is received\nfrom the authentication server:\n
\nHTTP/1.0 200 OK\nAuth-Status: Temporary server problem, try again later\nAuth-Error-Code: 451 4.3.0\nAuth-Wait: 3\n
\nthen the SMTP client will receive an error\n
\n451 4.3.0 Temporary server problem, try again later\n
\n
\nIf proxying SMTP does not require authentication,\nthe request will look as follows:\n
\nGET /auth HTTP/1.0\nHost: localhost\nAuth-Method: none\nAuth-User:\nAuth-Pass:\nAuth-Protocol: smtp\nAuth-Login-Attempt: 1\nClient-IP: 192.0.2.42\nClient-Host: client.example.org\nAuth-SMTP-Helo: client.example.org\nAuth-SMTP-From: MAIL FROM: <>\nAuth-SMTP-To: RCPT TO: <postmaster@mail.example.com>\n
\n
\nFor the SSL/TLS client connection (1.7.11),\nthe “Auth-SSL” header is added, and\n“Auth-SSL-Verify” will contain\nthe result of client certificate verification, if\nenabled:\n“SUCCESS”, “FAILED:reason”,\nand “NONE” if a certificate was not present.\n
\nPrior to version 1.11.7, the “FAILED” result\ndid not contain thereasonstring.\n
\nWhen the client certificate was present,\nits details are passed in the following request headers:\n“Auth-SSL-Subject”, “Auth-SSL-Issuer”,\n“Auth-SSL-Serial”, and “Auth-SSL-Fingerprint”.\nIf auth_http_pass_client_cert is enabled,\nthe certificate itself is passed in the\n“Auth-SSL-Cert” header.\nThe protocol and cipher of the established connection\nare passed in the “Auth-SSL-Protocol”\nand “Auth-SSL-Cipher” headers (1.21.2).\nThe request will look as follows:\n
\nGET /auth HTTP/1.0\nHost: localhost\nAuth-Method: plain\nAuth-User: user\nAuth-Pass: password\nAuth-Protocol: imap\nAuth-Login-Attempt: 1\nClient-IP: 192.0.2.42\nAuth-SSL: on\nAuth-SSL-Protocol: TLSv1.3\nAuth-SSL-Cipher: TLS_AES_256_GCM_SHA384\nAuth-SSL-Verify: SUCCESS\nAuth-SSL-Subject: /CN=example.com\nAuth-SSL-Issuer: /CN=example.com\nAuth-SSL-Serial: C07AD56B846B5BFF\nAuth-SSL-Fingerprint: 29d6a80a123d13355ed16b4b04605e29cb55a5ad\n
\n
\nWhen the\nPROXY protocol\nis used,\nits details are passed in the following request headers:\n“Proxy-Protocol-Addr”,\n“Proxy-Protocol-Port”,\n“Proxy-Protocol-Server-Addr”, and\n“Proxy-Protocol-Server-Port” (1.19.8).\n
\n\n| Example Configuration Directives listen max_errors protocol resolver resolver_timeout server server_name timeout |
\nThis module is not built by default, it should be\nenabled with\nthe --with-mail configuration parameter.\n
\n
\nworker_processes auto;\n\nerror_log /var/log/nginx/error.log info;\n\nevents {\n worker_connections 1024;\n}\n\nmail {\n server_name mail.example.com;\n auth_http localhost:9000/cgi-bin/nginxauth.cgi;\n\n imap_capabilities IMAP4rev1 UIDPLUS IDLE LITERAL+ QUOTA;\n\n pop3_auth plain apop cram-md5;\n pop3_capabilities LAST TOP USER PIPELINING UIDL;\n\n smtp_auth login plain cram-md5;\n smtp_capabilities \"SIZE 10485760\" ENHANCEDSTATUSCODES 8BITMIME DSN;\n xclient off;\n\n server {\n listen 25;\n protocol smtp;\n }\n server {\n listen 110;\n protocol pop3;\n proxy_pass_error_message on;\n }\n server {\n listen 143;\n protocol imap;\n }\n server {\n listen 587;\n protocol smtp;\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n listen \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server\n | \n
\nSets the address and port for the socket\non which the server will accept requests.\nIt is possible to specify just the port.\nThe address can also be a hostname, for example:\n
\nlisten 127.0.0.1:110;\nlisten *:110;\nlisten 110; # same as *:110\nlisten localhost:110;\n
\nIPv6 addresses (0.7.58) are specified in square brackets:\n
\nlisten [::1]:110;\nlisten [::]:110;\n
\nUNIX-domain sockets (1.3.5) are specified with the “unix:”\nprefix:\n
\nlisten unix:/var/run/nginx.sock;\n
\n\n
\nDifferent servers must listen on different\naddress:port pairs.\n
\nThe ssl parameter allows specifying that all\nconnections accepted on this port should work in SSL mode.\n
\nThe proxy_protocol parameter (1.19.8)\nallows specifying that all connections accepted on this port should use the\nPROXY\nprotocol.\nObtained information is passed to the\nauthentication server\nand can be used to\nchange the client address.\n
\nThe listen directive\ncan have several additional parameters specific to socket-related system calls.\n
backlog=number\nbacklog parameter in the\nlisten() call that limits\nthe maximum length for the queue of pending connections (1.9.2).\nBy default,\nbacklog is set to -1 on FreeBSD, DragonFly BSD, and macOS,\nand to 511 on other platforms.\nrcvbuf=size\nSO_RCVBUF option) for the listening socket (1.11.13).\nsndbuf=size\nSO_SNDBUF option) for the listening socket (1.11.13).\nbind\nbind()\ncall for a given address:port pair.\nThe fact is that if there are several listen directives with\nthe same port but different addresses, and one of the\nlisten directives listens on all addresses\nfor the given port (*:port), nginx will\nbind() only to *:port.\nIt should be noted that the getsockname() system call will be\nmade in this case to determine the address that accepted the connection.\nIf the backlog,\nrcvbuf, sndbuf,\nipv6only, multipath,\nor so_keepalive parameters\nare used then for a given\naddress:port pair\na separate bind() call will always be made.\nipv6only=on|off\nIPV6_V6ONLY socket option)\nwhether an IPv6 socket listening on a wildcard address [::]\nwill accept only IPv6 connections or both IPv6 and IPv4 connections.\nThis parameter is turned on by default.\nIt can only be set once on start.\nmultipath\nIPPROTO_MPTCP) for the listening socket.\nThis currently works only on Linux 5.6+.\n\nAdding or removing this parameter will also enable\nthe SO_REUSEPORT socket option, which may have its security\nimplications.\n\nso_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]\non”, the\nSO_KEEPALIVE option is turned on for the socket.\nIf it is set to the value “off”, the\nSO_KEEPALIVE option is turned off for the socket.\nSome operating systems support setting of TCP keepalive parameters on\na per-socket basis using the TCP_KEEPIDLE,\nTCP_KEEPINTVL, and TCP_KEEPCNT socket options.\nOn such systems\n(currently, Linux, NetBSD, Dragonfly, FreeBSD, and macOS),\nthey can be configured\nusing the keepidle, keepintvl, and\nkeepcnt parameters.\nOne or two parameters may be omitted, in which case the system default setting\nfor the corresponding socket option will be in effect.\nFor example,\n\nwill set the idle timeout (so_keepalive=30m::10
TCP_KEEPIDLE) to 30 minutes,\nleave the probe interval (TCP_KEEPINTVL) at its system default,\nand set the probes count (TCP_KEEPCNT) to 10 probes.\n\n
| \n Syntax:\n | \n\n mail { ... }\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
\nProvides the configuration file context in which the mail server directives\nare specified.\n
| \n Syntax:\n | \n\n max_errors \n | \n
|---|---|
| \n Default:\n | \n\n max_errors 5;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 1.21.0.\n
\nSets the number of protocol errors after which the connection is closed.\n
| \n Syntax:\n | \n\n protocol \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server\n | \n
\nSets the protocol for a proxied server.\nSupported protocols are\nIMAP,\nPOP3, and\nSMTP.\n
\nIf the directive is not set, the protocol can be detected automatically\nbased on the well-known port specified in the listen\ndirective:\n
imap: 143, 993\npop3: 110, 995\nsmtp: 25, 587, 465\n\n
\nUnnecessary protocols can be disabled using the\nconfiguration\nparameters --without-mail_imap_module,\n--without-mail_pop3_module, and\n--without-mail_smtp_module.\n
| \n Syntax:\n | \n\n resolver \n resolver \n | \n
|---|---|
| \n Default:\n | \n\n resolver off;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nConfigures name servers used to find the client’s hostname\nto pass it to the\nauthentication server,\nand in the\nXCLIENT\ncommand when proxying SMTP.\nFor example:\n
\nresolver 127.0.0.1 [::1]:5353;\n
\nThe address can be specified as a domain name or IP address,\nwith an optional port (1.3.1, 1.2.2).\nIf port is not specified, the port 53 is used.\nName servers are queried in a round-robin fashion.\n
\nBefore version 1.1.7, only a single name server could be configured.\nSpecifying name servers using IPv6 addresses is supported\nstarting from versions 1.3.1 and 1.2.2.\n
\n
\nBy default, nginx will look up both IPv4 and IPv6 addresses while resolving.\nIf looking up of IPv4 or IPv6 addresses is not desired,\nthe ipv4=off (1.23.1) or\nthe ipv6=off parameter can be specified.\n
\nResolving of names into IPv6 addresses is supported\nstarting from version 1.5.8.\n
\n
\nBy default, nginx caches answers using the TTL value of a response.\nAn optional valid parameter allows overriding it:\n
\nresolver 127.0.0.1 [::1]:5353 valid=30s;\n
\n
\nBefore version 1.1.9, tuning of caching time was not possible,\nand nginx always cached answers for the duration of 5 minutes.\n
\n
\nTo prevent DNS spoofing, it is recommended\nconfiguring DNS servers in a properly secured trusted local network.\n
\n
\nThe optional status_zone parameter (1.17.1)\nenables\ncollection\nof DNS server statistics of requests and responses\nin the specified zone.\nThe parameter is available as part of our\ncommercial subscription.\n
\nThe special value off disables resolving.\n
| \n Syntax:\n | \n\n resolver_timeout \n | \n
|---|---|
| \n Default:\n | \n\n resolver_timeout 30s;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets a timeout for DNS operations, for example:\n
\nresolver_timeout 5s;\n
\n
| \n Syntax:\n | \n\n server { ... }\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mail\n | \n
\nSets the configuration for a server.\n
| \n Syntax:\n | \n\n server_name \n | \n
|---|---|
| \n Default:\n | \n\n server_name hostname;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets the server name that is used:\n
EHLO command when connecting to the SMTP backend,\nif the passing of the\nXCLIENT command\nis enabled.\n\n
\nIf the directive is not specified, the machine’s hostname is used.\n
| \n Syntax:\n | \n\n timeout \n | \n
|---|---|
| \n Default:\n | \n\n timeout 60s;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets the timeout that is used before proxying to the backend starts.\n
\n\n| Directives imap_auth imap_capabilities imap_client_buffer |
| \n Syntax:\n | \n\n imap_auth \n | \n
|---|---|
| \n Default:\n | \n\n imap_auth plain;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets permitted methods of authentication for IMAP clients.\nSupported methods are:\n
plainlogincram-md5external\n
\nPlain text authentication methods\n(the LOGIN command, AUTH=PLAIN,\nand AUTH=LOGIN) are always enabled,\nthough if the plain and login methods\nare not specified,\nAUTH=PLAIN and AUTH=LOGIN\nwill not be automatically included in imap_capabilities.\n
| \n Syntax:\n | \n\n imap_capabilities \n | \n
|---|---|
| \n Default:\n | \n\n imap_capabilities IMAP4 IMAP4rev1 UIDPLUS;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets the\nIMAP protocol\nextensions list that is passed to the client in response to\nthe CAPABILITY command.\nThe authentication methods specified in the imap_auth directive and\nSTARTTLS\nare automatically added to this list depending on the\nstarttls directive value.\n
\nIt makes sense to specify the extensions\nsupported by the IMAP backends\nto which the clients are proxied (if these extensions are related to commands\nused after the authentication, when nginx transparently proxies a client\nconnection to the backend).\n
\nThe current list of standardized extensions is published at\nwww.iana.org.\n
| \n Syntax:\n | \n\n imap_client_buffer \n | \n
|---|---|
| \n Default:\n | \n\n imap_client_buffer 4k|8k;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets the size of the buffer used for reading IMAP commands.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\n
| Directives pop3_auth pop3_capabilities |
| \n Syntax:\n | \n\n pop3_auth \n | \n
|---|---|
| \n Default:\n | \n\n pop3_auth plain;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets permitted methods of authentication for POP3 clients.\nSupported methods are:\n
plainapopcram-md5external\n
\nPlain text authentication methods\n(USER/PASS, AUTH PLAIN,\nand AUTH LOGIN) are always enabled,\nthough if the plain method is not specified,\nAUTH PLAIN and AUTH LOGIN\nwill not be automatically included in pop3_capabilities.\n
| \n Syntax:\n | \n\n pop3_capabilities \n | \n
|---|---|
| \n Default:\n | \n\n pop3_capabilities TOP USER UIDL;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets the\nPOP3 protocol\nextensions list that is passed to the client in response to\nthe CAPA command.\nThe authentication methods specified in the pop3_auth directive\n(SASL extension) and\nSTLS\nare automatically added to this list depending on the\nstarttls directive value.\n
\nIt makes sense to specify the extensions\nsupported by the POP3 backends\nto which the clients are proxied (if these extensions are related to commands\nused after the authentication, when nginx transparently proxies the client\nconnection to the backend).\n
\nThe current list of standardized extensions is published at\nwww.iana.org.\n
\n\n| Directives proxy_buffer proxy_pass_error_message proxy_protocol proxy_smtp_auth proxy_timeout xclient |
| \n Syntax:\n | \n\n proxy_buffer \n | \n
|---|---|
| \n Default:\n | \n\n proxy_buffer 4k|8k;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets the size of the buffer used for proxying.\nBy default, the buffer size is equal to one memory page.\nDepending on a platform, it is either 4K or 8K.\n
| \n Syntax:\n | \n\n proxy_pass_error_message \n | \n
|---|---|
| \n Default:\n | \n\n proxy_pass_error_message off;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nIndicates whether to pass the error message obtained during\nthe authentication on the backend to the client.\n
\nUsually, if the authentication in nginx is a success,\nthe backend cannot return an error.\nIf it nevertheless returns an error,\nit means some internal error has occurred.\nIn such case the backend message can contain information\nthat should not be shown to the client.\nHowever, responding with an error for the correct password\nis a normal behavior for some POP3 servers.\nFor example, CommuniGatePro informs a user about\nmailbox\noverflow or other events by periodically outputting the\nauthentication\nerror.\nThe directive should be enabled in this case.\n
| \n Syntax:\n | \n\n proxy_protocol \n | \n
|---|---|
| \n Default:\n | \n\n proxy_protocol off;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 1.19.8.\n
\nEnables the\nPROXY\nprotocol for connections to a backend.\n
| \n Syntax:\n | \n\n proxy_smtp_auth \n | \n
|---|---|
| \n Default:\n | \n\n proxy_smtp_auth off;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 1.19.4.\n
\nEnables or disables user authentication on the SMTP backend\nusing the AUTH command.\n
\nIf XCLIENT is also enabled,\nthen the XCLIENT command will not send\nthe LOGIN parameter.\n
| \n Syntax:\n | \n\n proxy_timeout \n | \n
|---|---|
| \n Default:\n | \n\n proxy_timeout 24h;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets the timeout between two successive\nread or write operations on client or proxied server connections.\nIf no data is transmitted within this time, the connection is closed.\n
| \n Syntax:\n | \n\n xclient \n | \n
|---|---|
| \n Default:\n | \n\n xclient on;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nEnables or disables the passing of the\nXCLIENT\ncommand with client parameters when connecting to the SMTP backend.\n
\nWith XCLIENT, the MTA is able to write client information\nto the log and apply various limitations based on this data.\n
\nIf XCLIENT is enabled\nthen nginx passes the following commands when connecting to the backend:\n
EHLO with the\nserver name\n\nXCLIENT\n\nEHLO or HELO,\nas passed by the client\n\n
\nIf the name\nfound\nby the client IP address points to the same address,\nit is passed in the NAME parameter\nof the XCLIENT command.\nIf the name could not be found, points to a different address,\nor resolver is not specified,\nthe [UNAVAILABLE] is passed\nin the NAME parameter.\nIf an error has occurred in the process of resolving,\nthe [TEMPUNAVAIL] value is used.\n
\nIf XCLIENT is disabled\nthen nginx passes the EHLO command with the\nserver name\nwhen connecting to the backend if the client has passed\nEHLO,\nor HELO with the server name, otherwise.\n
| Example Configuration Directives set_real_ip_from |
\nThe ngx_mail_realip_module module is used\nto change the client address and port\nto the ones sent in the PROXY protocol header (1.19.8).\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
\n
\nlisten 110 proxy_protocol;\n\nset_real_ip_from 192.168.1.0/24;\nset_real_ip_from 192.168.2.1;\nset_real_ip_from 2001:0db8::/32;\n
\n
\n\n\n| \n Syntax:\n | \n\n set_real_ip_from \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nDefines trusted addresses that are known to send correct\nreplacement addresses.\nIf the special value unix: is specified,\nall UNIX-domain sockets will be trusted.\n
| Directives smtp_auth smtp_capabilities smtp_client_buffer smtp_greeting_delay |
| \n Syntax:\n | \n\n smtp_auth \n | \n
|---|---|
| \n Default:\n | \n\n smtp_auth plain login;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets permitted methods of\nSASL authentication\nfor SMTP clients.\nSupported methods are:\n
plainlogincram-md5externalnone\n
\nPlain text authentication methods\n(AUTH PLAIN and AUTH LOGIN)\nare always enabled,\nthough if the plain and login methods\nare not specified,\nAUTH PLAIN and AUTH LOGIN\nwill not be automatically included in smtp_capabilities.\n
| \n Syntax:\n | \n\n smtp_capabilities \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets the SMTP protocol extensions list\nthat is passed to the client in response to the\nEHLO command.\nThe authentication methods specified in the smtp_auth directive and\nSTARTTLS\nare automatically added to this list depending on the\nstarttls directive value.\n
\nIt makes sense to specify the extensions\nsupported by the MTA\nto which the clients are proxied (if these extensions are related to commands\nused after the authentication, when nginx transparently proxies the client\nconnection to the backend).\n
\nThe current list of standardized extensions is published at\nwww.iana.org.\n
| \n Syntax:\n | \n\n smtp_client_buffer \n | \n
|---|---|
| \n Default:\n | \n\n smtp_client_buffer 4k|8k;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets the size of the buffer used for reading SMTP commands.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\n
| \n Syntax:\n | \n\n smtp_greeting_delay \n | \n
|---|---|
| \n Default:\n | \n\n smtp_greeting_delay 0;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nAllows setting a delay before sending an SMTP greeting\nin order to reject clients who fail to wait for the greeting before\nsending SMTP commands.\n
\n\n\nThe ngx_mail_ssl_module module provides the necessary\nsupport for a mail proxy server to work with the SSL/TLS protocol.\n
\nThis module is not built by default, it should be enabled with the\n--with-mail_ssl_module\nconfiguration parameter.\n
\nThis module requires the\nOpenSSL library.\n
\n
\n\n\n\nTo reduce the processor load, it is recommended to\n
\n\n
\nworker_processes auto;\n\nmail {\n\n ...\n\n server {\n listen 993 ssl;\n\n ssl_protocols TLSv1.2 TLSv1.3;\n ssl_ciphers AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;\n ssl_certificate /usr/local/nginx/conf/cert.pem;\n ssl_certificate_key /usr/local/nginx/conf/cert.key;\n ssl_session_cache shared:SSL:10m;\n ssl_session_timeout 10m;\n\n ...\n }\n\n
\n\n\n| \n Syntax:\n | \n\n ssl \n | \n
|---|---|
| \n Default:\n | \n\n ssl off;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nThis directive was made obsolete in version 1.15.0\nand was removed in version 1.25.1.\nThe ssl parameter\nof the listen directive\nshould be used instead.\n
| \n Syntax:\n | \n\n ssl_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSpecifies a file with the certificate in the PEM format\nfor the given server.\nIf intermediate certificates should be specified in addition to a primary\ncertificate, they should be specified in the same file in the following\norder: the primary certificate comes first, then the intermediate certificates.\nA secret key in the PEM format may be placed in the same file.\n
\nSince version 1.11.0,\nthis directive can be specified multiple times\nto load certificates of different types, for example, RSA and ECDSA:\n
\nserver {\n listen 993 ssl;\n\n ssl_certificate example.com.rsa.crt;\n ssl_certificate_key example.com.rsa.key;\n\n ssl_certificate example.com.ecdsa.crt;\n ssl_certificate_key example.com.ecdsa.key;\n\n ...\n}\n\n
\nOnly OpenSSL 1.0.2 or higher supports separate\ncertificate\nchains\nfor different certificates.\nWith older versions, only one certificate chain can be used.\n
\n
\nThe value\ndata:certificate\ncan be specified instead of the file (1.15.10),\nwhich loads a certificate\nwithout using intermediate files.\nNote that inappropriate use of this syntax may have its security implications,\nsuch as writing secret key data to\nerror log.\n
| \n Syntax:\n | \n\n ssl_certificate_compression \n | \n
|---|---|
| \n Default:\n | \n\n ssl_certificate_compression off;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 1.29.1.\n
\nEnables TLS 1.3\ncompression\nof server certificates.\n
\nThe directive is supported when using OpenSSL 3.2 or higher;\nthe list of supported compression algorithms is provided by the library.\n
\n
\nThe directive is supported when using BoringSSL;\nthe list of supported compression algorithms includes\nzlib (1.29.3).\n\n
| \n Syntax:\n | \n\n ssl_certificate_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSpecifies a file with the secret key in the PEM format\nfor the given server.\n
\nThe value\nengine:name:id\ncan be specified instead of the file (1.7.9),\nwhich loads a secret key with a specified id\nfrom the OpenSSL engine name.\n
\nThe value\nstore:scheme:id\ncan be specified instead of the file (1.29.0),\nwhich is used to load a secret key with a specified id\nand OpenSSL provider registered URI scheme, such as\npkcs11.\n
\nThe value\ndata:key\ncan be specified instead of the file (1.15.10),\nwhich loads a secret key without using intermediate files.\nNote that inappropriate use of this syntax may have its security implications,\nsuch as writing secret key data to\nerror log.\n
| \n Syntax:\n | \n\n ssl_ciphers \n | \n
|---|---|
| \n Default:\n | \n\n ssl_ciphers HIGH:!aNULL:!MD5;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSpecifies the enabled ciphers.\nThe ciphers are specified in the format understood by the\nOpenSSL library, for example:\n
\nssl_ciphers ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;\n
\n
\nThe full list can be viewed using the\n“openssl ciphers” command.\n
\n
\nThe previous versions of nginx used\ndifferent\nciphers by default.\n
\n
| \n Syntax:\n | \n\n ssl_client_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 1.7.11.\n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to verify client certificates.\n
\nThe list of certificates will be sent to clients.\nIf this is not desired, the ssl_trusted_certificate\ndirective can be used.\n
| \n Syntax:\n | \n\n ssl_conf_command \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 1.19.4.\n
\nSets arbitrary OpenSSL configuration\ncommands.\n
\nThe directive is supported when using OpenSSL 1.0.2 or higher.\n
\n
\nSeveral ssl_conf_command directives\ncan be specified on the same level:\n
\nssl_conf_command Options PrioritizeChaCha;\nssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;\n
\nThese directives are inherited from the previous configuration level\nif and only if there are no ssl_conf_command directives\ndefined on the current level.\n
\n
\nNote that configuring OpenSSL directly\nmight result in unexpected behavior.\n
\n
| \n Syntax:\n | \n\n ssl_crl \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 1.7.11.\n
\nSpecifies a file with revoked certificates (CRL)\nin the PEM format used to verify\nclient certificates.\nWhen using intermediate certificates, their CRLs should be\nspecified in the same file.\n
| \n Syntax:\n | \n\n ssl_dhparam \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 0.7.2.\n
\nSpecifies a file with DH parameters for DHE ciphers.\n
\nBy default no parameters are set,\nand therefore DHE ciphers will not be used.\n
\nPrior to version 1.11.0, builtin parameters were used by default.\n
\n
| \n Syntax:\n | \n\n ssl_ecdh_curve \n | \n
|---|---|
| \n Default:\n | \n\n ssl_ecdh_curve auto;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\n This directive appeared in versions 1.1.0 and 1.0.6.\n \n
\n\nSpecifies a curve for ECDHE ciphers.\n
\nWhen using OpenSSL 1.0.2 or higher,\nit is possible to specify multiple curves (1.11.0), for example:\n
\nssl_ecdh_curve prime256v1:secp384r1;\n
\n
\nThe special value auto (1.11.0) instructs nginx to use\na list built into the OpenSSL library when using OpenSSL 1.0.2 or higher,\nor prime256v1 with older versions.\n
\n
\nPrior to version 1.11.0,\nthe prime256v1 curve was used by default.\n\n
\n
\nWhen using OpenSSL 1.0.2 or higher,\nthis directive sets the list of curves supported by the server.\nThus, in order for ECDSA certificates to work,\nit is important to include the curves used in the certificates.\n
\n
| \n Syntax:\n | \n\n ssl_password_file \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 1.7.3.\n
\nSpecifies a file with passphrases for\nsecret keys\nwhere each passphrase is specified on a separate line.\nPassphrases are tried in turn when loading the key.\n
\nExample:\n
\nmail {\n ssl_password_file /etc/keys/global.pass;\n ...\n\n server {\n server_name mail1.example.com;\n ssl_certificate_key /etc/keys/first.key;\n }\n\n server {\n server_name mail2.example.com;\n\n # named pipe can also be used instead of a file\n ssl_password_file /etc/keys/fifo;\n ssl_certificate_key /etc/keys/second.key;\n }\n}\n\n
| \n Syntax:\n | \n\n ssl_prefer_server_ciphers \n | \n
|---|---|
| \n Default:\n | \n\n ssl_prefer_server_ciphers off;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSpecifies that server ciphers should be preferred over client ciphers\nwhen the SSLv3 and TLS protocols are used.\n
| \n Syntax:\n | \n\n ssl_protocols \n [\n | \n
|---|---|
| \n Default:\n | \n\n ssl_protocols TLSv1.2 TLSv1.3;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nEnables the specified protocols.\n
\nTheTLSv1.1andTLSv1.2parameters\n(1.1.13, 1.0.12) work only when OpenSSL 1.0.1 or higher is used.\n
\n
\nThe TLSv1.3 parameter (1.13.0) works only when\nOpenSSL 1.1.1 or higher is used.\n\n
\nThe TLSv1.3 parameter is used by default\nsince 1.23.4.\n\n
| \n Syntax:\n | \n\n ssl_session_cache \n \n | \n
|---|---|
| \n Default:\n | \n\n ssl_session_cache none;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSets the types and sizes of caches that store session parameters.\nA cache can be of any of the following types:\n
offnonebuiltin\n
\nBoth cache types can be used simultaneously, for example:\n
\nssl_session_cache builtin:1000 shared:SSL:10m;\n
\nbut using only shared cache without the built-in cache should\nbe more efficient.\n
| \n Syntax:\n | \n\n ssl_session_ticket_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 1.5.7.\n
\nSets a file with the secret key used to encrypt\nand decrypt TLS session tickets.\nThe directive is necessary if the same key has to be shared between\nmultiple servers.\nBy default, a randomly generated key is used.\n
\nIf several keys are specified, only the first key is\nused to encrypt TLS session tickets.\nThis allows configuring key rotation, for example:\n
\nssl_session_ticket_key current.key;\nssl_session_ticket_key previous.key;\n
\n
\nThe file must contain 80 or 48 bytes\nof random data and can be created using the following command:\n
\nopenssl rand 80 > ticket.key\n
\nDepending on the file size either AES256 (for 80-byte keys, 1.11.8)\nor AES128 (for 48-byte keys) is used for encryption.\n
| \n Syntax:\n | \n\n ssl_session_tickets \n | \n
|---|---|
| \n Default:\n | \n\n ssl_session_tickets on;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 1.5.9.\n
\nEnables or disables session resumption through\nTLS session tickets.\n
| \n Syntax:\n | \n\n ssl_session_timeout \n | \n
|---|---|
| \n Default:\n | \n\n ssl_session_timeout 5m;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\nSpecifies a time during which a client may reuse the\nsession parameters.\n
| \n Syntax:\n | \n\n ssl_trusted_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 1.7.11.\n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to verify client certificates.\n
\nIn contrast to the certificate set by ssl_client_certificate,\nthe list of these certificates will not be sent to clients.\n
| \n Syntax:\n | \n\n ssl_verify_client \n \n | \n
|---|---|
| \n Default:\n | \n\n ssl_verify_client off;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 1.7.11.\n
\nEnables verification of client certificates.\nThe verification result is passed in the\n“Auth-SSL-Verify” header of the\nauthentication\nrequest.\n
\nThe optional parameter requests the client\ncertificate and verifies it if the certificate is present.\n
\nThe optional_no_ca parameter\nrequests the client\ncertificate but does not require it to be signed by a trusted CA certificate.\nThis is intended for the use in cases when a service that is external to nginx\nperforms the actual certificate verification.\nThe contents of the certificate is accessible through requests\nsent\nto the authentication server.\n
| \n Syntax:\n | \n\n ssl_verify_depth \n | \n
|---|---|
| \n Default:\n | \n\n ssl_verify_depth 1;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
This directive appeared in version 1.7.11.\n
\nSets the verification depth in the client certificates chain.\n
| \n Syntax:\n | \n\n starttls \n \n | \n
|---|---|
| \n Default:\n | \n\n starttls off;\n | \n
| \n Context:\n | \n\n mail, server\n | \n
\n
onSTLS command for the POP3\nand the STARTTLS command for the IMAP and SMTP;\noffSTLS\nand STARTTLS commands;\nonly\n
\n\n\nRelease Date:\n19 May 2026\n
\nnginx modules:\n
\nSecurity:\na heap buffer overflow might occur in a worker process\nwhen the\n\njs_fetch_proxy\ndirective value contains nginx variables derived from the client request\n(\n$http_*,\n\n$arg_*,\n\n$cookie_*,\netc.) and the location's JS handler invokes\nngx.fetch()\n(CVE-2026-8711).\nThe issue was introduced in\ndea83189\n(0.9.4).\n
\nFeature:\nadded\njs_access\ndirective.\n
\n\nFeature:\nadded\nr.readRequestText(),\n\nr.readRequestArrayBuffer(),\nand\nr.readRequestJSON()\nasync methods that read the request body, available in\njs_access\nand\njs_content\ndirectives.\n
\n\nFeature:\nadded\nr.readRequestForm()\nasync method that parses the request body submitted from an HTML form\n(application/x-www-form-urlencoded and\nmultipart/form-data) and returns a structured accessor\nobject.\nThe method is available in\njs_access\nand\njs_content\ndirectives.\n
\nFeature:\nadded\njsVarNames()\nmethod.\nThe method returns the names of variables declared with\njs_var.\n
\n\n
\nCore:\n
\nBugfix:\nfixed evaluation order of call arguments with side effects.\nPreviously, an earlier argument could observe a later argument's mutation,\ne.g. f(a, a = 2) passed 2 as both\narguments.\nThe issue was introduced in\nfd5e523f\n(0.9.7).\n
\n
\nRelease Date:\n23 April 2026\n
\nnginx modules:\n
\nBugfix:\nfixed loading of the built-in crypto module.\nThe issue was introduced in\n3185ce81\n(0.9.7).\n
\n
\nRelease Date:\n21 April 2026\n
\nnginx modules:\n
\nFeature:\nimproved\nshared dict\neviction strategy.\n
\n\nFeature:\nadded\nttl()\nmethod to\nshared dictionaries.\n
\n\nBugfix:\nremoved spurious js vm init notice log emitted during\nconfiguration parsing.\n
\nBugfix:\nremoved\nshared dict\nexpiration from read-locked paths.\n
\n\nBugfix:\nfixed double-free in\nshared dict\nupdate with eviction.\n
\n\nBugfix:\nfixed per-entry TTL reset on\nincr()\ncalls.\n
\n\n
\nCore:\n
\nFeature:\nadded Ed25519 and X25519 support for\nWebCrypto.\n
\n\nFeature:\nadded\nwrapKey()\nand\nunwrapKey()\nsupport for\nWebCrypto.\n
\n\nFeature:\nadded\ncrypto.randomUUID().\n
\n\nFeature:\nallowed await expressions in tagged templates\nand as call arguments.\n
\nImprovement:\nswitched to OpenSSL EVP for hashing in the built-in\ncrypto\nmodule.\n
\n\nBugfix:\nfixed call argument evaluation.\n
\n\n
\nRelease Date:\n3 March 2026\n
\nnginx modules:\n
\nBugfix:\nfixed expire field truncation in\nshared dict\nstate files.\nMillisecond timestamps were silently truncated to 10 digits,\nmaking restored entries appear expired on restart.\n
\n\nBugfix:\nsuppressed slab log_nomem for evict\nshared dict\nzones.\nWhen evict is enabled, memory allocation failures are expected\nand handled by evicting old entries.\n
\n\nBugfix:\nfixed stack trace for\nngx.fetch()\nexceptions\nfor qjs engine.\n
\n\n
\nCore:\n
\nFeature:\nadded optional chaining support.\n
\n\nFeature:\nadded nullish coalescing assignment operator\n(??=).\n
\nFeature:\nadded logical assignment operators\n(||= and &&=).\n
\nImprovement:\naligned SyntaxError reporting with other JS engines.\nPreviously, file name was a part of the error message.\nNow it is reported as \"stack\" property.\n
\nImprovement:\nimproved Error.stack traces.\nStack traces are now attached in error constructors.\nPerformance of Error.stack is improved by ~100 times.\n
\nBugfix:\nfixed string offset map corruption in scope values hash.\nThe issue caused SEGV/SIGBUS crashes for multi-byte UTF-8 string\nconstants with more than 32 characters when accessing a character\nat index >= 32 (e.g. via .replace() or bracket notation).\nThe issue was introduced in\ne7caa46d\n(0.9.5).\n
\nBugfix:\nfixed heap-buffer-overflow in atom hash caused by\nSymbol().\n
\nBugfix:\nfixed WebCrypto\nimportKey()\ncrash with mismatched JWK key type.\n
\n\nBugfix:\nfixed interactive mode detection for piped stdin.\n
\n\nBugfix:\nfixed build on MacOS.\n
\n\nBugfix:\nfixed PTR macro compatibility with newer BFD library.\n
\n\nBugfix:\nauto/cc: use portable command -v\ninstead of which.\nThanks to Zurab Kvachadze.\n
\n
\nRelease Date:\n13 January 2026\n
\nnginx modules:\n
\nFeature:\nadded native module support for\nqjs engine\nfor\nhttp\nand\nstream.\n
\n\nBugfix:\nfixed\njs_body_filter\nwith multiple chunks\nfor qjs engine.\n
\n\nBugfix:\nfixed buffer_type inheritance in if blocks for\njs_body_filter.\nPreviously, when js_body_filter was used inside an if block,\nthe data parameter received Buffer type\ninstead of the expected String type.\n
\nBugfix:\nfixed js_body_filter\nwhen data is not in memory.\nPreviously, when upstream data was delivered from nginx cache,\njs_body_filter was not able to process it correctly.\n
\nBugfix:\nimproved\nr.subrequest() error handling.\nFixed a problem of a lost write event when the njs handler\nmaking r.subrequest() is called from a lua handler as a\nsubrequest.\n
\n
\nCore:\n
\nBugfix:\nfixed XMLAttr object.\nPointer to xmlAttr could become invalid\nwhen the parent XMLNode was modified.\n
\nBugfix:\nfixed XMLNode update.\n
\nBugfix:\nfixed ArrayBuffer with detached buffers.\n
\nBugfix:\nadded missing detached array checks.\n
\n\nBugfix:\nfixed fs.mkdir() and friends.\n
\n\nBugfix:\nfixed path restoration in\nfs.mkdir()\nand friends on error.\n
\n\nBugfix:\nfixed missed allocation check in promise code.\n
\n\n
\nRelease Date:\n28 October 2025\n
\nnginx modules:\n
\nFeature:\nadded HTTP forward proxy support for\nngx.fetch() API.\n
\n\n
\nCore:\n
\nBugfix:\nfixed r.subrequest()\nto a location with JS handler for QuickJS.\nThe bug became visible after\nbellard/quickjs@42eb2795.\n
\n\n
\nRelease Date:\n07 October 2025\n
\nnginx modules:\n
\nBugfix:\nfixed heap-use-after-free while module loading.\n
\n\n\nBugfix:\nfixed heap-use-after-free in js_set handler used in log phase.\nThe issue was introduced in\n04f6dfb\n(0.9.2).\n
\n
\nRelease Date:\n23 September 2025\n
\nnginx modules:\n
\nFeature:\nadded HTTP keepalive support for\nngx.fetch()\nAPI.\n
\nImprovement:\nadded configure time check when\nthe js_import directive is not specified for\nhttp or\nstream.\n
\nBugfix:\nfixed merging of js_path directives for\nhttp and\nstream.\n\n
\nBugfix:\nfixed building when the\nngx_http_ssl_module\nand\nngx_stream_ssl_module\nmodules are unavailable.\n
\n\n
\nCore:\n
\nChange:\nincreased the default stack size to 160k for njs VM.\n
\n\nFeature:\nadded njs.on('exit') API\nfor the qjs engine.\n
\nImprovement:\noptimized memory consumption while streaming\nin qjs.\n
\n\nBugfix:\nfixed building qjs engine with clang 19.\n
\n\nBugfix:\nfixed building with GCC 15 and O3 optimization level.\n
\n\n
\nRelease Date:\n10 Jul 2025\n
\nnginx modules:\n
\nFeature:\nadded state file for a\nshared dictionary.\n
\n\nBugfix:\nfixed handling of Content-Length header when a body is provided in\nFetch API.\n
\n\nBugfix:\nfixed qjs engine after\nbellard/quickjs@458c34d2.\n
\n\nBugfix:\nfixed NULL pointer dereference when processing\nIf-Match and If-Unmodified-Since headers.\n
\n
\nCore:\n
\nFeature:\nadded ECDH support for\nWebCrypto.\n
\n\nImprovement:\nreduced memory consumption by the object hash.\nThe new hash uses 42% less memory per element.\n
\n\nImprovement:\nreduced memory consumption for concatenation of numbers and strings.\n
\n\nImprovement:\nreduced memory consumption of\nString.prototype.concat() with scalar values.\n
\nBugfix:\nfixed segfault in njs_property_query().\nThe issue was introduced in\nb28e50b1\n(0.9.0).\n
\nBugfix:\nfixed Function constructor template injection.\n
\n\nBugfix:\nfixed GCC compilation with O3 optimization level.\n
\n\nBugfix:\nfixed constant is too large\nfor 'long' warning on MIPS -mabi=n32.\n
\nBugfix:\nfixed compilation with GCC 4.1.\n
\n\nBugfix:\nfixed %TypedArray%.from() with the buffer is detached\nby the mapper.\n
\nBugfix:\nfixed %TypedArray%.prototype.slice() with overlapping\nbuffers.\n
\nBugfix:\nfixed handling of detached buffers for typed arrays.\n
\n\nBugfix:\nfixed frame saving for async functions with closures.\n
\n\nBugfix:\nfixed RegExp compilation of patterns with escaped '[' characters.\n
\n\n
\nRelease Date:\n06 May 2025\n
\nCore:\n
\nFeature:\nrefactored handling of built-in strings, symbols, and small integers.\nPerformance improvements (arewefastyet/benchmarks/v8-v7 benchmark):\n
\nRichards: +57% (631 → 989)\n
\n\nCrypto: +7% (1445 → 1551)\n
\n\nRayTrace: +37% (562 → 772)\n
\n\nNavierStokes: +20% (2062 → 2465)\n
\n\nOverall score: +29% (1014 → 1307)\n
\n\n
\n\nBugfix:\nfixed handling of undefined values of a captured group\nin RegExp.prototype[Symbol.split]().\n
\nBugfix:\nfixed GCC 15 build error with\n-Wunterminated-string-initialization.\n
\n
\nRelease Date:\n08 April 2025\n
\nnginx modules:\n
\nFeature:\nreading r.requestText\nor\nr.requestBuffer\nfrom a temporary file.\nPreviously, an exception was thrown when accessing\nr.requestText\nor\nr.requestBuffer\nif the size of the client request body exceeded \nclient_body_buffer_size.\n
\nImprovement:\nimproved reporting of unhandled promise rejections.\n
\n\nBugfix:\nfixed name corruption in variables and headers processing.\n
\n\nBugfix:\nfixed incr()\nmethod of a shared dictionary with an empty init argument for the\nQuickJS engine.\n
\nBugfix:\naccepting response headers with underscore characters in\nFetch API.\n
\n\n
\nCore:\n
\nChange:\nfixed\nserializeToString().\nPreviously, serializeToString() was\nexclusiveC14n()\nwhich returned a string instead of Buffer.\nAccording to the published documentation, it\nshould be c14n().\n
\nFeature:\nadded\nWebCrypto\nAPI for the\nQuickJS engine.\n
\nFeature:\nadded TextEncoder\nand\nTextDecoder\nfor the\nQuickJS engine.\n
\nFeature:\nadded querystring\nmodule for the\nQuickJS engine.\n
\nFeature:\nadded support for the QuickJS-NG library.\n
\nBugfix:\nfixed\nBuffer.concat()\nwith a single argument in QuickJS.\n
\nBugfix:\nadded missed syntax error for await in template literal.\n
\nBugfix:\nfixed non-NULL terminated strings formatting in exceptions for the\nQuickJS engine.\n
\n\nBugfix:\nfixed compatibility with recent change in QuickJS\nand QuickJS-NG.\n
\n
\nRelease Date:\n14 January 2025\n
\nnginx modules:\n
\nBugfix: removed extra VM creation per server.\nPreviously, when js_import was declared in\nhttp or\nstream\nblocks, an extra copy of the VM instance was created for each server block.\nThis was not needed and consumed a lot of memory for configurations with many\nserver blocks.\nThis issue was introduced in 0.8.6 and was\npartially fixed for location blocks only in 0.8.7.\n
\n
\nCore:\n
\n
\nRelease Date:\n10 December 2024\n
\nnginx modules:\n
\nFeature:\nimplemented shared dictionary\nfor the QuickJS engine.\n
\n\nImprovement:\njs_preload_object\nis refactored.\n
\n\nBugfix: fixed limit rated output.\n
\n\nBugfix: optimized use of SSL contexts for the\njs_fetch_trusted_certificate\ndirective.\n
\n\n
\nCore:\n
\nFeature:\nimplemented process object\nfor the QuickJS engine.\n
\n\nFeature:\nimplemented the\nprocess.kill() method.\n
\n\nBugfix: fixed XML tests with\nlibxml2 2.13\nand later.\n
\n\nBugfix: fixed promise resolving when Promise is inherited.\n
\n\nBugfix: fixed absolute scope in cloned VMs.\n
\n\n
\nRelease Date:\n22 October 2024\n
\nnginx modules:\n
\nBugfix: eliminated unnecessary VM creation.\nPreviously, njs consumed\nmemory proportionally to the number of nginx locations.\nThe issue was introduced in 0.8.6.\n
\n\nImprovement: added strict syntax validation for\njs_body_filter.\n
\n\nImprovement: improved error messages for module loading failures.\n
\n\n
\nCore:\n
\nFeature: implemented\nfs.readlinkSync().\n
\nImprovement: implemented lazy stack symbolization.\n
\n\nBugfix: fixed heap-buffer-overflow in\nBuffer.prototype.indexOf().\nThe issue was introduced in 0.8.6.\n
\nBugfix: fixed Buffer.prototype.lastIndexOf() when `from` is\nprovided.\n
\n
\nRelease Date:\n02 October 2024\n
\nnginx modules:\n
\nFeature:\nintroduced the QuickJS engine.\n
\n\nFeature:\nadded optional nocache flag for the\njs_set directive for\nhttp\nand \nstream.\nThanks to Thomas P.\n
\nFeature:\nexposed\ncapture group variables\nin the HTTP module.\nThanks to Thomas P.\n
\n\n
\nCore:\n
\nFeature:\nadded Buffer module for the QuickJS engine.\n
\nBugfix:\nfixed handling of empty labelled statement in a function.\n
\n\nBugfix:\nfixed Function constructor handling when called without\narguments.\n
\nBugfix:\nfixed Buffer.prototype.writeInt8() and friends.\n
\nBugfix:\nfixed Buffer.prototype.writeFloat() and friends.\n
\nBugfix:\nfixed Buffer.prototype.lastIndexOf().\n
\nBugfix:\nfixed Buffer.prototype.write().\n
\nBugfix:\nfixed maybe-uninitialized warnings in error creation.\n
\n\nBugfix:\nfixed ctx.codepoint initialization in UTF-8 decoding.\n
\nBugfix:\nfixed length initialization in\nArray.prototype.pop().\n
\nBugfix:\nfixed handling of encode arg in\nfs.readdir() and\nfs.realpath().\n
\n
\nRelease Date:\n25 June 2024\n
\nnginx modules:\n
\nChange:\nbytes invalid in UTF-8 encoding are converted into the replacement character in:\n
\nr.variables.var,\nr.requestText,\nr.responseText,\ns.variables.var,\n
\nthe\ndata argument of the\ns.on() callback\nwith upload or download event types,\n
\nthe data argument of the\njs_body_filter\ndirective.\n
\nWhen working with binary data, use:\n
\nr.rawVariables.var,\nr.requestBuffer,\nr.responseBuffer,\ns.rawVariables.var,\n
\nthe upstream or downstream event type\nfor\ns.on(),\n
\nbuffer_type=buffer for\njs_body_filter.\n
\n\n
\n\nFeature:\nadded timeout argument for\nadd(),\nset(), and\nincr()\nmethods of a shared dictionary.\n
\nBugfix:\nfixed checking for duplicate\njs_set\nvariables.\n
\nBugfix:\nfixed request Host header when the port is non-standard.\n
\nBugfix:\nfixed handling of a zero-length request body in\nngx.fetch()\nand\nr.subrequest().\n
\nBugfix:\nfixed heap-buffer-overflow in Headers.get().\n
\nBugfix:\nfixed\nr.subrequest()\nerror handling.\n
\n
\nCore:\n
\nFeature:\nadded zlib module for QuickJS engine.\n
\nBugfix:\nfixed\nzlib.inflate().\n
\nBugfix:\nfixed String.prototype.replaceAll()\nwith a zero-length argument.\n
\nBugfix:\nfixed retval handling after an exception in\nArray.prototype.toSpliced(),\nArray.prototype.toReversed(),\nArray.prototype.toSorted().\n
\nBugfix:\nfixed RegExp.prototype[@@replace]() with replacements\ncontaining $', $`\nand strings with Unicode characters.\n
\nBugfix:\nfixed a one-byte overread in\ndecodeURI() and\ndecodeURIComponent().\n
\nBugfix:\nfixed tracking of argument scope.\n
\n\nBugfix:\nfixed integer overflow in Date.parse().\n
\n
\nRelease Date:\n16 April 2024\n
\nnginx modules:\n
\nFeature:\nthe Server header for outgoing header can be set.\n
\nImprovement:\nvalidating URI and args arguments in\nr.subrequest().\n
\nImprovement:\nchecking for duplicate\njs_set variables.\n
\n\nBugfix:\nfixed\nclear()\nmethod of a shared dictionary without a timeout\nintroduced in 0.8.3.\n
\nBugfix:\nfixed\nr.send()\nmethod of a shared dictionary without a timeout\nwith Buffer argument.\n
\n
\nCore:\n
\nFeature:\nadded QuickJS engine support in CLI.\n
\nBugfix:\nfixed\natob()\nwith non-padded base64 strings.\n
\n
\nRelease Date:\n07 February 2024\n
\nnginx modules:\n
\nBugfix:\nfixed\nHeaders.set().\n
\nBugfix:\nfixed\njs_set\nwith Buffer values.\n
\nBugfix:\nfixed\nclear()\nmethod of a shared dictionary when a timeout is not specified.\n
\nBugfix:\nfixed\nstub_status\nstatistics when\njs_periodic\nis enabled.\n
\n\n
\nCore:\n
\nBugfix:\nfixed building with\nlibxml2 2.12\nand later.\n
\n\nBugfix:\nfixed Date constructor for overflows\nand with NaN values.\n
\nBugfix:\nfixed underflow in\nquerystring.parse().\n
\nBugfix:\nfixed potential buffer overread in\nString.prototype.match().\n
\nBugfix:\nfixed parsing of for-in loops.\n
\nBugfix:\nfixed parsing of\nhexadecimal, octal, and binary literals with no digits.\n
\n\n
\nRelease Date:\n24 October 2023\n
\nnginx modules:\n
\nFeature:\nintroduced\nconsole object.\nThe following methods were introduced:\nerror(),\ninfo(),\nlog(),\ntime(),\ntimeEnd(),\nwarn().\n
\nBugfix:\nfixed\nHEAD response handling with large Content-Length in\nFetch API.\n
\nBugfix:\nfixed\nitems()\nmethod for a shared dictionary.\n
\nBugfix:\nfixed\ndelete()\nmethod for a shared dictionary.\n
\n
\nCore:\n
\nFeature:\nextended\nfs module.\nAdded\nfs.existsSync().\n
\nBugfix:\nfixed\nxml module.\nBroken XML exception handling in\nxml.parse()\nmethod was fixed.\n
\nBugfix:\nfixed\nRegexp.prototype.exec() with global regexp and Unicode input.\n
\n
\nRelease Date:\n12 September 2023\n
\nnginx modules:\n
\nFeature:\nintroduced the js_periodic directive for\nhttp\nand\nstream\nthat allows specifying a JS handler to run at regular intervals.\n
\nFeature:\nimplemented\nitems()\nmethod of a\nshared dictionary.\nThe method returns all the non-expired key-value pairs.\n
\nBugfix:\nfixed\nsize()\nand\nkeys()\nmethods of a\nshared dictionary.\n
\nBugfix:\nfixed erroneous exception in\nr.internalRedirect()\nintroduced in 0.8.0.\n
\n
\nCore:\n
\nBugfix:\nfixed incorrect order of keys in\nObject.getOwnPropertyNames().\n
\n
\nRelease Date:\n06 July 2023\n
\nnginx modules:\n
\nChange:\nremoved special treatment of forbidden headers in\nFetch API\nintroduced in 0.7.10.\n
\n\nChange:\nremoved deprecated since 0.5.0\nr.requestBody\nand\nr.responseBody\nin\nhttp\nmodule.\n
\nChange:\nthrowing an exception in\nr.internalRedirect()\nwhile filtering in\nhttp\nmodule.\n
\nFeature:\nintroduced more global\nnginx properties:\nngx.build,\nngx.conf_file_path,\nngx.error_log_path,\nngx.prefix,\nngx.version,\nngx.version_number,\nand\nngx.worker_id.\n
\nFeature:\nintroduced the js_shared_dict_zone directive for\nhttp\nand\nstream\nthat allows declaring a dictionary shared between worker processes.\n
\nFeature:\nintroduced global\nnginx.shared\nmethods and properties for working with shared dictionaries.\n
\nImprovement:\nadded compile-time options to disable njs modules.\nFor example, to disable libxslt-related code:\n
\nNJS_LIBXSLT=NO ./configure .. --add-module=/path/to/njs/module\n
\n
\n\nBugfix:\nfixed\nr.status\nsetter when filtering in\nhttp\nmodule.\n
\nBugfix:\nfixed setting of Location header in\nhttp\nmodule.\n
\n
\nCore:\n
\nChange:\nnative methods are provided with retval argument.\nThis change breaks compatibility with C extension for njs\nrequiring the modification of the code.\n
\nChange:\nnon-compliant deprecated String methods were removed.\nThe following methods were removed:\nString.bytesFrom(),\nString.prototype.fromBytes(),\nString.prototype.fromUTF8(),\nString.prototype.toBytes(),\nString.prototype.toUTF8(),\nString.prototype.toString(.\nencoding)
\nChange:\nremoved support for building with GNU readline.\n
\n\nFeature:\nadded ES13-compliant Array methods:\nArray.from(),\nArray.prototype.toSorted(),\nArray.prototype.toSpliced(),\nArray.prototype.toReversed().\n
\nFeature:\nadded ES13-compliant TypedArray methods:\n%TypedArray%.prototype.toSorted(),\n%TypedArray%.prototype.toSpliced(),\n%TypedArray%.prototype.toReversed().\n
\nFeature:\nadded\nCryptoKey\nproperties in\nWebCrypto API.\nThe following properties were added:\nalgorithm,\nextractable,\ntype,\nusages.\n
\nBugfix:\nfixed retval of\nсrypto.getRandomValues().\n
\nBugfix:\nfixed evaluation of computed property names with function expressions.\n
\n\nBugfix:\nfixed implicit name for a function expression declared in arrays.\n
\n\nBugfix:\nfixed parsing of for-in loops.\n
\nBugfix:\nfixed\nDate.parse() with ISO-8601 format and UTC time offset.\n
\n
\nRelease Date:\n10 April 2023\n
\nnginx modules:\n
\nBugfix:\nfixed Headers() constructor in\nFetch API.\n
\n
\nCore:\n
\nFeature:\nadded\nHash.copy()\nmethod in\ncrypto module.\n
\nFeature:\nadded\nzlib\nmodule.\n
\n\nImprovement:\nadded support for\nexport {name as default} statement.\n
\nBugfix:\nfixed Number constructor according to the spec.\n
\n
\nRelease Date:\n09 March 2023\n
\nnginx modules:\n
\nBugfix:\nadded missed linking with\nlibxml2\nfor the dynamic module.\nThe bug was introduced in 0.7.10.\n
\n\n
\nCore:\n
\nFeature:\nadded\nXMLNode API\nto modify XML documents.\n
\n\nChange:\nremoved XML_PARSE_DTDVALID during parsing of an XML document\ndue to security implications.\nThe issue was introduced in 0.7.10.\nWhen XML_PARSE_DTDVALID is enabled,\nlibxml2\nparses and executes external entities present inside an XML document.\n
\nBugfix:\nfixed the detection of await in arguments.\n
\nBugfix:\nfixed Error() instance dumping\nwhen “name” prop is not primitive.\n
\nBugfix:\nfixed array instance with a getter property dumping.\n
\nBugfix:\nfixed njs_object_property() with\nNJS_WHITEOUT properties.\n
\nBugfix:\nfixed func instance dumping\nwith “name” as getter.\n
\nBugfix:\nfixed attaching of a stack to an error object.\n
\n\nBugfix:\nfixed String.prototype.replace() with replacement\ncontaining “$'”, “$`”.\n
\n
\nRelease Date:\n07 February 2023\n
\nnginx modules:\n
\nFeature:\nadded\nRequest,\nResponse,\nand\nHeaders\nctors in\nFetch API.\n
\nBugfix:\nfixed nginx logger callback for calls in the master process.\n
\n\n
\nCore:\n
\nFeature:\nadded signal support in CLI.\n
\n\nFeature:\nadded\nxml\nmodule for working with XML documents.\n
\nFeature:\nextended support for symmetric and asymmetric keys in WebCrypto.\nMost notably JWK format for\nimportKey()\nwas added.\n
\nFeature:\nextended support for symmetric and asymmetric keys in\nWebCrypto API.\nMost notably JWK format for\nimportKey()\nwas added.\ngenerateKey()\nand\nexportKey()\nwere also implemented.\n
\nFeature:\nadded\nString.prototype.replaceAll().\n
\nBugfix:\nfixed for(expr1; conditional syntax error handling.\n
\nBugfix:\nObject.values()\nand\nObject.entries()\nwith external objects.\n
\nBugfix:\nfixed RegExp.prototype[@@replace]().\n
\n
\nRelease Date:\n17 November 2022\n
\nnginx modules:\n
\nBugfix:\nfixed\nFetch\nResponse prototype reinitialization.\nWhen at least one js_import directive was declared in both\nHTTP\nand\nStream,\nngx.fetch()\nreturned inapproriate response in Stream.\nThe bug was introduced in 0.7.7.\n
\n
\nCore:\n
\nBugfix:\nfixed String.prototype.replace(re)\nif re.exec() returns non-flat array.\n
\nBugfix:\nfixed Array.prototype.fill()\nwhen start object changes this.\n
\nBugfix:\nfixed description for\nfs.mkdir()\nand\nfs.rmdir()\nmethods.\n
\nBugfix:\nfixed %TypedArray%.prototype.set(s)\nwhen s element changes this.\n
\nBugfix:\nfixed Array.prototype.splice(s,d)\nwhen d resizes this during eval.\n
\nBugfix:\nfixed for-in loop with left and right hand side expressions.\n
\n
\nRelease Date:\n25 October 2022\n
\nnginx modules:\n
\nFeature:\nadded\njs_preload_object directive.\n
\n\nFeature:\nadded\nngx.conf_prefix\nproperty.\n
\nFeature:\nadded\ns.sendUpstream()\nand\ns.sendDownstream()\nin\nstream module.\n
\nFeature:\nadded support for HEAD method in\nFetch API.\n
\nImprovement:\nimproved async callback support for\ns.send()\nin\nstream module.\n
\n
\nCore:\n
\nFeature:\nadded name instance property for a function object.\n
\nFeature:\nadded\nnjs.memoryStats\nobject.\n
\nBugfix:\nfixed\nString.prototype.trimEnd()\nwith unicode string.\n
\nBugfix:\nfixed Object.freeze() with fast arrays.\n
\nBugfix:\nfixed Object.defineProperty() with fast arrays.\n
\nBugfix:\nfixed async token as a property name of an object.\n
\nBugfix:\nfixed property set instruction when key modifies base binding.\n
\n\nBugfix:\nfixed complex assignments.\n
\n\nBugfix:\nfixed handling of unhandled promise rejection.\n
\n\nBugfix:\nfixed process.env\nwhen duplicate environ variables are present.\n
\n\nBugfix:\nfixed double declaration detection in modules.\n
\n\nBugfix:\nfixed bound function calls according to the spec.\n
\n\nBugfix:\nfixed break label for if statement.\n
\nBugfix:\nfixed labeled empty statements.\n
\n\n
\nRelease Date:\n30 August 2022\n
\nnginx modules:\n
\nFeature:\nthe number of nginx configuration contexts where\njs directives can be specified is extended.\n\n
\nHTTP:\nthe js_import,\njs_path,\njs_set, and\njs_var directives\nare allowed in\nserver and location contexts.\nThe js_content,\njs_body_filter and\njs_header_filter\nare allowed in\nif context.\n
\nStream:\nthe js_import,\njs_path,\njs_set, and\njs_var\nare allowed in\nserver context.\n
\n\n
\n\nFeature:\nadded\nr.internal\nproperty.\n
\nBugfix:\nfixed reading response body in\nFetch API.\n
\n\nBugfix:\nfixed\njs_fetch_timeout\nin stream.\n
\n\nBugfix:\nfixed socket leak with 0 fetch timeout.\n
\n
\nCore:\n
\nFeature:\nextended\nfs module.\nAdded\nfs.openSync(),\nfs.promises.open(),\nfs.fstatSync(),\nfs.readSync(),\nfs.writeSync().\n
\nThe following properties of\nFileHandle\nare implemented:\nfd,\nread(),\nstat(),\nwrite(),\nclose().\n
\nBugfix:\nfixed parseInt(),\nparseFloat(),\nSymbol.for()\nwith no arguments.\n
\n
\nRelease Date:\n19 July 2022\n
\nnginx modules:\n
\nFeature:\nimproved\nr.args{} object.\nAdded support for multiple arguments with the same key.\nAdded case sensitivity for keys.\nKeys and values are percent-decoded now.\n
\nBugfix:\nfixed\nr.headersOut{}\nsetter for special headers.\n
\n
\nCore:\n
\nFeature:\nadded Symbol.for() and Symbol.keyfor().\n
\nFeature:\nadded\natob()\nand\nbtoa()\nfrom\nWHATWG spec.\n
\nBugfix:\nfixed large non-decimal literals.\n
\n\nBugfix:\nfixed Unicode argument trimming in parseInt().\n
\nBugfix:\nfixed break instruction\nin try-catch block.\n
\nBugfix:\nfixed async function declaration in CLI.\n
\n
\nRelease Date:\n21 June 2022\n
\nnginx modules:\n
\nChange:\nadapting to changes in nginx header structures.\n
\n\nBugfix:\nfixed\nr.headersOut{}\nspecial getters when value is absent.\n
\nChange:\nreturning undefined value instead of an empty string for\nContent-Type when the header is absent.\n
\n
\nCore:\n
\nBugfix:\nfixed catching of the exception thrown from an awaited function.\n
\n\nBugfix:\nfixed function value initialization.\n
\n\nBugfix:\nfixed interpreter when await fails.\n
\n\nBugfix:\nfixed typed-array constructor when source array is changed while iterating.\n
\n\nBugfix:fixed\nString.prototype.replace()\nwith byte strings.\n
\nBugfix:\nfixed template literal from producing byte-strings.\n
\n\nBugfix:\nfixed array iterator with sparse arrays.\n
\n\nBugfix:\nfixed memory free while converting a flat array to a slow array.\n
\n\nBugfix:\nproperly handling NJS_DECLINE in\npromise native functions.\n
\nBugfix:\nfixed working with an array-like object in\nPromise.all()\nand friends.\n
\n
\nRelease Date:\n24 May 2022\n
\nnginx modules:\n
\nFeature:\nadded extended directives for configuring\nFetch API.\nThe following directives were added for\nhttp and\nstream:\n
\njs_fetch_timeout,\n
\n\njs_fetch_verify,\n
\n\njs_fetch_buffer_size,\n
\n\n\n
\n\nChange:\nr.internalRedirect() now accepts escaped URIs.\n
\nBugfix:\nfixed\nResponse parsing\nwith more than 8 headers in\nFetch API.\n
\n\n
\nCore:\n
\nFeature:\nadded\nnjs.version_number property.\n
\nFeature:\nadded compatibility with BoringSSL for\nWebCrypto API.\n
\n\nBugfix:\nfixed\nArray.prototype.sort()\nwhen arr size is changed in a comparator.\n
\nBugfix:\nfixed\nArray.prototype.slice()\nwith slow this argument.\n
\nBugfix:\nfixed aggregation methods of Promise ctor\nwith array-like object.\n
\nBugfix:\nfixed String.prototype.lastIndexOf()\nwith Unicode string as this.\n
\nBugfix:\nfixed\nJSON.parse()\nwhen reviver function is provided.\n
\nBugfix:\nfixed\nObject.defineProperty()\nwhen a recursive descriptor is provided.\n
\nBugfix:\nfixed Array.prototype.fill() for typed-arrays.\n
\nBugfix:\nmaking function expression binding immutable according to the specs.\n
\n\nBugfix:\nfixed redefinition of special props in\nObject.defineProperty().\n
\n
\nRelease Date:\n12 April 2022\n
\nCore:\n
\nFeature:\nadded support of module resolution callback.\nThis feature allows the host environment to control\nhow imported modules are loaded.\n
\n\nBugfix:\nfixed backtraces while traversing imported user modules.\n
\n\nBugfix:\nfixed\nArray.prototype.concat()\nwhen this is a slow array.\n
\nBugfix:\nfixed frame allocation from an awaited frame.\n
\n\nBugfix:\nfixed allocation of large array literals.\n
\n\nBugfix:\nfixed interpreter when toString conversion fails.\n
\n
\nRelease Date:\n25 January 2022\n
\nCore:\n
\nBugfix:\nfixed\nArray.prototype.join()\nwhen array is changed while iterating.\n
\nBugfix:\nfixed\nArray.prototype.slice()\nwhen array is changed while iterating.\n
\nBugfix:\nfixed\nArray.prototype.concat()\nwhen array is changed while iterating.\n
\nBugfix:\nfixed\nArray.prototype.reverse()\nwhen array is changed while iterating.\n
\nBugfix:\nfixed\nBuffer.concat()\nwith subarrays.\nThanks to Sylvain Etienne.\n
\nBugfix:\nfixed\ntype confusion bug while resolving promises.\n
\n\nBugfix:\nfixed\nFunction.prototype.apply()\nwith large array arguments.\n
\nBugfix:\nfixed recursive async function calls.\n
\nBugfix:\nfixed function redeclaration.\nThe bug was introduced in\n0.7.0.\n
\n\n
\nRelease Date:\n28 December 2021\n
\nnginx modules:\n
\nChange:\nthe js_include directive\ndeprecated since 0.4.0 was removed.\n
\n\nChange:\nPCRE/PCRE2-specific code was moved to the modules.\nThis ensures that njs uses the same RegExp library as nginx.\n
\n\n
\nCore:\n
\nBugfix:\nfixed\ndecodeURI() and\ndecodeURIComponent()\nwith invalid byte strings.\nThe bug was introduced in\n0.4.3.\n
\nBugfix:\nfixed heap-use-after-free in await frame.\nThe bug was introduced in\n0.7.0.\n
\nBugfix:\nfixed WebCrypto sign() and\nverify() methods with OpenSSL 3.0.\n
\nBugfix:\nfixed exception throwing when RegExp match fails.\nThe bug was introduced in\n0.1.15.\n
\n\nBugfix:\nfixed catching of exception thrown in try block\nof async function.\nThe bug was introduced in\n0.7.0.\n
\nBugfix:\nfixed execution of async function in synchronous context.\nThe bug was introduced in\n0.7.0.\n
\nBugfix:\nfixed function redeclaration in CLI when interactive mode is on.\nThe bug was introduced in\n0.6.2.\n
\n\nBugfix:\nfixed typeof operator with\nDataView object.\n
\nBugfix: eliminated information leak in Buffer.from().\n
\n\n
\nRelease Date:\n19 October 2021\n
\nnginx modules:\n
\n
\nCore:\n
\nFeature:\nintroduced Async/Await implementation.\n
\nFeature:\nadded\nWebCrypto API\nimplementation.\n
\n\nBugfix:\nfixed copying of closures for declared functions.\nThe bug was introduced in\n0.6.0.\n
\n\nBugfix:\nfixed unhandled promise rejection in handle events.\n
\nBugfix:\nfixed Response.headers getter in Fetch API.\n
\n\n\n
\nRelease Date:\n31 August 2021\n
\nnginx modules:\n
\nBugfix:\nfixed CPU hog when\njs_filter is registered in both directions.\n
\n
\nCore:\n
\nFeature:\nintroduced AggregateError implementation.\n
\nFeature:\nadded remaining Promise constructor methods.\nThe following methods were added:\nPromise.all(),\nPromise.allSettled(),\nPromise.any(),\nPromise.race().\n
\nImprovement:\nremoved recursion from code generator.\n
\n\nBugfix:\nfixed rest parameter parsing without binding identifier.\n
\n\nBugfix:\nfixed resolve/reject callback for\nPromise.prototype.finally() .\n
\nBugfix:\nfixed %TypedArray%.prototype.join()\nwith detached buffer.\n
\nBugfix:\nfixed memory leak in interactive shell.\n
\n\n\n
\nRelease Date:\n29 June 2021\n
\n
\nBugfix:\nfixed RegExpBuiltinExec() with UTF-8 only regexps.\nThe bug was introduced in 0.4.2.\n
\nBugfix:\nfixed parsing of export default declaration with non-assignment expressions.\nThanks to Artem S. Povalyukhin.\n
\n\n
\nRelease Date:\n15 June 2021\n
\nCore:\n
\nFeature:\nadded\nlet and\nconst declaration support.\n
\nFeature:\nadded RegExp.prototype[Symbol.split].\n
\nFeature:\nadded sticky flag support for RegExp.\n
\n\nBugfix:\nfixed heap-buffer-overflow in\nString.prototype.lastIndexOf().\n
\nBugfix:\nfixed\nRegExp.prototype.test()\naccording to the specification.\n
\nBugfix:\nfixed\nString.prototype.split()\naccording to the specification.\n
\nBugfix:\nfixed use-of-uninitialized-value while tracking rejected promises.\n
\n\nBugfix:\nfixed njs.dump() for objects with circular references.\n
\n
\nRelease Date:\n30 March 2021\n
\nnginx modules:\n
\n
\nRelease Date:\n09 March 2021\n
\nnginx modules:\n
\nFeature:\nadded the\njs_body_filter\ndirective.\n
\nFeature:\nintroduced the\ns.status\nproperty for\nStream Session\nobject.\n
\n
\nCore:\n
\nFeature:\nadded\nnjs.on\n(exit) callback support.\n
\nBugfix:\nfixed property descriptor reuse for not extensible objects.\nThanks to Artem S. Povalyukhin.\n
\n\nBugfix:\nfixed Object.freeze() and friends\naccording to the specification.\nThanks to Artem S. Povalyukhin.\n
\nBugfix:\nfixed Function() in CLI mode.\n
\nBugfix:\nfixed for-in iteration of typed array values.\nThanks to Artem S. Povalyukhin.\n
\n
\nRelease Date:\n16 February 2021\n
\nnginx modules:\n
\nFeature:\nintroduced\nngx.fetch()\nmethod implementing Fetch API.\n
\nThe following properties and methods of\nResponse\nobject are implemented:\narrayBuffer(),\nbodyUsed,\njson(),\nheaders,\nok,\nredirect,\nstatus,\nstatusText,\ntext(),\ntype,\nurl.\n
\nNotable limitations:\nonly the http:// scheme is supported,\nredirects are not handled.\n
\nIn collaboration with 洪志道 (Hong Zhi Dao).\n
\n\nFeature:\nadded the\njs_header_filter\ndirective.\n
\nBugfix:\nfixed processing buffered data in body filter in\nstream module.\n
\n\n
\nCore:\n
\nBugfix:\nfixed safe mode bypass in Function constructor.\n
\nBugfix:\nfixed Date.prototype.toISOString() with invalid date values.\n
\n
\nRelease Date:\n01 December 2020\n
\nnginx modules:\n
\nFeature:\nintroduced global\nngx object.\n
\nThe following methods were added:\n
\n
\n\n\nThe following properties were added:\n
\nngx.INFO,\nngx.WARN,\nngx.ERR.\n
\n
\n\n\nFeature:\nadded support for\nBuffer object where string is expected.\n
\nFeature:\nadded Buffer version of existing properties.\n
\n\n\nThe following properties were added:\n
\nr.requestBuffer\n(r.requestBody),\nr.responseBuffer\n(r.responseBody),\nr.rawVariables\n(r.variables),\ns.rawVariables\n(s.variables).\n
\n
\n\n\nThe following events were added in the stream module:\n
\nupstream\n(upload),\ndownstream\n(download).\n
\n
\n\n\nImprovement:\nadded aliases to existing properties.\n
\n\n\nThe following properties were added:\n
\nr.requestText\n(r.requestBody),\nr.responseText\n(r.responseBody).\n
\n
\n\n\nImprovement:\nthrowing an exception in\nr.internalRedirect()\nfor a subrequest.\n
\nBugfix:\nfixed promise\nr.subrequest()\nwith\nerror_page\nredirect.\n
\nBugfix:\nfixed\npromise events handling.\n
\n
\nCore:\n
\nFeature:\nadded\nTypeScript definitions for built-in modules.\nThanks to Jakub Jirutka.\n
\nFeature:\ntracking unhandled promise rejection.\n
\nFeature:\nadded initial iterator support.\nThanks to Artem S. Povalyukhin.\n
\n\nImprovement:\nTypeScript definitions are refactored.\nThanks to Jakub Jirutka.\n
\nImprovement:\nadded forgotten support for\nObject.prototype.valueOf()\nin\nBuffer.from().\n
\nBugfix:\nfixed heap-use-after-free in\nJSON.parse().\n
\nBugfix:\nfixed heap-use-after-free in\nJSON.stringify().\n
\nBugfix:\nfixed\nJSON.stringify() for arrays resizable via getters.\n
\nBugfix:\nfixed heap-buffer-overflow for\nRegExp.prototype[Symbol.replace].\n
\nBugfix:\nfixed returned value for\nBuffer.prototype.write*\nfunctions.\n
\nBugfix:\nfixed\nquerystring.stringify().\nThanks to Artem S. Povalyukhin.\n
\nBugfix:\nfixed the catch handler for\nPromise.prototype.finally().\n
\nBugfix:\nfixed\nquerystring.parse().\n
\n
\nRelease Date:\n29 September 2020\n
\nnginx modules:\n
\nBugfix:\nfixed location merge.\n
\n\nBugfix:\nfixed\nr.httpVersion\nfor HTTP/2.\n
\n
\nCore:\n
\nFeature:\nadded support for numeric separators (ES12).\n
\n\nFeature:\nadded remaining methods for\n%TypedArray%.prototype.\nThe following methods were added:\nevery(),\nfilter(),\nfind(),\nfindIndex(),\nforEach(),\nincludes(),\nindexOf(),\nlastIndexOf(),\nmap(),\nreduce(),\nreduceRight(),\nreverse(),\nsome().\n
\nFeature:\nadded %TypedArray% remaining methods.\nThe following methods were added:\nfrom(),\nof().\n
\nFeature:\nadded DataView object.\n
\nFeature:\nadded Buffer object implementation.\n
\nFeature:\nadded support for ArrayBuffer in\nTextDecoder.prototype.decode()\n
\nFeature:\nadded support for Buffer object in\ncrypto\nmethods.\n
\nFeature:\nadded support for Buffer object in\nfs\nmethods.\n
\nChange:\nHash.prototype.digest()\nand\nHmac.prototype.digest()\nnow return a Buffer instance instead of a byte string when\nencoding is not provided.\n
\nChange:\nfs.readFile()\nand friends now return a Buffer instance\ninstead of a byte string when encoding is not provided.\n
\nBugfix:\nfixed function prototype property handler while setting.\n
\nBugfix:\nfixed function constructor property handler while setting.\n
\nBugfix:\nfixed String.prototype.indexOf()\nfor byte strings.\n
\nBugfix:\nfixed RegExpBuiltinExec()\nwith a global flag and byte strings.\n
\nBugfix:\nfixed RegExp.prototype[Symbol.replace]\nthe when replacement value is a function.\n
\nBugfix:\nfixed\nTextDecoder.prototype.decode()\nwith non-zero TypedArray offset.\n
\n
\nRelease Date:\n11 August 2020\n
\nCore:\n
\nFeature:\nadded\nQuery String\nmodule.\n
\nFeature:\nimproved\nfs.mkdir()\nto support recursive directory creation.\nThanks to Artem S. Povalyukhin.\n
\nFeature:\nimproved\nfs.rmdir()\nto support recursive directory removal.\nThanks to Artem S. Povalyukhin.\n
\nFeature:\nintroduced UTF-8 decoder according to\nWHATWG encoding spec.\n
\n\nFeature:\nadded\nTextDecoder()\nand\nTextEncoder()\nimplementation.\n
\nBugfix:\nfixed parsing return statement without semicolon.\n
\n\nBugfix:\nfixed njs_number_to_int32() for big-endian platforms.\n
\nBugfix:\nfixed unit test on big-endian platforms.\n
\n\nBugfix:\nfixed regexp-literals parsing with “=” characters.\n
\nBugfix:\nfixed pre/post increment/decrement in assignment operations.\n
\n\n
\nRelease Date:\n07 July 2020\n
\nCore:\n
\nFeature:\nadded RegExp.prototype[Symbol.replace].\n
\nFeature:\nintroduced line level backtrace.\n
\n\nFeature:\nadded %TypedArray%.prototype.sort().\n
\nFeature:\nextended\nfs module.\nAdded\nmkdir(),\nreaddir(),\nrmdir(),\nand friends.\n
\nImprovement:\nparser refactoring.\n
\n\nBugfix:\nfixed TypedScript API description for HTTP headers.\n
\n\nBugfix:\nfixed TypedScript API description for NjsByteString type.\n
\nBugfix:\nfixed\nString.prototype.repeat()\naccording to the specification.\n
\nBugfix:\nfixed\nString.prototype.replace()\naccording to the specification.\n
\nBugfix:\nfixed parsing of flags for regexp literals.\n
\n\nBugfix:\nfixed index generation for global objects in generator.\n
\n\nBugfix:\nfixed %TypedArray%.prototype.copyWithin()\nwith nonzero byte offset.\n
\nBugfix:\nfixed Array.prototype.splice()\nfor sparse arrays.\n
\nBugfix:\nfixed Array.prototype.reverse()\nfor sparse arrays.\n
\nBugfix:\nfixed Array.prototype.sort()\nfor sparse arrays.\n
\n
\nRelease Date:\n19 May 2020\n
\nnginx modules:\n
\nFeature:\nadded support for multi-value headers in\nr.headersIn{}.\n
\nFeature:\nintroduced raw headers API:\nr.rawHeadersIn[]\nand\nr.rawHeadersOut[].\n
\nFeature:\nadded TypeScript API description.\n
\n\n
\nCore:\n
\nBugfix:\nfixed Array.prototype.slice() for sparse arrays.\n
\n
\nRelease Date:\n23 April 2020\n
\nnginx modules:\n
\nFeature:\nadded support for multi-value headers in\nr.headersOut{}.\n
\nFeature:\nadded js_import directive for\nhttp and\nstream.\n
\nImprovement:\nimproved iteration over\nr.headersOut{}\nwith special headers.\n
\nImprovement:\nimproved iteration over\nr.headersOut{}\nwith duplicates.\n
\nChange:\nr.responseBody\nproperty handler now returns\nundefined\ninstead of throwing an exception if the response body is not available.\n
\n
\nCore:\n
\nFeature:\nadded script arguments support in CLI.\n
\n\nFeature:\nconverting externals values to native js objects.\n
\n\nBugfix:\nfixed NULL-pointer dereference\nin __proto__ property handler.\n
\nBugfix:\nfixed handling of no-newline at the end of the script.\n
\n\nBugfix:\nfixed RegExp() constructor\nwith empty pattern and non-empty flags.\n
\nBugfix:\nfixed\nString.prototype.replace()\nwhen function returns non-string.\n
\nBugfix:\nfixed reading of pseudofiles in\nfs.\n
\n
\nRelease Date:\n03 March 2020\n
\nnginx modules:\n
\nFeature:\nadded detached mode for\nr.subrequest().\nResponses to detached subrequests are ignored.\nUnlike ordinary subrequests,\na detached subrequest can be created inside a variable handler.\n
\n
\nCore:\n
\nFeature:\nadded promises API for\nfs module.\nThanks to Artem S. Povalyukhin.\n
\nFeature:\nextended fs\nmodule.\nAdded\naccess(),\nsymlink(),\nunlink(),\nrealpath(),\nand friends.\nThanks to Artem S. Povalyukhin.\n
\nImprovement:\nintroduced memory-efficient ordinary arrays.\n
\n\nImprovement:\nlexer refactoring.\n
\n\nBugfix:\nfixed matching of native functions in backtraces.\n
\n\nBugfix:\nfixed callback invocations in\nfs module.\nThanks to Artem S. Povalyukhin.\n
\nBugfix:\nfixed Object.getOwnPropertySymbols().\n
\nBugfix:\nfixed heap-buffer-overflow in\nnjs_json_append_string().\n
\nBugfix:\nfixed\nencodeURI()\nand\ndecodeURI()\naccording to the specification.\n
\nBugfix:\nfixed Number.prototype.toPrecision().\n
\nBugfix:\nfixed handling of space argument in\nJSON.stringify().\n
\nBugfix:\nfixed\nJSON.stringify()\nwith\nNumber() and\nString()\nobjects.\n
\nBugfix:\nfixed Unicode Escaping in\nJSON.stringify()\naccording to specification.\n
\nBugfix:\nfixed non-native module importing.\nThanks to 洪志道 (Hong Zhi Dao).\n
\n\nBugfix:\nfixed\nnjs.dump() with the\nDate()\ninstance in a container.\n
\n
\nRelease Date:\n21 January 2020\n
\nnginx modules:\n
\nFeature:\nadded Promise support for\nr.subrequest().\nIf a callback is not provided,\nr.subrequest()\nreturns an ordinary\nPromise object\nthat resolves to a subrequest response object.\n
\nChange:\nr.parent\nproperty handler now returns\nundefined\ninstead of throwing an exception if a parent object is not available.\n
\n
\nCore:\n
\nFeature:\nadded Promise support.\nImplemented according to the specification without:\nPromise.all(),\nPromise.allSettled(),\nPromise.race().\n
\nFeature:\nadded initial Typed-arrays support.\nThanks to Tiago Natel de Moura.\n
\n\nFeature:\nadded ArrayBuffer support.\nThanks to Tiago Natel de Moura.\n
\nFeature:\nadded initial Symbol support.\nThanks to Artem S. Povalyukhin.\n
\nFeature:\nadded externals support for\nJSON.stringify().\n
\nFeature:\nadded Object.is().\nThanks to Artem S. Povalyukhin.\n
\nFeature:\nadded Object.setPrototypeOf().\nThanks to Artem S. Povalyukhin.\n
\nFeature:\nintroduced nullish coalescing operator.\n
\n\nBugfix:\nfixed\nObject.getPrototypeOf()\naccording to the specification.\n
\nBugfix:\nfixed\nObject.prototype.valueOf()\naccording to the specification.\n
\nBugfix:\nfixed\nJSON.stringify()\nwith unprintable values and replacer function.\n
\nBugfix:\nfixed operator in\naccording to the specification.\n
\nBugfix:\nfixed\nObject.defineProperties()\naccording to the specification.\n
\nBugfix:\nfixed\nObject.create()\naccording to the specification.\nThanks to Artem S. Povalyukhin.\n
\nBugfix:\nfixed\nNumber.prototype.toString(radix)\nwhen fast-math is enabled.\n
\nBugfix:\nfixed RegExp() instance properties.\n
\nBugfix:\nfixed import segfault.\nThanks to 洪志道 (Hong Zhi Dao).\n
\n\n
\nRelease Date:\n19 November 2019\n
\nnginx modules:\n
\nImprovement:\nrefactored iteration over external objects.\n
\n\n
\nCore:\n
\nFeature:\nadded Object.assign().\n
\nFeature:\nadded Array.prototype.copyWithin().\n
\nFeature:\nadded support for labels in console.time().\n
\nChange:\nremoved console.help() from CLI.\n
\nImprovement:\nmoved constructors and top-level objects to global object.\n
\n\nImprovement:\narguments validation for configure script.\n
\n\nImprovement:\nrefactored JSON methods.\n
\n\nBugfix:\nfixed heap-buffer-overflow in\nnjs_array_reverse_iterator() function.\nThe following functions were affected:\nArray.prototype.lastIndexOf(),\nArray.prototype.reduceRight().\n
\nBugfix:\nfixed\n[[Prototype]] slot of NativeErrors.\n
\nBugfix:\nfixed\nNativeError.prototype.message properties.\n
\nBugfix:\nadded conversion of\nthis value to object in\nArray.prototype functions.\n
\nBugfix:\nfixed iterator for\nArray.prototype.find() and\nArray.prototype.findIndex()\nfunctions.\n
\nBugfix:\nfixed\nArray.prototype.includes() and\nArray.prototype.join() with\nundefined argument.\n
\nBugfix:\nfixed constructor property of\nHash and\nHmac\nobjects.\n
\nBugfix:\nfixed __proto__ property of getters and setters.\n
\nBugfix:\nfixed Date object string formatting.\n
\nBugfix:\nfixed handling of\nNaN and -0 arguments in\nMath.min() and\nMath.max().\n
\nBugfix:\nfixed Math.round()\naccording to the specification.\n
\nBugfix:\nreimplemented bound functions\naccording to the specification.\n
\n
\nRelease Date:\n22 October 2019\n
\nnginx modules:\n
\nImprovement:\ngetting special headers from\nr.headersIn{}.\n
\n
\nCore:\n
\nFeature:\nadded new Function() support.\n
\nFeature:\nadded Number.prototype.toFixed().\n
\nFeature:\nadded Number.prototype.toPrecision().\n
\nFeature:\nadded Number.prototype.toExponential().\n
\nImprovement:\nmaking prototype property of function instances writable.\n
\nImprovement:\nlimiting recursion depth while compiling.\n
\n\nImprovement:\nmoving global functions to the global object.\n
\n\nBugfix:\nfixed prototype mutation for object literals.\n
\n\nBugfix:\nfixed heap-buffer-overflow while parsing regexp literals.\n
\n\nBugfix:\nfixed integer-overflow while parsing exponent of number literals.\n
\n\nBugfix:\nfixed parseFloat().\n
\nBugfix:\nfixed Array.prototype functions\naccording to the specification.\nThe following functions were fixed:\nevery,\nincludes,\nindexOf,\nfilter,\nfind,\nfindIndex,\nforEach,\nlastIndexOf,\nmap,\npop,\npush,\nreduce,\nreduceRight,\nshift,\nsome,\nunshift.\n
\nBugfix:\nfixed handing of accessor descriptors in Object.freeze().\n
\nBugfix:\nfixed\nString.prototype.replace()\nwhen first argument is not a string.\n
\nBugfix:\nfixed stack-use-after-scope in Array.prototype.map().\n
\nBugfix:\nDate.prototype.toUTCString()\nformat was aligned to ES9.\n
\nBugfix:\nfixed buffer overflow in\nNumber.prototype.toString(radix).\n
\nBugfix:\nfixed\nRegexp.prototype.test()\nfor regexps with backreferences.\n
\nBugfix:\nfixed\nArray.prototype.map()\nfor objects with nonexistent values.\n
\nBugfix:\nfixed\nArray.prototype.pop() and\nshift() for sparse objects.\n
\nBugfix:\nfixed\nDate.UTC()\naccording to the specification.\n
\nBugfix:\nfixed\nDate() constructor\naccording to the specification.\n
\nBugfix:\nfixed type of\nDate.prototype.\nThanks to Artem S. Povalyukhin.\n
\nBugfix:\nfixed\nDate.prototype.setTime().\nThanks to Artem S. Povalyukhin.\n
\nBugfix:\nfixed default number of arguments expected by built-in functions.\n
\n\nBugfix:\nfixed\ncaller and\narguments\nproperties of a function instance.\nThanks to Artem S. Povalyukhin.\n
\n
\nRelease Date:\n15 August 2019\n
\nCore:\n
\nBugfix:\nfixed module importing using require().\nThe bug was introduced in 0.3.4.\n
\nBugfix:\nfixed\n[[SetPrototypeOf]].\n
\n
\nRelease Date:\n13 August 2019\n
\nCore:\n
\nFeature:\nadded\nObject\nshorthand methods and computed property names.\nThanks to 洪志道 (Hong Zhi Dao) and Artem S. Povalyukhin.\n
\nFeature:\nadded getter/setter literal support.\nThanks to 洪志道 (Hong Zhi Dao) and Artem S. Povalyukhin.\n
\n\nFeature:\nadded\nfs.renameSync().\n
\nFeature:\nadded\nString.prototype.trimEnd()\nand\nString.prototype.trimStart().\n
\nImprovement:\nadded memory-sanitizer support.\n
\n\nImprovement:\nUnicode case tables updated to version 12.1.\n
\n\nImprovement:\nadded UTF8 validation for string literals.\n
\n\nBugfix:\nfixed reading files with zero size in\nfs.readFileSync().\n
\nBugfix:\nextended the list of space separators in\nString.prototype.trim().\n
\nBugfix:\nfixed using of uninitialized value in\nString.prototype.padStart().\n
\nBugfix:\nfixed\nString.prototype.replace()\nfor $0 and $& replacement string.\n
\nBugfix:\nfixed\nString.prototype.replace()\nfor byte strings with regex argument.\n
\nBugfix:\nfixed global match in\nString.prototype.replace()\nwith regexp argument.\n
\nBugfix:\nfixed\nArray.prototype.slice()\nfor primitive types.\n
\nBugfix:\nfixed heap-buffer-overflow while importing module.\n
\n\nBugfix:\nfixed UTF-8 character escaping.\n
\n\nBugfix:\nfixed\nObject.values()\nand\nObject.entries()\nfor shared objects.\n
\nBugfix:\nfixed uninitialized memory access in\nString.prototype.match().\n
\nBugfix:\nfixed\nString.prototype.match()\nfor byte strings with regex argument.\n
\nBugfix:\nfixed\nArray.prototype.lastIndexOf()\nwith undefined arguments.\n
\nBugfix:\nfixed\nString.prototype.substring()\nwith empty substring.\n
\nBugfix:\nfixed invalid memory access in\nString.prototype.substring().\n
\nBugfix:\nfixed\nString.fromCharCode()\nfor code points more than 65535 and NaN.\n
\nBugfix:\nfixed\nString.prototype.toLowerCase()\nand\nString.prototype.toUpperCase().\n
\nBugfix:\nfixed\nError()\nconstructor with no arguments.\n
\nBugfix:\nfixed\nin\noperator for values with accessor descriptors.\n
\nBugfix:\nfixed\nObject.defineProperty()\nfor non-boolean descriptor props.\n
\nBugfix:\nfixed\nError.prototype.toString()\nwith UTF8 string properties.\n
\nBugfix:\nfixed\nError.prototype.toString()\nwith non-string values for name and message.\n
\n
\nRelease Date:\n25 June 2019\n
\nnginx modules:\n
\nImprovement:\ngetting of special response headers in\nr.headersOut{}.\n
\nImprovement:\nworking with unknown methods in\nr.subrequest().\n
\nImprovement:\nadded support for null as a second argument of\nr.subrequest().\n
\nBugfix:\nfixed processing empty output chain in stream body filter.\n
\n\n
\nCore:\n
\nFeature:\nadded runtime support for property getter/setter.\nThanks to 洪志道 (Hong Zhi Dao) and Artem S. Povalyukhin.\n
\n\nFeature:\nadded\nprocess\nglobal object.\n
\nFeature:\nwritable most of built-in properties and methods.\n
\n\nFeature:\nadded generic implementation of\nArray.prototype.fill().\n
\nBugfix:\nfixed integer-overflow in\nString.prototype.concat().\n
\nBugfix:\nfixed setting of object properties.\n
\n\nBugfix:\nfixed\nArray.prototype.toString().\n
\nBugfix:\nfixed\nDate.prototype.toJSON().\n
\nBugfix:\nfixed overwriting “constructor” property of built-in prototypes.\n
\n\nBugfix:\nfixed processing of invalid surrogate pairs in strings.\n
\n\nBugfix:\nfixed processing of invalid surrogate pairs in JSON strings.\n
\n\nBugfix:\nfixed heap-buffer-overflow in\ntoUpperCase()\nand\ntoLowerCase().\n
\nBugfix:\nfixed escaping lone closing square brackets in\nRegExp() constructor.\n
\nBugfix:\nfixed handling zero byte characters inside RegExp pattern strings.\n
\n\nBugfix:\nfixed\nString.prototype.toBytes()\nfor ASCII strings.\n
\nBugfix:\nfixed truth value of JSON numbers in\nJSON.parse().\n
\nBugfix:\nfixed use-of-uninitialized-value in\nnjs_string_replace_join().\n
\nBugfix:\nfixed parseInt('-0').\nThanks to Artem S. Povalyukhin.\n
\n
\nRelease Date:\n21 May 2019\n
\nCore:\n
\nFeature:\nadded support for template literals.\nThanks to 洪志道 (Hong Zhi Dao) and Artem S. Povalyukhin.\n
\n\nFeature:\nexecuting command from command line arguments.\n
\n\nFeature:\nadded support for RegExp groups object (ES9).\n
\nFeature:\nadded block scoped function definitions support.\n
\n\nFeature:\nadded support for building with GNU Readline library.\n
\n\nFeature:\nmade configurable\nlength,\nname,\nand most of built-in methods.\n
\nFeature:\nmade all constructor properties configurable.\n
\n\nBugfix:\nfixed\nRegexp.prototype.exec()\nfor Unicode-only regexps.\n
\nBugfix:\nfixed\nnjs_vm_value_dump()\nfor empty string values.\n
\nBugfix:\nfixed RegExp constructor for regexp value arguments.\n
\n\nBugfix:\nfixed walking over prototypes chain during iteration over an object.\n
\n\nBugfix:\nfixed overflow in\nArray.prototype.concat().\n
\nBugfix:\nfixed length calculation for UTF-8 string with escape characters.\n
\n\nBugfix:\nfixed parsing surrogate pair presents as UTF-16 escape sequences.\n
\n\nBugfix:\nfixed processing the “*” quantifier for\nString.prototype.match().\n
\nBugfix:\nfixed\nDate()\nconstructor with one argument.\n
\nBugfix:\nfixed arrays expansion.\n
\n\nBugfix:\nfixed heap-buffer-overflow in\nString.prototype.replace().\n
\nBugfix:\nfixed heap-buffer-overflow in\nString.prototype.lastIndexOf().\n
\nBugfix:\nfixed regexp literals parsing with escaped backslash\nand backslash in square brackets.\n
\n\nBugfix:\nfixed regexp literals with lone closing brackets.\n
\n\nBugfix:\nfixed uninitialized-memory-access in\nObject.defineProperties().\n
\nBugfix:\nfixed processing the “*” quantifier for\nString.prototype.replace().\n
\nBugfix:\nfixed\nArray.prototype.slice()\nfor UTF8-invalid byte strings.\n
\nBugfix:\nfixed\nString.prototype.split()\nfor UTF8-invalid byte strings.\n
\nBugfix:\nfixed handling of empty block statements.\n
\n\n
\nRelease Date:\n16 April 2019\n
\nCore:\n
\nFeature:\nadded arrow functions support.\nThanks to 洪志道 (Hong Zhi Dao) and Artem S. Povalyukhin.\n
\n\nFeature:\nadded\nObject.getOwnPropertyNames().\nThanks to Artem S. Povalyukhin.\n
\nFeature:\nadded\nObject.getOwnPropertyDescriptors().\nThanks to Artem S. Povalyukhin.\n
\nFeature:\nmaking __proto__ accessor descriptor\nof Object instances mutable.\n
\nFeature:\nadded shebang support in CLI.\n
\n\nFeature:\nadded support for module mode execution in CLI.\nIn module mode global, this is unavailable.\n
\n\nBugfix:\nfixed editline detection.\n
\n\nBugfix:\nfixed\nFunction.prototype.bind().\nThanks to 洪志道 (Hong Zhi Dao).\n
\nBugfix:\nfixed checking of duplication of parameters for functions.\nThanks to 洪志道 (Hong Zhi Dao).\n
\n\nBugfix:\nfixed function declaration with the same name as a variable.\nThanks to 洪志道 (Hong Zhi Dao).\n
\n\nImprovement:\ncode related to parsing of objects, variables and\nfunctions is refactored.\nThanks to 洪志道 (Hong Zhi Dao).\n
\n\nImprovement:\nlarge-value output improved in console.log().\n
\nImprovement:\nstring output improved in console.log()\nin a compliant way (without escaping and quotes).\n
\nImprovement:\nusing ES6 version of\nToInt32(),\nToUint32(),\nToLength().\n
\n
\nRelease Date:\n26 March 2019\n
\nnginx modules:\n
\nFeature:\nadded the js_path directive for\nhttp and\nstream.\n
\nChange:\nreturning undefined value instead of empty strings\nfor absent properties in the following objects:\nr.args{},\nr.headersIn{},\nr.headersOut{},\nr.variables{},\ns.variables{}.\n
\nChange:\nreturning undefined value instead of throwing an exception for\nr.requestBody\nwhen request body is unavailable.\n
\nBugfix:\nfixed crash while iterating over\nr.args{}\nwhen a value is absent in a key-value pair.\n
\n
\nCore:\n
\nFeature:\nadded initial ES6 modules support.\nDefault import and default export statements are supported.\nThanks to 洪志道 (Hong Zhi Dao).\n
\n\nFeature:\nadded\nObject.prototype.propertyIsEnumerable().\n
\nFeature:\nreporting file name and function name in disassembler output.\n
\n\nBugfix:\nfixed function redeclarations in interactive shell.\nThanks to 洪志道 (Hong Zhi Dao).\n
\n\nBugfix:\nfixed RegExp literals parsing.\n
\n\nBugfix:\nfixed setting length of UTF8 string in\nfs.readFileSync().\n
\nBugfix:\nfixed\nnxt_file_dirname() for paths with no dir component.\n
\n
\nRelease Date:\n26 February 2019\n
\nnginx modules:\n
\nChange:\nproperties of HTTP request deprecated in 0.2.2\nare removed.\n
\n\nFeature:\nadded support for delete operation in\nr.headersOut{}.\n
\nFeature:\nadded support for setting nginx variables.\n
\n\nBugfix:\nfixed\nr.subrequest()\nfor empty body value.\n
\nImprovement:\nsetting special response headers in\nr.headersOut{}.\n
\n
\nCore:\n
\nFeature:\nadded labels support.\n
\n\nFeature:\nadded\nsetImmediate() method.\n
\nFeature:\nadded support for shorthand property names for Object literals.\n
\n\nBugfix:\nfixed\nFunction.prototype.bind().\n
\nBugfix:\nfixed parsing of string literals containing newline characters.\n
\n\nBugfix:\nfixed line number in reporting variable reference errors.\n
\n\nBugfix:\nfixed creation of long UTF8 strings.\n
\n\nBugfix:\nfixed\nsetting special response headers in\nString.prototype.split()\nfor Unicode strings.\n
\nBugfix:\nfixed heap-buffer-overflow in\nString.prototype.split().\n
\nBugfix:\nfixed\nArray.prototype.fill().\nThanks to Artem S. Povalyukhin.\n
\nImprovement:\ncode related to function invocation is refactored.\nThanks to 洪志道 (Hong Zhi Dao).\n
\n\nImprovement:\ncode related to variables is refactored.\nThanks to 洪志道 (Hong Zhi Dao).\n
\n\nImprovement: parser is refactored.\nThanks to 洪志道 (Hong Zhi Dao).\n
\n\nImprovement:\nreporting filenames in exceptions.\n
\n\n
\nRelease Date:\n25 December 2018\n
\nCore:\n
\nFeature:\nrest parameters syntax (destructuring is not supported).\nThanks to Alexander Pyshchev.\n
\n\nFeature:\nadded\nObject.entries()\nmethod.\n
\nFeature:\nadded\nObject.values()\nmethod.\n
\nImprovement:\ncode generator refactored and simplified.\n
\n\nBugfix:\nfixed automatic semicolon insertion.\n
\n\nBugfix:\nfixed assignment expression from compound assignment.\n
\n\nBugfix:\nfixed comparison of Byte and UTF8 strings.\n
\n\nBugfix:\nfixed type of iteration variable in for-in with array values.\n
\nBugfix:\nfixed building on platforms without librt.\n
\n\nBugfix:\nmiscellaneous bugs have been fixed.\n
\n\n
\nRelease Date:\n27 November 2018\n
\nCore:\n
\nFeature:\nmaking built-in prototypes mutable.\n
\n\nFeature:\nmaking global object mutable.\n
\n\nFeature:\nconsole.time()\nand\nconsole.timeEnd()\nmethods.\n
\nFeature:\nallowing variables and functions to be redeclared.\n
\n\nFeature:\nextending Object.defineProperty() spec conformance.\n
\nFeature:\nintroduced quiet mode for CLI to handle simple expressions from stdin.\n
\n\nFeature:\nintroduced compact form of backtraces to handle stack overflows.\n
\n\nImprovement:\nimproved wording for various exceptions.\n
\n\nBugfix:\nfixed closure values handling.\n
\n\nBugfix:\nfixed equality operator for various value types.\n
\n\nBugfix:\nfixed handling of this keyword in various scopes.\n
\nBugfix:\nfixed handling non-object values in\nObject.keys().\n
\nBugfix:\nfixed parsing of throw statement inside\nif statement.\n
\nBugfix:\nfixed parsing of newline after throw statement.\n
\n\nBugfix:\nfixed parsing of statements in if statement without newline.\n
\n\nBugfix:\nfixed size uint32_t overflow\nin njs_array_expand().\n
\nBugfix:\nfixed typeof operator\nfor object_value type.\n
\nBugfix:\nmiscellaneous bugs have been fixed.\n
\n\n
\nRelease Date:\n30 October 2018\n
\nnginx modules:\n
\nBugfix:\nfixed counting pending events in stream module.\n
\n\nBugfix:\nfixed\ns.off() in stream module.\n
\nBugfix:\nfixed processing of data chunks in\njs_filter in stream module.\n
\nBugfix:\nfixed http\nstatus and\ncontentType\ngetter in http module.\n
\nBugfix:\nfixed http response and parent getters in http module.\n
\n\n
\nCore:\n
\nFeature:\narguments object support.\n
\n\nFeature:\nnon-integer fractions support.\n
\n\nImprovement:\nhandling non-array values in\nArray.prototype.slice().\n
\nBugfix:\nfixed\nArray.prototype.length setter\n
\nBugfix:\nfixed\nnjs_array_alloc() for length > 2**31.\n
\nBugfix:\nhandling int overflow in\nnjs_array_alloc() on 32bit archs.\n
\nBugfix:\nfixed code size mismatch error message.\n
\n\nBugfix:\nfixed delete operator in a loop.\n
\n\nBugfix:\nfixed\nObject.getOwnPropertyDescriptor()\nfor complex object (inherited from\nArray and\nstring values).\n
\nBugfix:\nfixed\nObject.prototype.hasOwnProperty()\nfor non-object properties\n
\nBugfix:\nmiscellaneous bugs have been fixed.\n
\n\n
\nRelease Date:\n18 September 2018\n
\nnginx modules:\n
\nChange:\nstream module handlers refactored.\n
\n\n\nNew methods and properties:\ns.on(),\ns.off(),\ns.allow(),\ns.done(),\ns.decline(),\ns.deny().\n
\nRemoved properties of the\nStream object:\ns.OK,\ns.ABORT,\ns.AGAIN,\ns.DECLINED,\ns.ERROR\n(replaced with\ns.allow(),\ns.done(),\ns.deny()).\n
\ns.buffer\n(for reading replaced with data argument of\nthe corresponding callback, for writing use\ns.send()).\n
\ns.fromUpstream\n(replaced with a callback for a corresponding event).\n
\ns.eof\n(replaced with \nflags.last).\n
\n
\nCore:\n
\nFeature:\nadded\nFunction.prototype.length.\n
\nFeature:\nintroduced sandboxing mode.\n
\n\nImprovement:\nadded exception strings where appropriate.\n
\n\nImprovement:\nimproved wording for primitive type conversion exception.\n
\n\nBugfix:\nthrowing TypeError\nfor attempts to change frozen properties.\n
\nBugfix:\nfixed\nObject.defineProperty() for existing properties.\n
\nBugfix:\nrespecting the enumerable attribute while iterating by for in.\n
\n\nBugfix:\nrespecting writable attribute for property handlers.\n
\n\nBugfix:\nfixed exception handling in arguments of a function.\n
\n\nBugfix:\nfixed\nObject.prototype.toString\nfor different value types.\n
\nBugfix:\nfixed\nObject()\nconstructor for object types arguments.\n
\nBugfix:\nfixed comparison of objects and strings.\n
\n\nBugfix:\nfixed\nString.slice()\nfor undefined arguments.\n
\nBugfix:\nmiscellaneous bugs have been fixed.\n
\n\n
\nRelease Date:\n31 July 2018\n
\nnginx modules:\n
\nBugfix:\nmaking a subrequest from a\nReply\nobject caused a segmentation fault.\n
\nBugfix:\ngetting the parent property of the main\nHTTP Request\nobject caused a segmentation fault.\n
\n\n
\nCore:\n
\nFeature:\nadded the pretty string representation for values.\n
\n\nFeature:\ncorrectly printing floating point numbers.\n
\n\nFeature:\ncorrectly parsing floating point numbers.\n
\n\nFeature:\nString.bytesFrom() method\n(decoding hex,\nbase64,\nbase64url into a byte string).\n
\nFeature:\nString.padStart() and\nString.padEnd()\nmethods.\n
\nFeature:\nadded support of binary literals.\n
\n\nImprovement:\nadded information about illegal token in number parsing.\n
\n\nImprovement:\nallowed uppercased O in octal literal values.\n
\nImprovement:\nadded support for multiple arguments in console.log().\n
\nBugfix:\nfixed applying call() to methods of external values.\n
\nBugfix:\nfixed addition operator applied to an object.\n
\n\nBugfix:\nfixed exception handling in\nnjs_vm_value_to_ext_string().\n
\nBugfix:\nfixed\nNumber() with boolean, null and undefined arguments.\n
\nBugfix:\nfixed error handling of setting non-numeric Array.length.\n
\nBugfix:\nfixed autocompletion for global objects.\n
\n\nBugfix:\nmiscellaneous bugs have been fixed.\n
\n\n
\nRelease Date:\n19 June 2018\n
\nnginx modules:\n
\nChange:\nmerged HTTP Response and Reply\ninto HTTP Request.\nNew members of Request:\n\n
\nreq.status (res.status)\n
\nreq.parent (reply.parent)\n
\nreq.requestBody (req.body)\n
\nreq.responseBody (reply.body)\n
\nreq.headersIn (req.headers)\n
\nreq.headersOut (res.headers)\n
\nreq.sendHeader() (res.sendHeader())\n
\nreq.send() (res.send())\n
\nreq.finish() (res.finish())\n
\nreq.return() (res.return())\n
\nDeprecated members of Request:\n\n
\nreq.body (use req.requestBody\nor req.responseBody)\n
\nreq.headers (use req.headersIn\nor req.headersOut)\n
\nreq.response\n
\nDeprecated members of Response:\n\n
\nres.contentLength (use\nreq.headersOut['Content-Length'])\n
\nres.contentType (use req.headersOut['Content-Type'])\n
\nThe deprecated properties will be removed in\nnext releases.\n
\n\nFeature:\nHTTP internalRedirect()\nmethod.\n
\n\n
\nCore:\n
\nBugfix:\nfixed heap-buffer-overflow in\ncrypto.createHmac().\n
\n
\nRelease Date:\n31 May 2018\n
\nnginx modules:\n
\nFeature:\nHTTP request body getter.\n
\n\nImprovement:\nmoved njs vm to the main configuration.\n
\nImprovement:\nimproved logging for\njs_set and\njs_content directives.\n
\n\nImprovement:\nsetting status code to 500 by default in the\njs_content handler\n
\n\nImprovement:\nadded the debug for the returned status code in\njs_content handler\n
\n\nBugfix: fixed error logging in\njs_include.\n
\n\n
\nCore:\n
\nFeature:\nadded array length setter.\n
\n\nImprovement:\npublic header cleanup. njscript.h is renamed to\nnjs.h.\n
\nBugfix:\nfixed crypto update() method after\ndigest() is called.\n
\nBugfix:\nfixed crypto.createHmac() for keys with size <= alg size\nand > 64.\n
\nBugfix:\nfixed JSON.stringify() for arrays with empty cells.\n
\nBugfix:\nfixed exception type for unsupported types in\nJSON.stringify().\n
\nBugfix:\nfixed handling of undefined arguments of functions.\n
\n\nBugfix:\nfixed handling of missing arg of\nObject.getOwnPropertyDescriptor().\n
\nBugfix:\nfixed handling of properties in\nObject.getOwnPropertyDescriptor().\n
\nBugfix:\nfixed the writeable flag of Array.length property.\n
\nBugfix: fixed return value type of clearTimeout().\n
\nBugfix:\nfixed njs_vm_external_bind().\n
\nBugfix:\nmiscellaneous bugs have been fixed.\n
\n\n
\nRelease Date:\n03 April 2018\n
\n
\nFeature:\nreporting njs version by CLI.\n
\n\nFeature:\ntextual description for type converting exceptions.\n
\nsetTimeout() and\nclearTimeout() methods.\n\nFeature:\nByte string to\nhex,\nbase64,\nbase64url encodings.\n
\nFeature:\nNode.js style\nCrypto methods.\n
\nFeature:\nHTTP and stream\nwarn() and\nerror() methods.\n
\nFeature:\nHTTP subrequest() method.\n
\nFeature:\nHTTP return() method.\n
\nBugfix:\nmiscellaneous bugs have been fixed in the core and\ninteractive shell.\n
\n\n
\nRelease Date:\n20 November 2017\n
\n
\nFeature:\nError,\nEvalError,\nInternalError,\nRangeError,\nReferenceError,\nSyntaxError,\nTypeError,\nURIError objects.\n
\nFeature:\noctal literals support.\n
\n\nFeature:\nNode.js style\nFile system access methods:\nfs.readFile(),\nfs.readFileSync(),\nfs.appendFile(),\nfs.appendFileSync(),\nfs.writeFile(),\nfs.writeFileSync().\n
\nFeature:\nnginx modules print backtrace on exception.\n
\n\nBugfix:\nmiscellaneous bugs have been fixed.\n
\n\n
\nRelease Date:\n09 October 2017\n
\n
\nFeature:\nJSON object.\n
\n\nFeature:\nobject level completions in interactive shell.\n
\n\nFeature:\nvarious configure improvements.\n
\n\nBugfix:\nmiscellaneous bugs have been fixed in the core and\ninteractive shell.\n
\n\n
\nRelease Date:\n31 August 2017\n
\n
\nFeature:\nconsole.log() and\nconsole.help()\nmethods in interactive shell.\n
\nFeature:\ninteractive shell prints backtrace on exception.\n
\n\nFeature:\ninteractive shell by default\nif libedit is available.\n
\nBugfix:\nprocessing of large files from\nstdin in command line mode.\n
\nBugfix:\nimproved editline detection.\n
\n
\nRelease Date:\n08 August 2017\n
\n
\nFeature:\nInteractive shell.\n
\n\nBugfix:\nin Object.isSealed().\n
\n
\nRelease Date:\n27 June 2017\n
\n
\nFeature:\nObject.keys(),\nObject.prototype.hasOwnProperty()\nmethods.\n
\nFeature:\nObject.defineProperty(),\nObject.defineProperties(),\nObject.getOwnPropertyDescriptor()\nmethods.\n
\nFeature:\nObject.getPrototypeOf(),\nObject.prototype.isPrototypeOf()\nmethods.\n
\nFeature:\nObject.preventExtensions(),\nObject.isExtensible(),\nObject.freeze(),\nObject.isFrozen(),\nObject.seal(),\nObject.isSealed()\nmethods.\n
\nFeature:\nscientific notation (3.35e10) literals support.\n
\nFeature:\nhexadecimal (0x1123) literals support.\n
\nBugfix:\nprocessing of large array indexes.\n
\n\nBugfix:\nin parseInt() and\nDate.parse().\n
\n
\nRelease Date:\n04 April 2017\n
\n
\nFeature:\nnested functions and function closures.\n
\n\nFeature:\nArray.of(),\nArray.prototype.fill(),\nArray.prototype.find(),\nArray.prototype.findIndex()\nmethods.\n
\nBugfix:\nmiscellaneous bugs and segmentation faults have been fixed.\n
\n\n
\nRelease Date:\n01 February 2017\n
\n
\nBugfix:\nglobal variables were not initialized when njs was used\nin nginx.\n
\n\n
\nRelease Date:\n24 January 2017\n
\n
\nChange:\nthe strict mode is enforced,\nvariables must be explicitly declared.\n
\nFeature:\nfor and\nfor-in loops support variable declaration.\n
\nBugfix:\nglobal and function scopes have been fixed.\n
\n\nBugfix:\nnow for-in loop does not discard the last value\nof property variable.\n
\nBugfix:\nmiscellaneous bugs and segmentation faults have been fixed.\n
\n\n
\nRelease Date:\n27 December 2016\n
\n
\nChange:\nthe js_include directive\nhas been disabled at server and location levels.\n
\n\nFeature:\nexponentiation operators.\n
\n\nBugfix:\nmiscellaneous bugs and segmentation faults have been fixed.\n
\n\n
\nRelease Date:\n13 December 2016\n
\n
\nChange:\nthe js_set directive\nhas been disabled at server and location levels.\n
\n\nFeature:\nES6 Math methods.\n
\nBugfix:\nmiscellaneous bugs and segmentation faults have been fixed.\n
\n\n
\nnjs scripts development and debugging can be performed\nfrom the command-line.\nThe command-line utility is available after the installation of\nthe Linux package\nor after building from the\nsources.\nCompared to njs running inside nginx,\nnginx objects\n(HTTP and\nStream)\nare not available in the utility.\n
\n$ echo \"2**3\" | njs -q\n8\n\n$ njs\n>> globalThis\nglobal {\n njs: njs {\n version: '0.3.9'\n },\n global: [Circular],\n process: process {\n argv: [\n '/usr/bin/njs'\n ],\n env: {\n PATH: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',\n HOSTNAME: 'f777c149d4f8',\n TERM: 'xterm',\n NGINX_VERSION: '1.17.9',\n NJS_VERSION: '0.3.9',\n PKG_RELEASE: '1~buster',\n HOME: '/root'\n }\n },\n console: {\n log: [Function: native],\n dump: [Function: native],\n time: [Function: native],\n timeEnd: [Function: native]\n },\n print: [Function: native]\n}\n>>\n\n
\nnjs is created in compliance with\nECMAScript 5.1\n(strict mode) with some\nECMAScript 6\nand later extensions.\nThe compliance is still evolving.\n
\nDefinitions of njs specific properties and methods\nnot compliant with ECMAScript can be found in\nReference.\nDefinitions of njs properties and methods\ncompliant with ECMAScript can be found in\nECMAScript\nspecification.\n
\n
||=, &&=,\n??=\n(0.9.6)\nbreak,\ncatch,\ncontinue,\ndo while,\nelse,\nfinally,\nfor,\nfor in,\nif,\nreturn,\nswitch,\nthrow,\ntry,\nvar,\nwhile,\nlabeled statements (0.2.8)\nlet (0.6.0),\nconst (0.6.0),\nasync (0.7.0),\nawait (0.7.0)\nMath properties:\nE,\nLN10,\nLN2,\nLOG10E,\nLOG2E,\nPI,\nSQRT1_2,\nSQRT2\nMath methods:\nabs,\nacos,\nacosh,\nasin,\nasinh,\natan,\natan2,\natanh,\ncbrt,\nceil,\nclz32,\ncos,\ncosh,\nexp,\nexpm1,\nfloor,\nfround,\nhypot,\nimul,\nlog,\nlog10,\nlog1p,\nlog2,\nmax,\nmin,\npow,\nrandom,\nround,\nsign,\nsin,\nsinh,\nsqrt,\ntan,\ntanh,\ntrunc\nNumber properties:\nEPSILON,\nMAX_SAFE_INTEGER,\nMAX_VALUE,\nMIN_SAFE_INTEGER,\nMIN_VALUE,\nNEGATIVE_INFINITY,\nNaN,\nPOSITIVE_INFINITY\nNumber methods:\nisFinite,\nisInteger,\nisNaN,\nisSafeInteger,\nparseFloat,\nparseInt\nNumber prototype methods:\n\n\nString methods:\nfromCharCode\nfromCodePoint\nString prototype methods:\ncharAt,\nconcat,\nindexOf,\nlastIndexOf,\nmatch,\nreplace,\nsearch,\nslice,\nsplit,\nsubstr,\nsubstring,\ntoLowerCase,\ntrim,\ntoUpperCase\ncodePointAt,\nendsWith,\nincludes,\nrepeat,\nstartsWith\npadEnd,\npadStart\ntrimEnd\n(0.3.4),\ntrimStart\n(0.3.4)\nreplaceAll\n(0.7.10)\nObject methods:\ncreate (support without properties list),\ndefineProperties (accessor descriptors support\nsince 0.3.3),\ndefineProperty (accessor descriptors support\nsince 0.3.3),\nfreeze,\ngetOwnPropertyDescriptor,\ngetOwnPropertyDescriptors\n(0.3.1),\ngetOwnPropertyNames\n(0.3.1),\ngetPrototypeOf,\nisExtensible,\nisFrozen,\nisSealed,\nkeys,\npreventExtensions,\nseal\nassign\n(0.3.7)\nentries\n(0.2.7),\nvalues\n(0.2.7)\nObject prototype methods:\n\nArray methods:\nisArray\nof\nfrom\n(0.8.0),\nArray prototype methods:\nconcat,\nevery,\nfilter,\nforEach,\nindexOf,\njoin,\nlastIndexOf,\nmap,\npop,\npush,\nreduce,\nreduceRight,\nreverse,\nshift,\nslice,\nsome,\nsort,\nsplice,\nunshift\ncopyWithin\n(0.3.7),\nfill,\nfind,\nfindIndex\nincludes\ntoReversed\n(0.8.0),\ntoSorted\n(0.8.0),\ntoSpliced\n(0.8.0)\nArrayBuffer methods\n(0.3.8):\nisView\nArrayBuffer prototype methods\n(0.3.8):\nslice\nTyped-array constructors\n(0.3.8):\nInt8Array,\nUint8Array,\nUint8ClampedArray,\nInt16Array,\nUint16Array,\nInt32Array,\nUint32Array,\nFloat32Array,\nFloat64Array\nTyped-array prototype methods\n(0.3.8):\ncopyWithin,\nevery\n(0.4.4),\nfill,\nfilter\n(0.4.4),\nfind\n(0.4.4),\nfindIndex\n(0.4.4),\nforEach\n(0.4.4),\nincludes\n(0.4.4),\nindexOf\n(0.4.4),\njoin,\nlastIndexOf\n(0.4.4),\nmap\n(0.4.4),\nreduce\n(0.4.4),\nreduceRight\n(0.4.4),\nreverse\n(0.4.4),\nset,\nslice,\nsome\n(0.4.4),\nsort\n(0.4.2),\nsubarray,\ntoString\ntoReversed\n(0.8.0)\ntoSorted\n(0.8.0)\nBuffer methods\n(0.4.4):\nalloc,\nallocUnsafe,\nbyteLength,\ncompare,\nconcat,\nfrom,\nisBuffer,\nisEncoding\nBuffer prototype methods:\n(0.4.4):\ncompare,\ncopy,\nequals,\nfill,\nincludes,\nindexOf,\nlastIndexOf,\nreadIntBE,\nreadInt8,\nreadInt16BE,\nreadInt32BE,\nreadIntLE,\nreadInt8,\nreadInt16LE,\nreadInt32LE,\nreadUIntBE,\nreadUInt8,\nreadUInt16BE,\nreadUInt32BE,\nreadUIntLE,\nreadUInt8,\nreadUInt16LE,\nreadUInt32LE,\nreadDoubleBE,\nreadDoubleLE,\nreadFloatBE,\nreadFloatLE,\nsubarray,\nslice,\nswap16,\nswap32,\nswap64,\ntoJSON,\ntoString,\nwrite,\nwriteIntBE,\nwriteInt8,\nwriteInt16BE,\nwriteInt32BE,\nwriteIntLE,\nwriteInt8,\nwriteInt16LE,\nwriteInt32LE,\nwriteUIntBE,\nwriteUInt8,\nwriteUInt16BE,\nwriteUInt32BE,\nwriteUIntLE,\nwriteUInt8,\nwriteUInt16LE,\nwriteUInt32LE,\nwriteDoubleBE,\nwriteDoubleLE,\nwriteFloatBE,\nwriteFloatLE\nPromise methods\n(0.3.8):\n\n\nPromise prototype methods\n(0.3.8):\ncatch,\nfinally,\nthen\nFunction prototype methods:\napply,\nbind,\ncall\nRegExp prototype accessor properties:\n\n\nRegExp prototype methods:\n\n\nRegExp instance properties:\nlastIndex\nRegExp\nES9 named capture groups (0.3.2)\nDataView prototype methods\n(0.4.4):\ngetFloat32,\ngetFloat64,\ngetInt16,\ngetInt32,\ngetInt8,\ngetUint16,\ngetUint32,\ngetUint8,\nsetFloat32,\nsetFloat64,\nsetInt16,\nsetInt32,\nsetInt8,\nsetUint16,\nsetUint32,\nsetUint8\nDate methods:\nnow,\nparse,\nUTC\nDate prototype methods:\ngetDate,\ngetDay,\ngetFullYear,\ngetHours,\ngetMilliseconds,\ngetMinutes,\ngetMonth,\ngetSeconds,\ngetTime,\ngetTimezoneOffset,\ngetUTCDate,\ngetUTCDay,\ngetUTCFullYear,\ngetUTCHours,\ngetUTCMilliseconds,\ngetUTCMinutes,\ngetUTCMonth,\ngetUTCSeconds,\ntoDateString,\ntoISOString,\ntoLocaleDateString,\ntoLocaleString,\ntoLocaleTimeString,\ntoTimeString,\ntoUTCString,\nsetDate,\nsetFullYear,\nsetHours,\nsetMinutes,\nsetMilliseconds,\nsetMonth,\nsetSeconds,\nsetTime,\nsetUTCDate,\nsetUTCFullYear,\nsetUTCHours,\nsetUTCMilliseconds,\nsetUTCMinutes,\nsetUTCMonth,\nsetUTCSeconds\nJSON methods:\nparse,\nstringify\nSymbol methods\n(0.7.6):\nfor,\nkeyfor\narguments object\n(0.2.5)\ndecodeURI,\ndecodeURIComponent,\nencodeURI,\nencodeURIComponent,\nisFinite,\nisNaN,\nparseFloat,\nparseInt\natob,\nbtoa\nError objects:\nError,\nEvalError,\nInternalError,\nRangeError,\nReferenceError,\nSyntaxError,\nTypeError,\nURIError\nclearTimeout\nand\nsetTimeout\nfunctions\n(0.2.0)\nFile system methods:\nfs.accessSync\n(0.3.9),\nfs.appendFileSync,\nfs.closeSync,\nfs.existsSync\n(0.8.2),\nfs.FileHandle\n(0.7.7),\nfs.fstatSync\n(0.7.7),\nfs.lstatSync\n(0.7.1),\nfs.mkdirSync\n(0.4.2),\nfs.openSync\n(0.7.7),\nfs.promises.open\n(0.7.7),\nfs.readdirSync\n(0.4.2),\nfs.readFileSync,\nfs.readSync\n(0.7.7),\nfs.realpathSync\n(0.3.9),\nfs.renameSync\n(0.3.4),\nfs.rmdirSync\n(0.4.2),\nfs.symlinkSync\n(0.3.9),\nfs.unlinkSync\n(0.3.9),\nfs.writeFileSync\nfs.writeSync\n(0.7.7)\nfs.promises API (0.3.9),\nasynchronous version of file system methods.\nCrypto methods\n(0.2.0):\ncrypto.createHash,\ncrypto.createHmac\nQuery String\nmethods\n(0.4.3):\nquerystring.decode,\nquerystring.encode,\nquerystring.escape,\nquerystring.parse,\nquerystring.stringify,\nquerystring.unescape\nTextDecoder\nmethods\n(0.4.3):\nencoding,\nfatal,\nignoreBOM,\ndecode\nTextEncoder\nmethods\n(0.4.3):\nencode,\nencodeInto\nXML\nmethods\n(0.7.10):\nparse,\nxml.c14n,\nxml.exclusiveC14n\nzlib\nmethods\n(0.7.12):\ndeflateRawSync,\ndeflateSync,\ninflateRawSync\ninflateSync\nexport and\ndefault import\nstatements\n(0.3.0)\nconsole\n(0.8.2):\nerror,\ninfo,\nlog,\ntime,\ntimeEnd,\nwarn\ncrypto\n(0.7.0):\ngetRandomValues,\nrandomUUID\n(0.9.7),\nsubtle.encrypt,\nsubtle.decrypt,\nsubtle.deriveBits,\nsubtle.deriveKey,\nsubtle.digest\nsubtle.exportKey\n(0.7.10),\nsubtle.generateKey\n(0.7.10),\nsubtle.importKey,\nsubtle.sign,\nsubtle.verify,\nsubtle.wrapKey\n(0.9.7),\nsubtle.unwrapKey\n(0.9.7)\nglobalThis alias\n(0.3.8),\nnjs:\nversion,\nversion_number\n(0.7.4),\ndump,\nmemoryStats\n(0.7.8),\non\n(0.5.2)\nprocess:\nargv,\nenv,\npid,\nppid\nHTTP Request:\nr.done\n(0.5.2),\nr.error,\nr.finish,\nr.internalRedirect,\nr.log,\nr.return\n(0.5.0),\nr.send\n(0.5.0),\nr.sendBuffer\n(0.5.2),\nr.sendHeader,\nr.setReturnValue\n(0.7.0),\nr.subrequest,\nr.warn\nStream Session:\ns.allow\n(0.2.4),\ns.decline\n(0.2.4),\ns.deny\n(0.2.4),\ns.done\n(0.2.4),\ns.error,\ns.log,\ns.off\n(0.2.4),\ns.on\n(0.2.4),\ns.send\n(0.2.4),\ns.sendDownstream\n(0.7.8),\ns.sendUpstream\n(0.7.8),\ns.setReturnValue\n(0.7.0),\ns.warn\nHeaders\n(0.5.1):\nappend,\ndelete,\nget,\ngetAll,\nforEach,\nhas,\nset\nRequest\n(0.7.10):\narrayBuffer,\nheaders,\njson,\ntext\nResponse\n(0.5.1):\narrayBuffer,\nheaders,\njson,\ntext\nngx\n(0.5.0):\nfetch\n(0.5.1),\nlog\nngx.shared\n(0.8.0):\nadd,\nclear,\ndelete,\nfreeSpace,\nget,\nhas,\nincr,\nitems,\nkeys,\npop,\nreplace,\nset,\nsize,\nttl\n(0.9.7)\nHTTP Request:\nr.args,\nr.headersIn,\nr.headersOut,\nr.httpVersion,\nr.internal,\nr.jsVarNames\n(0.9.9),\nr.method,\nr.parent,\nr.readRequestArrayBuffer\n(0.9.9),\nr.readRequestForm\n(0.9.9),\nr.readRequestJSON\n(0.9.9),\nr.readRequestText\n(0.9.9),\nr.rawHeadersIn\n(0.4.1),\nr.rawHeadersOut\n(0.4.1),\nr.rawVariables\n(0.5.0),\nr.remoteAddress,\nr.requestBuffer\n(0.5.0),\nr.requestText,\nr.responseBuffer\n(0.5.0),\nr.responseText\n(0.5.0),\nr.status,\nr.uri,\nr.variables\n(0.2.8)\nStream Session:\ns.jsVarNames\n(0.9.9),\ns.remoteAddress,\ns.rawVariables\n(0.5.0),\ns.status\n(0.5.2),\ns.variables\n(0.2.8)\nPeriodic Session\n(0.8.1):\nPeriodicSession.rawVariables,\nPeriodicSession.variables\nRequest\n(0.7.10):\nbodyUsed,\ncache,\ncredentials,\nmethod,\nmode,\nurl\nResponse\n(0.5.1):\nbodyUsed,\nok,\nredirected,\nstatus,\nstatusText,\ntype,\nurl\nngx\n(0.5.0):\nbuild\n(0.8.0),\nconf_file_path\n(0.8.0),\nconf_prefix\n(0.7.8),\nerror_log_path\n(0.8.0),\nprefix\n(0.8.0),\nversion\n(0.8.0),\nversion_number\n(0.8.0),\nworker_id\n(0.8.0)\nngx.shared\n(0.8.0):\ncapacity,\nname,\ntype\n\n
\nStarting from version 0.8.6,\nmultiple JavaScript engines are supported.\nTo specify a particular engine, use the js_engine directive\navailable for both the\nhttp\nand\nstream.\nBy default, the njs engine is used.\n
\nnjs is an embeddable JavaScript engine\ndeveloped as a part of the njs module.\nSee the Сompatibility section for details.\n
\nQuickJS is a lightweight,\nembeddable JavaScript engine that supports\nthe ES2023 specification,\nincluding features as modules, asynchronous generators, proxies and BigInt.\n
\nSince version 0.8.6,\na drop-in replacement for\nnjs/nginx objects\nhas been introduced\nto ensure compatibility with the njs engine, with the following exceptions:\n\n
njs.dump(),\nconsole.dump().\nrequire(),\nuse the import statement instead.\njs_preload_object directive for\nhttp\nand\nstream.\n\n\n
\nnjs built-in modules status:\n\n
buffer:\nsince 0.8.6.\ncrypto:\nsince 0.8.10.\nfs:\nsince 0.8.9.\nquerystring:\nsince 0.8.10.\nWebCrypto:\nsince 0.8.10.\nxml:\nsince 0.8.10.\nzlib:\nsince 0.8.5.\n\n\n
\nnjs built-in objects status:\n\n
process:\nsince 0.8.8.\nTextDecoder:\nsince 0.8.10.\nTextEncoder:\nsince 0.8.10.\n\n\n
\nnginx built-in objects status:\n\n
ngx.fetch:\nsince 0.9.1.\nshared dictionary:\nsince 0.8.8.\n\n\n
\nnjs is an nginx module that extends the server's functionality through\nJavaScript scripting, enabling the creation of custom\nserver-side logic and more.\n
\n
\n
\n
\n
\n
\n
\n
\nSee examples\nfor more njs use cases.\n
\nTo use njs in nginx:\n
\ninstall njs scripting language\n
\n\ncreate an njs script file, for example, http.js.\nSee Reference\nfor the list of njs properties and methods.\n
\nfunction hello(r) {\n r.return(200, \"Hello world!\");\n}\n\nexport default {hello};\n\n
\n\nin the nginx.conf file, enable\nngx_http_js_module module\nand specify the\njs_import\ndirective\nwith the http.js script file:\n
\nload_module modules/ngx_http_js_module.so;\n\nevents {}\n\nhttp {\n js_import http.js;\n\n server {\n listen 8000;\n\n location / {\n js_content http.hello;\n }\n }\n}\n\n
\n\nThere is also a standalone command line utility\nthat can be used independently of nginx for njs development and debugging.\n
\n
\n
| Installing as a Linux package Building from the sources Adding QuickJS engine support Building njs command-line utility |
\nFor Linux, njs modules\npackages can be used:\n
nginx-module-njs — njs\ndynamic modules\nnginx-module-njs-dbg — debug symbols for the\nnginx-module-njs package\n\n
\nAfter package installation, njs dynamic modules need to be loaded with the\nload_module\ndirective:\n
\nload_module modules/ngx_http_js_module.so;\n
\nor\n
\nload_module modules/ngx_stream_js_module.so;\n
\n
\nThe repository\nwith njs sources can be cloned with the following command\n(requires Git client):\n
\ngit clone https://github.com/nginx/njs\n
\nThen the modules should be compiled from\nnginx root directory using the\n--add-module configuration parameter:\n
\n./configure --add-module=path-to-njs/nginx\n
\nThe modules can also be built as\ndynamic:\n
\n./configure --add-dynamic-module=path-to-njs/nginx\n
\n
\nMake sure you have built the QuickJS library:\n
\ngit clone https://github.com/bellard/quickjs\ncd quickjs\nCFLAGS='-fPIC' make libquickjs.a\n
\nAt the module compilation step, also\nspecify the include (-I) and library (-L)\npaths with the\n--with-cc-opt= and\n--with-ld-opt= configuration parameters:\n
\n./configure --add-module=path-to-njs/nginx \\\n --with-cc-opt=\"-Ipath-to-quickjs\" \\\n --with-ld-opt=\"-Lpath-to-quickjs\"\n
\n
\nTo build only the njs command-line utility, run\n./configure and make njs commands\nfrom njs root directory.\nAfter building, the utility is available as ./build/njs.\n
| Overview When to use native modules Loading native modules in NGINX Building native modules Additional resources |
\nNative modules allow loading C-based shared libraries (.so files)\ninto NGINX JavaScript for performance-critical operations\nor system-level integrations.\nThis feature is available only with the\nQuickJS engine\nand is not supported by the njs native engine.\nNative module support has been available\nsince 0.9.5.\n
\nNative modules are useful in the following scenarios:\n\n
\n
\nNative modules should be used for low-level primitives\nrather than for complex business logic,\nfor example, for cryptographic operations (hashing, encryption),\ndata compression/decompression, binary protocol parsing,\nhigh-performance string operations, or mathematical computations.\nComplex application logic should remain in JavaScript\nwhere it's easier to maintain, debug, and modify.\n
\nLimitations:\n\n
\n
\nNative modules are loaded using these directives\nspecified in the main context:\n\n
\n
\nExample configuration:\n
\njs_load_http_native_module /path/to/mylib.so;\njs_load_http_native_module /path/to/other.so as myalias;\n\nhttp {\n js_import main.js;\n\n server {\n listen 8000;\n location / {\n js_content main.handler;\n }\n }\n}\n\n
\nOnce loaded, the module can be imported in JavaScript code:\n
\n// Import by filename\nimport * as mylib from 'mylib.so';\n\n// Import by alias\nimport * as myalias from 'myalias';\n\nfunction handler(r) {\n let result = mylib.add(5, 10);\n r.return(200, `Result: ${result}\\n`);\n}\n\nexport default { handler };\n\n
\nNative modules must implement the js_init_module\nfunction as the entry point.\nThis function is called by QuickJS when the module is loaded.\n
\nA complete example of a simple native module\nthat exports two functions:\n
\n#include <quickjs.h>\n\n#define countof(x) (sizeof(x) / sizeof((x)[0]))\n\n/* Add two numbers */\nstatic JSValue\njs_add(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)\n{\n int a, b;\n\n if (argc < 2) {\n return JS_ThrowTypeError(ctx, \"expected 2 arguments\");\n }\n\n if (JS_ToInt32(ctx, &a, argv[0]) < 0) {\n return JS_EXCEPTION;\n }\n\n if (JS_ToInt32(ctx, &b, argv[1]) < 0) {\n return JS_EXCEPTION;\n }\n\n return JS_NewInt32(ctx, a + b);\n}\n\n/* Reverse a string */\nstatic JSValue\njs_reverse_string(JSContext *ctx, JSValueConst this_val, int argc,\n JSValueConst *argv)\n{\n char *reversed;\n size_t i, len;\n JSValue result;\n const char *str;\n\n if (argc < 1) {\n return JS_ThrowTypeError(ctx, \"expected 1 argument\");\n }\n\n str = JS_ToCStringLen(ctx, &len, argv[0]);\n if (!str) {\n return JS_EXCEPTION;\n }\n\n reversed = js_malloc(ctx, len + 1);\n if (!reversed) {\n JS_FreeCString(ctx, str);\n return JS_EXCEPTION;\n }\n\n for (i = 0; i < len; i++) {\n reversed[i] = str[len - 1 - i];\n }\n reversed[len] = '\\0';\n\n result = JS_NewString(ctx, reversed);\n\n js_free(ctx, reversed);\n JS_FreeCString(ctx, str);\n\n return result;\n}\n\n/* Module function list */\nstatic const JSCFunctionListEntry js_module_funcs[] = {\n JS_CFUNC_DEF(\"add\", 2, js_add),\n JS_CFUNC_DEF(\"reverseString\", 1, js_reverse_string),\n};\n\n/* Module initialization */\nstatic int\njs_module_init(JSContext *ctx, JSModuleDef *m)\n{\n return JS_SetModuleExportList(ctx, m, js_module_funcs,\n countof(js_module_funcs));\n}\n\n/* Required entry point */\nJSModuleDef *\njs_init_module(JSContext *ctx, const char *module_name)\n{\n JSModuleDef *m;\n\n m = JS_NewCModule(ctx, module_name, js_module_init);\n if (!m) {\n return NULL;\n }\n\n JS_AddModuleExportList(ctx, m, js_module_funcs,\n countof(js_module_funcs));\n\n return m;\n}\n\n
\nTo compile the native module:\n
\ngcc -fPIC -shared -I/path/to/quickjs -o mymodule.so mymodule.c\n
\nwhere /path/to/quickjs is the directory\ncontaining the QuickJS header files.\n
\n
\nFor proper memory tracking, always use QuickJS memory allocation functions\n(js_malloc,js_free)\ninstead of standard library functions\n(malloc,free).\n
\n
\nFor more information about the QuickJS C API:\n\n
quickjs.h)\ncontains comprehensive API documentation\n\n
| Environment Protobufjs DNS-packet |
\nOften, a developer wants to use 3rd-party code,\nusually available as a library of some kind.\nIn the JavaScript world, the concept of a module is relatively new,\nso there was no standard until recently.\nMany platforms (browsers) still don't support modules, which makes code\nreuse harder.\nThis article describes ways to reuse\nNode.js code in njs.\n
\nExamples in this article use features that appeared in\nnjs\n0.3.8\n
\nThere is a number of issues\nthat may arise when 3rd-party code is added to njs:\n\n
\n
\nThe good news is that such problems are not something new or specific to njs.\nJavaScript developers face them daily\nwhen trying to support multiple disparate platforms\nwith very different properties.\nThere are instruments designed to resolve the above-mentioned issues.\n\n
\nThis can be solved by merging all the interdependent code into a single file.\nTools like\nbrowserify or\nwebpack\naccept an entire project and produce a single file containing\nyour code and all the dependencies.\n
\n\nYou can use multiple libraries that implement such APIs\nin a platform-agnostic manner (at the expense of performance, though).\nParticular features can also be implemented using the\npolyfill approach.\n
\n\nSuch code can be transpiled:\nthis means performing a number of transformations\nthat rewrite newer language features in accordance with an older standard.\nFor example, babel project\ncan be used to this purpose.\n
\n\n
\nIn this guide, we will use two relatively large npm-hosted libraries:\n\n
\n
\n
\nThis document mostly employs a generic approach\nand avoids specific best practice advices concerning Node.js\nand JavaScript.\nMake sure to consult the corresponding package's manual\nbefore following the steps suggested here.\n
\nFirst (assuming Node.js is installed and operational), let's create an\nempty project and install some dependencies;\nthe commands below assume we are in the working directory:\n
\n$ mkdir my_project && cd my_project\n$ npx license choose_your_license_here > LICENSE\n$ npx gitignore node\n\n$ cat > package.json <<EOF\n{\n \"name\": \"foobar\",\n \"version\": \"0.0.1\",\n \"description\": \"\",\n \"main\": \"index.js\",\n \"keywords\": [],\n \"author\": \"somename <some.email@example.com> (https://example.com)\",\n \"license\": \"some_license_here\",\n \"private\": true,\n \"scripts\": {\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n }\n}\nEOF\n$ npm init -y\n$ npm install browserify\n\n
\nThe library provides a parser\nfor the .proto interface definitions\nand a code generator for message parsing and generation.\n
\nIn this example, we will use the\nhelloworld.proto\nfile\nfrom the gRPC examples.\nOur goal is to create two messages:\nHelloRequest and\nHelloResponse.\nWe will use the\nstatic\nmode of protobufjs instead of dynamically generating classes, because\nnjs doesn't support adding new functions dynamically\ndue to security considerations.\n
\nNext, the library is installed and\nthe JavaScript code implementing message marshalling\nis generated from the protocol definition:\n
\n$ npm install protobufjs\n$ npx pbjs -t static-module helloworld.proto > static.js\n
\n
\nThus, the static.js file becomes our new dependency,\nstoring all the code we need to implement message processing.\nThe set_buffer() function contains code that uses the\nlibrary to create a buffer with the serialized\nHelloRequest message.\nThe code resides in the code.js file:\n
\nvar pb = require('./static.js');\n\n// Example usage of protobuf library: prepare a buffer to send\nfunction set_buffer(pb)\n{\n // set fields of gRPC payload\n var payload = { name: \"TestString\" };\n\n // create an object\n var message = pb.helloworld.HelloRequest.create(payload);\n\n // serialize object to buffer\n var buffer = pb.helloworld.HelloRequest.encode(message).finish();\n\n var n = buffer.length;\n\n var frame = new Uint8Array(5 + buffer.length);\n\n frame[0] = 0; // 'compressed' flag\n frame[1] = (n & 0xFF000000) >>> 24; // length: uint32 in network byte order\n frame[2] = (n & 0x00FF0000) >>> 16;\n frame[3] = (n & 0x0000FF00) >>> 8;\n frame[4] = (n & 0x000000FF) >>> 0;\n\n frame.set(buffer, 5);\n\n return frame;\n}\n\nvar frame = set_buffer(pb);\n\n
\nTo ensure it works, we execute the code using node:\n
\n$ node ./code.js\nUint8Array [\n 0, 0, 0, 0, 12, 10,\n 10, 84, 101, 115, 116, 83,\n 116, 114, 105, 110, 103\n]\n
\nYou can see that this got us a properly encoded gRPC frame.\nNow let's run it with njs:\n
\n$ njs ./code.js\nThrown:\nError: Cannot find module \"./static.js\"\n at require (native)\n at main (native)\n
\n
\nModules are not supported, so we've received an exception.\nTo overcome this issue, let's use browserify\nor other similar tool.\n
\nAn attempt to process our existing code.js file will result\nin a bunch of JS code that is supposed to run in a browser,\ni.e. immediately upon loading.\nThis isn't something we actually want.\nInstead, we want to have an exported function that\ncan be referenced from the nginx configuration.\nThis requires some wrapper code.\n
\nIn this guide, we use\nnjs cli in all examples for the sake of simplicity.\nIn real life, you will be using nginx njs module to run your code.\n
\n
\nThe load.js file contains the library-loading code that\nstores its handle in the global namespace:\n
\nglobal.hello = require('./static.js');\n \nThis code will be replaced with merged content.\nOur code will be using the \"global.hello\" handle to access\nthe library.\n
\nNext, we process it with browserify\nto get all dependencies into a single file:\n
\n$ npx browserify load.js -o bundle.js -d\n
\nThe result is a huge file that contains all our dependencies:\n
\n(function(){function......\n...\n...\n},{\"protobufjs/minimal\":9}]},{},[1])\n//# sourceMappingURL..............\n \nTo get final \"njs_bundle.js\" file we concatenate\n\"bundle.js\" and the following code:\n
\n// Example usage of protobuf library: prepare a buffer to send\nfunction set_buffer(pb)\n{\n // set fields of gRPC payload\n var payload = { name: \"TestString\" };\n\n // create an object\n var message = pb.helloworld.HelloRequest.create(payload);\n\n // serialize object to buffer\n var buffer = pb.helloworld.HelloRequest.encode(message).finish();\n\n var n = buffer.length;\n\n var frame = new Uint8Array(5 + buffer.length);\n\n frame[0] = 0; // 'compressed' flag\n frame[1] = (n & 0xFF000000) >>> 24; // length: uint32 in network byte order\n frame[2] = (n & 0x00FF0000) >>> 16;\n frame[3] = (n & 0x0000FF00) >>> 8;\n frame[4] = (n & 0x000000FF) >>> 0;\n\n frame.set(buffer, 5);\n\n return frame;\n}\n\n// functions to be called from outside\nfunction setbuf()\n{\n return set_buffer(global.hello);\n}\n\n// call the code\nvar frame = setbuf();\nconsole.log(frame);\n\nLet's run the file using node to make sure things still work:\n
\n$ node ./njs_bundle.js\nUint8Array [\n 0, 0, 0, 0, 12, 10,\n 10, 84, 101, 115, 116, 83,\n 116, 114, 105, 110, 103\n]\n
\nNow let's proceed further with njs:\n
\n$ njs ./njs_bundle.js\nUint8Array [0,0,0,0,12,10,10,84,101,115,116,83,116,114,105,110,103]\n
\nThe last thing will be to use njs-specific API to convert\narray into byte string, so it could be usable by nginx module.\nWe can add the following snippet before the line\nreturn frame; }:\n
\nif (global.njs) {\n return String.bytesFrom(frame)\n}\n\nFinally, we got it working:\n
\n$ njs ./njs_bundle.js |hexdump -C\n00000000 00 00 00 00 0c 0a 0a 54 65 73 74 53 74 72 69 6e |.......TestStrin|\n00000010 67 0a |g.|\n00000012\n
\nThis is the intended result.\nResponse parsing can be implemented similarly:\n
\nfunction parse_msg(pb, msg)\n{\n // convert byte string into integer array\n var bytes = msg.split('').map(v=>v.charCodeAt(0));\n\n if (bytes.length < 5) {\n throw 'message too short';\n }\n\n // first 5 bytes is gRPC frame (compression + length)\n var head = bytes.splice(0, 5);\n\n // ensure we have proper message length\n var len = (head[1] << 24)\n + (head[2] << 16)\n + (head[3] << 8)\n + head[4];\n\n if (len != bytes.length) {\n throw 'header length mismatch';\n }\n\n // invoke protobufjs to decode message\n var response = pb.helloworld.HelloReply.decode(bytes);\n\n console.log('Reply is:' + response.message);\n}\n\n
\nThis example uses a library for generation and parsing of DNS packets.\nThis a case worth considering because the library and its dependencies\nuse modern language constructions not yet supported by njs.\nIn turn, this requires from us an extra step: transpiling the source code.\n
\nAdditional node packages are needed:\n
\n$ npm install @babel/core @babel/cli @babel/preset-env babel-loader\n$ npm install webpack webpack-cli\n$ npm install buffer\n$ npm install dns-packet\n
\nThe configuration file, webpack.config.js:\n
\nconst path = require('path');\n\nmodule.exports = {\n entry: './load.js',\n mode: 'production',\n output: {\n filename: 'wp_out.js',\n path: path.resolve(__dirname, 'dist'),\n },\n optimization: {\n minimize: false\n },\n node: {\n global: true,\n },\n module : {\n rules: [{\n test: /\\.m?js$$/,\n exclude: /(bower_components)/,\n use: {\n loader: 'babel-loader',\n options: {\n presets: ['@babel/preset-env']\n }\n }\n }]\n }\n};\n \nNote we are using \"production\" mode.\nIn this mode webpack does not use \"eval\" construction\nnot supported by njs.\nThe referenced load.js file is our entry point:\n
\nglobal.dns = require('dns-packet')\nglobal.Buffer = require('buffer/').Buffer\n\nWe start the same way, by producing a single file for the libraries:\n
\n$ npx browserify load.js -o bundle.js -d\n
\nNext, we process the file with webpack, which itself invokes babel:\n
\n$ npx webpack --config webpack.config.js\n
\nThis command produces the dist/wp_out.js file, which is a\ntranspiled version of bundle.js.\nWe need to concatenate it with code.js\nthat stores our code:\n
\nfunction set_buffer(dnsPacket)\n{\n // create DNS packet bytes\n var buf = dnsPacket.encode({\n type: 'query',\n id: 1,\n flags: dnsPacket.RECURSION_DESIRED,\n questions: [{\n type: 'A',\n name: 'google.com'\n }]\n })\n\n return buf;\n}\n \nNote that in this example generated code is not wrapped into function and we\ndo not need to call it explicitly.\nThe result is in the \"dist\" directory:\n
\n$ cat dist/wp_out.js code.js > njs_dns_bundle.js\n
\nLet's call our code at the end of a file:\n
\nvar b = set_buffer(global.dns);\nconsole.log(b);\n
\nAnd execute it using node:\n
\n$ node ./njs_dns_bundle_final.js\nBuffer [Uint8Array] [\n 0, 1, 1, 0, 0, 1, 0, 0,\n 0, 0, 0, 0, 6, 103, 111, 111,\n 103, 108, 101, 3, 99, 111, 109, 0,\n 0, 1, 0, 1\n]\n
\nMake sure this works as expected, and then run it with njs:\n
\n$ njs ./njs_dns_bundle_final.js\nUint8Array [0,1,1,0,0,1,0,0,0,0,0,0,6,103,111,111,103,108,101,3,99,111,109,0,0,1,0,1]\n
\n\n
\nThe response can be parsed as follows:\n
\nfunction parse_response(buf)\n{\n var bytes = buf.split('').map(v=>v.charCodeAt(0));\n\n var b = global.Buffer.from(bytes);\n\n var packet = dnsPacket.decode(b);\n\n var resolved_name = packet.answers[0].name;\n\n // expected name is 'google.com', according to our request above\n}\n\n
\nFor each incoming request njs creates a separate virtual machine.\nThis brings a lot of benefits such as predictable memory consumption\nor requests isolation.\nHowever, as all requests are isolated,\nif a request handler needs to access some data,\nit has to read it by itself.\nThis is not efficient especially when the amount of data is large.\n
\nTo address this limitation,\na preloaded shared object was introduced.\nSuch objects are created immutable and do not have prototype chains:\ntheir values cannot be changed, properties cannot be added or removed.\n
\nHere are some examples of how to work with a preload object in njs:\n\n
\n\npreloaded_object.prop_name\npreloaded_object[prop_name]\n
\nfor (i in preloaded_object_name) {\n ...\n}\n\ncall():\n\n\nArray.prototype.filter.call(preloaded_object_name, ...)\n
\n
\nnjs provides objects, methods and properties\nfor extending nginx functionality.\n
\nThis reference contains only njs specific properties, methods and modules\nnot compliant with ECMAScript.\nDefinitions of njs properties and methods compliant with ECMAScript\ncan be found in\nECMAScript\nspecification.\nList of all njs properties and methods can be found in\nCompatibility.\n
\n
\nThe HTTP request object is available only in the\nngx_http_js_module module.\nBefore 0.8.5,\nall string properties of the object\nwere byte strings.\n\n
r.args{}\nThe query string is returned as an object.\nSince 0.7.6,\nduplicate keys are returned as an array,\nkeys are case-sensitive, both keys and values are percent-decoded.\n
\n\n\nFor example, the query string\n
\n'a=1&b=%32&A=3&b=4&B=two%20words'\n
\nis converted to r.args as:\n
\n{a: \"1\", b: [\"2\", \"4\"], A: \"3\", B: \"two words\"}\n \nMore advanced parsing scenarios can be achieved with the\nQuery String module\nand with the\n$args\nvariable, for example:\n\n
\nimport qs from 'querystring';\n\nfunction args(r) {\n return qs.parse(r.variables.args);\n}\n \nThe argument object\nis evaluated at the first access to r.args.\nIf only a single argument is needed, for example foo,\nnginx variables can be used:\n
\nr.variables.arg_foo\n
\nHere, nginx variables object\nreturns the first value for a given key,\ncase-insensitive, without percent-decoding.\n
\n\n\nTo convert r.args back to a string,\nthe Query String\nstringify\nmethod can be used.\n
r.decline()satisfy any\n(0.9.9).\nA handler that returns without calling\nr.decline()\nor\nr.return()\nimplicitly grants access.\nMay be called only from the\njs_access function.\nr.done()r.error(string)string to the error log\non the error level of logging\n\n
\nAs nginx has a\nhardcoded\nmaximum line length limit,\nonly first 2048 bytes of the string can be logged.\n
\n
\nr.finish()r.headersIn{}\nThe Foo request header\ncan be accessed with the syntax:\nheadersIn.foo or headersIn['Foo'].\n
\nThe\n“Authorization”,\n“Content-Length”,\n“Content-Range”,\n“Content-Type”,\n“ETag”,\n“Expect”,\n“From”,\n“Host”,\n“If-Match”,\n“If-Modified-Since”,\n“If-None-Match”,\n“If-Range”,\n“If-Unmodified-Since”,\n“Max-Forwards”,\n“Proxy-Authorization”,\n“Referer”,\n“Transfer-Encoding”, and\n“User-Agent”\nrequest headers can have only one field value\n(0.4.1).\nDuplicate field values in “Cookie” headers\nare separated by semicolon (;).\nDuplicate field values in all other request headers are separated by commas.\n
r.headersOut{}\nIf r.headersOut{} is the response object of\na subrequest, it represents response headers.\nIn this case, field values in\n“Accept-Ranges”,\n“Connection”,\n“Content-Disposition”,\n“Content-Encoding”,\n“Content-Length”,\n“Content-Range”,\n“Date”,\n“Keep-Alive”,\n“Server”,\n“Transfer-Encoding”,\n“X-Accel-*”\nresponse headers may be omitted.\n
\nThe “Foo” response header\ncan be accessed with the syntax:\nheadersOut.foo or headersOut['Foo'].\n
\nOutgoing headers should be set before a response header is sent to a client,\notherwise header update will be ignored.\nThis means that r.headersOut{} is effectively writable in:\n\n
r.sendHeader() or\nr.return() are called\n\n
\n\n\nField values of multi-value response headers\n(0.4.0)\ncan be set with the syntax:\n
\nr.headersOut['Foo'] = ['a', 'b']\n
\nwhere the output will be:\n
\nFoo: a\nFoo: b\n
\nAll previous field values of the “Foo” response header\nwill be deleted.\n
\n\n\nFor standard response headers\nthat accept only a single field value such as\n“Content-Type”,\nonly the last element of the array will take effect.\nField values of the “Set-Cookie” response header\nare always returned as an array.\nDuplicate field values in\n“Age”,\n“Content-Encoding”,\n“Content-Length”,\n“Content-Type”,\n“ETag”,\n“Expires”,\n“Last-Modified”,\n“Location”,\n“Retry-After”\nresponse headers are ignored.\nDuplicate field values in all other response headers\nare separated by commas.\n
\nr.httpVersionr.internalr.internalRedirect(uri)uri.\nIf the uri starts with the “@” prefix,\nit is considered a named location.\nIn a new location, all request processing is repeated\nstarting from NGX_HTTP_SERVER_REWRITE_PHASE\nfor ordinary locations and from NGX_HTTP_REWRITE_PHASE\nfor named locations.\nAs a result, a redirect to a named location\ndoes not check client_max_body_size\nlimit.\nSee dev guide\nfor more details.\nRedirected requests become internal and can access the\ninternal\nlocations.\nThe actual redirect happens after the handler execution is completed.\n\n
\nAfter redirect,\na new njs VM is started in the target location,\nthe VM in the original location is stopped.\nValues of nginx variables are kept\nand can be used to pass information to the target location.\nSince 0.5.3,\nthe variable declared with the js_var directive for\nhttp or\nstream\ncan be used.\n\n
\n\n\n
\nSince 0.7.4,\nthe method accepts escaped URIs.\n
\n
\n\nr.log(string)string to the error log\non the info level of logging\n\n
\nAs nginx has a\nhardcoded\nmaximum line length limit,\nonly first 2048 bytes of the string can be logged.\n
\n
\nr.methodr.parentr.remoteAddressr.readRequestArrayBuffer()Promise that resolves with the client\nrequest body as an ArrayBuffer\n(0.9.9).\nSee\nr.readRequestText()\nfor availability, body caching, and concurrency semantics.\nr.readRequestForm([options])Promise that resolves with a form object\n(0.9.9).\nSupported content types are\napplication/x-www-form-urlencoded\nand multipart/form-data.\n\n\nThe form object provides the following methods:\n
get(name)name,\nor null if absent.\ngetAll(name)name.\nhas(name)true if at least one entry exists\nfor name.\nforEach(callback[,\nthisArg])callback for each entry with arguments\n(value, key, form).\nhasFiles()true if the form contains any file parts.\n\n
\n\n\nFor text fields, values are decoded strings.\nFor file parts, the value is an object with the client-supplied\nfilename available as the name property;\nfile contents are not exposed.\nThe filename is client-supplied and is not sanitized.\n
\nThe optional options object accepts the following\nproperties:\n
maxKeys\nnumber128.\nExceeding the limit rejects the returned promise.\n\n
\n\n\nSee\nr.readRequestText()\nfor availability, body caching, and concurrency semantics.\nThe parsed form is itself cached on the request:\na subsequent call returns the same form object and ignores any\nnew options argument.\n
r.readRequestJSON()Promise that resolves with the client\nrequest body parsed as JSON\n(0.9.9).\nSee\nr.readRequestText()\nfor availability, body caching, and concurrency semantics.\nr.readRequestText()Promise that resolves with the client\nrequest body as a string\n(0.9.9).\nThe size of the request body is limited by\nclient_max_body_size.\nThe method is available in the\njs_access\nand\njs_content directives.\n\n\nThe body is read once and cached on the request:\nsubsequent calls to\nr.readRequestText(),\nr.readRequestArrayBuffer(),\nr.readRequestJSON(),\nor\nr.readRequestForm()\nresolve from the cached body without re-reading the wire.\nA second call issued while a previous read is still pending throws\n\"request body is already being read\".\n
\nNote that\nit may convert bytes invalid in UTF-8 encoding into the replacement\ncharacter.\n
\nr.requestBodyr.requestBuffer or\nr.requestText property\nshould be used instead.\nr.requestBufferr.readRequestText()\nand other “r.readRequest*()” methods.\nr.requestTextr.requestBuffer,\nbut returns a string.\nNote that\nit may convert bytes invalid in UTF-8 encoding into the replacement character.\nFor asynchronous access, or for use in\njs_access, see\nr.readRequestText().\nr.rawHeadersIn[]\nFor example, with the following request headers:\n
\nHost: localhost\nFoo: bar\nfoo: bar2\n
\nthe output of r.rawHeadersIn will be:\n
\n[\n ['Host', 'localhost'],\n ['Foo', 'bar'],\n ['foo', 'bar2']\n]\n
\nAll foo headers\ncan be collected with the syntax:\n
\nr.rawHeadersIn.filter(v=>v[0].toLowerCase() == 'foo').map(v=>v[1])\n
\nthe output will be:\n
\n['bar', 'bar2']\n
\nHeader field names are not converted to lower case,\nduplicate field values are not merged.\n
\nr.rawHeadersOut[]r.responseBodyr.responseBuffer\nor\nthe r.responseText\nproperty\nshould be used instead.\nr.responseBufferr.responseBuffer is limited by the\nsubrequest_output_buffer_size\ndirective.\nr.responseTextr.responseBuffer\nbut returns a string\n(since 0.5.0).\nNote that\nit may convert bytes invalid in UTF-8 encoding into the replacement character.\nr.return(status[,\nstring | Buffer])status to the client.\nThe response can be a string or Buffer\n(0.5.0).\n\nMay be called from the\njs_content\nor, since 0.9.9,\njs_access handler.\n
\n\nIt is possible to specify either a redirect URL\n(for codes 301, 302, 303, 307, and 308)\nor the response body text (for other codes) as the second argument\n
\nr.send(string\n| Buffer)r.sendBuffer(data[,\noptions])\nThe data can be a string or Buffer.\nThe options is an object used\nto override nginx buffer flags derived from an incoming data chunk buffer.\nThe flags can be overridden with the following flags:\n
lastflushflush flag\n\n
\nThe method may be called only from the\njs_body_filter function.\nr.sendHeader()r.setReturnValue(value)\nasync function js_set(r) {\n const digest = await crypto.subtle.digest('SHA-256', r.headersIn.host);\n r.setReturnValue(digest);\n}\n\nr.statusr.subrequest(uri[,\noptions[, callback]])uri and\noptions, and installs\nan optional completion callback.\n\n\nA\nsubrequest\nshares its input headers with the client request.\nTo send headers different from original headers to a proxied server, the\nproxy_set_header\ndirective can be used.\nTo send a completely new set of headers to a proxied server, the\nproxy_pass_request_headers\ndirective can be used.\n
\n\n\nIf options is a string, then it\nholds the subrequest arguments string.\nOtherwise, options is expected to be\nan object with the following keys:\n
argsbodymethodGET method is used\ndetachedtrue, the created subrequest is a detached subrequest.\nResponses to detached subrequests are ignored.\nUnlike ordinary subrequests, a detached subrequest\ncan be created inside a variable handler.\nThe detached flag and callback argument\nare mutually exclusive.\n\n
\n\n\nThe completion callback receives\na subrequest response object with methods and properties\nidentical to the parent request object.\n
\nSince 0.3.8,\nif a callback is not provided,\nthe Promise object\nthat resolves to the subrequest response object\nis returned.\n
\nFor example, to view all response headers in the subrequest:\n
\nasync function handler(r) {\n const reply = await r.subrequest('/path');\n\n for (const h in reply.headersOut) {\n r.log(`${h}: ${reply.headersOut[h]}`);\n }\n\n r.return(200);\n}\n\n
\n\nr.urir.rawVariables{}r.jsVarNames([prefix])prefix argument must be a string.\nIf it is specified, only names that start with the prefix are returned.\nr.variables{}\nFor example, to get the $foo variable,\none of the following syntax can be used:\n
\nr.variables['foo']\nr.variables.foo\n
\nSince 0.8.6,\nregular expression captures can be accessed using the following syntax:\n
\nr.variables['1']\nr.variables[1]\n
\n
\n\n\nnginx treats variables referenced in nginx.conf\nand unreferenced variables differently.\nWhen a variable is referenced, it may be cacheable,\nbut when it is unreferenced it is always uncacheable.\nFor example, when the\n$request_id\nvariable is only accessed from njs,\nit has a new value every time it is evaluated.\nBut, when the\n$request_id\nis referenced, for example:\n
\nproxy_set_header X-Request-Id $request_id;\n
\nthe r.variables.request_id returns the same value every time.\n
\nA variable is writable if:\n
js_var directive for\nhttp or\nstream\n(since 0.5.3)\n \nEven so, some embedded variables still cannot be assigned a value (for example,\n$http_).\n
r.warn(string)string to the error log\non the warning level of logging\n\n
\nAs nginx has a\nhardcoded\nmaximum line length limit,\nonly first 2048 bytes of the string can be logged.\n
\n
\n\n
\n
\nThe stream session object is available only in the\nngx_stream_js_module\nmodule.\nBefore 0.8.5,\nall string properties of the object\nwere byte strings.\n
\n
s.allow()s.done(0)\n(0.2.4)\ns.decline()s.done(-5)\n(0.2.4)\ns.deny()s.done(403)\n(0.2.4)\ns.done([code])code for the current\nphase handler\nto a code value, by default 0.\nThe actual finalization happens when the js handler is completed\nand all pending events, for example, from\nngx.fetch() or\nsetTimeout(),\nare processed\n(0.2.4).\n\nPossible code values:\n
0 — \nsuccessful finalization, passing control to the next phase\n-5 — \nundecided, passing control to the next handler of the current phase (if any)\n403 — \naccess is forbidden\n\n
\nMay be called only from a phase handler function:\njs_access\nor\njs_preread.\ns.error(string)string to the error log\non the error level of logging\n\n
\nAs nginx has a\nhardcoded\nmaximum line length limit,\nonly first 2048 bytes of the string can be logged.\n
\n
\ns.log(string)string to the error log\non the info level of logging\n\n
\nAs nginx has a\nhardcoded\nmaximum line length limit,\nonly first 2048 bytes of the string can be logged.\n
\n
\ns.off(eventName)s.on(event,\ncallback)callback\nfor the specified event\n(0.2.4).\n\n\nAn event may be one of the following strings:\n
uploaddownloadupstreamdownstream\n
\n\n\nThe completion callback has the following prototype:\ncallback(data, flags), where\ndata is string or Buffer (depending on the event type)\nflags is an object\nwith the following properties:\n
last\n
\ns.remoteAddresss.rawVariabless.jsVarNames([prefix])prefix argument must be a string.\nIf it is specified, only names that start with the prefix are returned.\ns.send(data[,\noptions])\nThe data can be a string or Buffer\n(0.5.0).\nThe options is an object used\nto override nginx buffer flags derived from an incoming data chunk buffer.\nThe flags can be overridden with the following flags:\n
lastflushflush flag\n\n
\nThe method can be called multiple times per callback invocation.\ns.sendDownstream()s.sendUpstream()s.status$status\nvariable,\nread only\n(since 0.5.2)\ns.setReturnValue(value)\nasync function js_set(r) {\n const digest = await crypto.subtle.digest('SHA-256', r.headersIn.host);\n r.setReturnValue(digest);\n}\n\ns.variables{}s.warn(string)string to the error log\non the warning level of logging\n\n
\nAs nginx has a\nhardcoded\nmaximum line length limit,\nonly first 2048 bytes of the string can be logged.\n
\n
\n\n
\n
PeriodicSession.rawVariables{} |
PeriodicSession.variables{} |
\nThe Periodic Session object is provided as the first argument\nfor the js_periodic handler for\nhttp\nand\nstream\n(since 0.8.1).\n
\n
PeriodicSession.rawVariables{}PeriodicSession.variables{}\n
\n
Headers() |
Headers.append() |
Headers.delete() |
Headers.get() |
Headers.getAll() |
Headers.forEach() |
Headers.has() |
Headers.set() |
\nThe Headers interface of the\nFetch API\nis available since 0.5.1.\n
\nA new Headers object can be created using the\nHeaders() constructor:\n(since 0.7.10):\n\n
Headers([init])initHeaders object,\ncan be a string,\nan array of name-value pairs,\nor an existing Headers object.\n\n
\nA new Headers object can be created\nwith the following properties and methods:\n\n
append()Headers object,\nor adds the header if it does not already exist\n(since 0.7.10).\ndelete()Headers object\n(since 0.7.10).\nget()getAll(name)forEach()Headers object\n(since 0.7.10).\nhas()set()Headers object,\nor adds the header if it does not already exist\n(since 0.7.10).\n\n
\n
Request() |
Request.arrayBuffer() |
Request.bodyUsed |
Request.cache |
Request.credentials |
Request.headers |
Request.json() |
Request.method |
Request.mode |
Request.text() |
Request.url |
\nThe Request interface of the\nFetch API\nis available since 0.7.10.\n
\nA new Request object can be created using the\nRequest() constructor:\n\n
Request[resource[,\noptions]])Request object to fetch\nthat can be passed later to\nngx.fetch().\nThe resource can be a URL\nor an existing Request object.\nThe options is an optional argument\nthat is expected to be an object with the following keys:\n\nbodyheadersHeaders object,\ncan be a string,\nan array of name-value pairs,\nor an existing Headers object.\nmethod\n
\nA new Request object can be created\nwith the following properties and methods:\n\n
arrayBuffer()Promise that resolves with\nan ArrayBuffer.\nbodyUsedtrue\nif the body was used in the request.\ncachecredentialssame-origin.\nheadersHeaders read-only object\nassociated with the\nRequest.\njson()Promise that resolves with\nthe result of parsing the request body as JSON.\nmethodmodetext()Promise that resolves with a\nstring representation of the request body.\nurl\n
\n
\nThe Response interface is available since\n0.5.1.\n
\nA new Response object can be created using the\nResponse() constructor\n(since 0.7.10):\n\n
Response[body[,\noptions]])Response object.\nThe body is an optional argument,\ncan be a string or a buffer,\nby default is null.\nThe options is an optional argument\nthat is expected to be an object with the following keys:\n\nheadersHeaders object,\ncan be a string,\nan array of name-value pairs,\nor an existing Headers object.\nstatusstatusText\n
\nA new Response() object can be created\nwith the following properties and methods:\n\n
arrayBuffer()Response stream and reads it to completion.\nReturns a Promise that resolves with\nan ArrayBuffer.\nbodyUsedtrue\nif the body was read.\nheadersHeaders read-only object\nassociated with the\nResponse.\njson()Response stream and reads it to completion.\nReturns a Promise that resolves with\nthe result of parsing the body text as JSON.\noktrue\nif the response was successful (status codes between 200–299).\nredirectedtrue\nif the response is the result of a redirect.\nstatusstatusTexttext()Response stream and reads it to completion.\nReturns a Promise that resolves with a string.\ntypeurl\n
\n
ngx.build |
ngx.conf_file_path |
ngx.conf_prefix |
ngx.error_log_path |
ngx.fetch() |
ngx.log() |
ngx.prefix |
ngx.version |
ngx.version_number |
ngx.worker_id |
\nThe ngx global object is available\nsince 0.5.0.\n
ngx.build--build=name\nargument\nof the configure script,\nby default is \"\"\n(0.8.0)\nngx.conf_file_pathngx.conf_prefixngx.error_log_pathngx.fetch(resource,\n[options])\nMakes a request to fetch a resource\n(0.5.1), which can be an\nURL or the Request object\n(0.7.10).\nReturns a Promise that resolves with\nthe Response object.\nSince 0.7.0,\nthe https:// scheme is supported,\nredirects are not handled.\n
\nIf the URL in the resource is specified as a domain name,\nit is determined using a\nresolver.\nIf the https:// scheme is specified, the\njs_fetch_trusted_certificate\ndirective should be configured\nfor the authentication of the resource's HTTPS server.\n
\nThe options parameter is expected to be an object\nwith the following keys:\n
bodybuffer_size4096\nheadersmax_response_body_size32768\nmethodGET method is used\nverifytrue\n(0.7.0)\n\nExample:\n
\nlet reply = await ngx.fetch('http://nginx.org/');\nlet body = await reply.text();\n\nr.return(200, body);\n\n
\nngx.log(level,\nmessage)level parameter specifies one of the log levels,\nthe message parameter can be a string or Buffer.\nThe following log levels can be specified:\nngx.INFO,\nngx.WARN, and\nngx.ERR.\n\n
\nAs nginx has a\nhardcoded\nmaximum line length limit,\nonly first 2048 bytes of the string can be logged.\n
\n
\nngx.prefixngx.version1.25.0\n(0.8.0)\nngx.version_number1025000\n(0.8.0)\nngx.worker_id0 and the value specified in the\nworker_processes directive\n(0.8.0)\n\n
\nThe ngx.shared global object is available\nsince 0.8.0.\n
\n
\nThe shared dictionary object is available\nsince 0.8.0.\nThe shared dictionary name, type, and size\nare set with the js_shared_dict_zone directive in\nhttp\nor\nstream.\n
\nA SharedDict() object\nhas the following properties and methods:\n
ngx.shared.SharedDict.add(key,\nvalue [,timeout])value\nfor the specified key in the dictionary\nonly if the key does not exist yet.\nThe key is a string representing\nthe key of the item to add,\nthe value is the value of the item to add.\n\nThe optional timeout argument is specified in milliseconds\nand overrides the timeout parameter of the\njs_shared_dict_zone directive in\nhttp\nor\nstream\n(since 0.8.5).\nIt can be useful when some keys are expected to have unique timeouts.\n
\nReturns true if the value has been successfully added\nto the SharedDict dictionary,\nfalse if the key already exists in the dictionary.\nThrows SharedMemoryError if\nthere is not enough free space in the SharedDict dictionary.\nThrows TypeError if the value is\nof a different type than expected by this dictionary.\n
ngx.shared.SharedDict.capacitySharedDict dictionary,\ncorresponds to the size parameter of\njs_shared_dict_zone directive in\nhttp\nor\nstream.\nngx.shared.SharedDict.clear()SharedDict dictionary.\nngx.shared.SharedDict.delete(key)SharedDict dictionary,\ntrue if the item in the dictionary existed and was removed,\nfalse otherwise.\nngx.shared.SharedDict.freeSpace()SharedDict dictionary\nwill still accept new values if there is space in the occupied pages.\nngx.shared.SharedDict.get(key)key,\nreturns the value associated with the key\nor undefined if there is none.\nngx.shared.SharedDict.has(key)key,\nreturns true if such item exists or\nfalse otherwise.\nngx.shared.SharedDict.incr(key,delta[[,init], timeout]))key\nby delta.\nThe key is a string,\nthe delta is the number\nto increment or decrement the value by.\nIf the key does not exist,\nthe item will be initialized to an optional init argument,\nby default is 0.\n\n\nThe optional timeout argument is specified in milliseconds\nand overrides the timeout parameter of the\njs_shared_dict_zone directive in\nhttp\nor\nstream\n(since 0.8.5).\nIf the timeout argument is not specified,\nthe existing per-entry TTL is preserved\n(since 0.9.7).\nBefore version 0.9.7,\nomitting timeout would reset the entry expiry\nto the directive default.\n
\nReturns the new value.\nThrows SharedMemoryError if\nthere is not enough free space in the SharedDict dictionary.\nThrows TypeError if this dictionary does not expect numbers.\n
\n
\nThis method can be used only if the dictionary type was declared with\ntype=numberparameter of the\njs_shared_dict_zonedirective in\nhttp\nor\nstream.\n
\n
\nngx.shared.SharedDict.items([maxCount])SharedDict dictionary\nkey-value items (since 0.8.1).\nThe maxCount parameter\nsets maximum number of items to retrieve,\nby default is 1024.\n\nngx.shared.SharedDict.keys([maxCount])SharedDict dictionary keys.\nThe maxCount parameter\nsets maximum number of keys to retrieve,\nby default is 1024.\nngx.shared.SharedDict.nameSharedDict dictionary,\ncorresponds to the zone= parameter of\njs_shared_dict_zone directive in\nhttp\nor\nstream.\nngx.shared.SharedDict.pop(key)key\nfrom the SharedDict dictionary,\nreturns the value associated with the key\nor undefined if there is none.\nngx.shared.SharedDict.replace(key,\nvalue)value\nfor the specified key only if the key already exists,\nreturns true if the value was successfully replaced,\nfalse if the key does not exist\nin the SharedDict dictionary.\nThrows SharedMemoryError if\nthere is not enough free space in the SharedDict dictionary.\nThrows TypeError if the value is\nof a different type than expected by this dictionary.\nngx.shared.SharedDict.set(key,\nvalue [,timeout])value for the specified key,\nreturns this SharedDict dictionary (for method chaining).\n\n\nThe optional timeout argument is specified in milliseconds\nand overrides the timeout parameter of the\njs_shared_dict_zone directive in\nhttp\nor\nstream\n(since 0.8.5).\nIt can be useful when some keys are expected to have unique timeouts.\n
ngx.shared.SharedDict.size()SharedDict dictionary.\nngx.shared.SharedDict.ttl(key)key,\nor undefined if the key does not exist\nor has expired\n(since 0.9.7).\n\n\nThrows TypeError if the dictionary was declared\nwithout the timeout parameter of the\njs_shared_dict_zone directive in\nhttp\nor\nstream.\n
ngx.shared.SharedDict.typestring or number that\ncorresponds to the SharedDict dictionary type\nset by the type= parameter of\njs_shared_dict_zone directive in\nhttp\nor\nstream.\n\n
\n
console.error() |
console.info() |
console.log() |
console.time() |
console.timeEnd() |
console.warn() |
\nThe console object is available\nin nginx since 0.8.2,\nin CLI since 0.2.6.\n
console.error(msg[, msg2 ...])console.info(msg[, msg2 ...])console.log(msg[, msg2 ...])console.time(label)label parameter allows naming different timers.\nIf console.timeEnd()\nwith the same name is called,\nthe time that elapsed since the timer was started will be output,\nin milliseconds.\nconsole.timeEnd(label)console.time()\nThe label parameter allows naming different timers.\nconsole.warn(msg[, msg2 ...])\n
\n
\nThe crypto object is a global object\nthat allows using cryptographic functionality\n(since 0.7.0).\nSince 0.9.7,\nthe full\nWeb Crypto API\nspecification is supported.\n
\n
сrypto.getRandomValues(typedArray)typedArray\nbut with its contents replaced with the newly generated random numbers.\nPossible values:\n\ntypedArrayInt8Array,\nInt16Array,\nUint16Array,\nInt32Array, or\nUint32Array\nсrypto.randomUUID()\"36b8f84d-df4e-4d49-b662-bcde71a8764f\"\n(since 0.9.7).\nсrypto.subtle.encrypt(algorithm,\nkey,\ndata)data\nusing the provided\nalgorithm and\nkey.\nReturns a Promise that fulfills with\nan ArrayBuffer containing the ciphertext.\nPossible values:\n\nalgorithmRSA-OAEP,\npass the object with the following keys:\n\nname is a string,\nshould be set to RSA-OAEP:\n\n
\ncrypto.subtle.encrypt({name: \"RSA-OAEP\"}, key, data)\n\n
\nAES-CTR,\npass the object with the following keys:\n\nname is a string,\nshould be set to AES-CTR\ncounter is an\nArrayBuffer,\nTypedArray, or\nDataView —\nthe initial value of the counter block,\nmust be 16 bytes long (the AES block size).\nThe rightmost length bits of this block are used for the counter,\nand the rest is used for the nonce.\nFor example, if length is set to 64,\nthen the first half of counter is the nonce\nand the second half is used for the counter\nlength is the number of bits in the counter block\nthat are used for the actual counter.\nThe counter must be big enough that it doesn't wrap.\nAES-CBC, pass the object with the following keys:\n\nname is a string,\nshould be set to AES-CBC\niv or the initialization vector, is an\nArrayBuffer,\nTypedArray, or\nDataView,\nmust be 16 bytes, unpredictable,\nand preferably cryptographically random.\nHowever, it need not be secret,\nfor example, it may be transmitted unencrypted along with the ciphertext.\nAES-GCM, pass the object with the following keys:\n\nname is a string,\nshould be set to AES-GCM\niv or the initialization vector, is an\nArrayBuffer,\nTypedArray, or\nDataView,\nmust be 16 bytes,\nand must be unique for every encryption operation carried out with a given key\nadditionalData (optional) is an\nArrayBuffer,\nTypedArray, or\nDataView\nthat contains additional data that\nwill not be encrypted but will be authenticated along with the encrypted data.\nIf additionalData is specified,\nthen the same data must be specified in the corresponding call to\ndecrypt():\nif the data given to the decrypt() call\ndoes not match the original data,\nthe decryption will throw an exception.\nThe bit length of additionalData\nmust be smaller than 2^64 - 1.\ntagLength (optional, default is 128) -\na number that determines the size in bits\nof the authentication tag generated in the encryption operation\nand used for authentication in the corresponding decryption\nPossible values:\n32,\n64,\n96,\n104,\n112,\n120, or\n128.\nThe AES-GCM specification recommends that it should be\n96,\n104,\n112,\n120, or\n128,\nalthough\n32 or\n64\nbits may be acceptable in some applications.\nkeyCryptoKey that contains\nthe key to be used for encryption\ndataArrayBuffer,\nTypedArray, or\nDataView\nthat contains\nthe data to be encrypted (also known as the plaintext)\nсrypto.subtle.decrypt(algorithm,\nkey,\ndata)Promise with the decrypted data.\nPossible values:\n\nalgorithmencrypt() call.\n\nRSA-OAEP,\npass the object with the following keys:\n\nname is a string,\nshould be set to RSA-OAEP:\n\n
\ncrypto.subtle.encrypt({name: \"RSA-OAEP\"}, key, data)\n\n
\nAES-CTR,\npass the object with the following keys:\n\nname is a string,\nshould be set to AES-CTR\ncounter is an\nArrayBuffer,\nTypedArray, or\nDataView —\nthe initial value of the counter block,\nmust be 16 bytes long (the AES block size).\nThe rightmost length bits of this block are used for the counter,\nand the rest is used for the nonce.\nFor example, if length is set to 64,\nthen the first half of counter is the nonce\nand the second half is used for the counter.\nlength is the number of bits in the counter block\nthat are used for the actual counter.\nThe counter must be big enough that it doesn't wrap.\nAES-CBC, pass the object with the following keys:\n\nname is a string,\nshould be set to AES-CBC\niv or the initialization vector, is an\nArrayBuffer,\nTypedArray, or\nDataView,\nmust be 16 bytes, unpredictable,\nand preferably cryptographically random.\nHowever, it need not be secret\n(for example, it may be transmitted unencrypted along with the ciphertext).\nAES-GCM, pass the object with the following keys:\n\nname is a string,\nshould be set to AES-GCM\niv or the initialization vector, is an\nArrayBuffer,\nTypedArray, or\nDataView,\nmust be 16 bytes,\nand must be unique for every encryption operation carried out with a given key\nadditionalData (optional) is an\nArrayBuffer,\nTypedArray, or\nDataView\nthat contains additional data that\nwill not be encrypted but will be authenticated along with the encrypted data.\nIf additionalData is specified,\nthen the same data must be specified in the corresponding call to\ndecrypt():\nif the data given to the decrypt() call\ndoes not match the original data,\nthe decryption will throw an exception.\nThe bit length of additionalData\nmust be smaller than 2^64 - 1.\ntagLength (optional, default is 128) -\na number that determines the size in bits\nof the authentication tag generated in the encryption operation\nand used for authentication in the corresponding decryption.\nPossible values:\n32,\n64,\n96,\n104,\n112,\n120, or\n128.\nThe AES-GCM specification recommends that it should be\n96,\n104,\n112,\n120, or\n128,\nalthough\n32 or\n64\nbits may be acceptable in some applications.\nkeyCryptoKey\nthat contains the key to be used for decryption.\nIf RSA-OAEP is used, this is the\nprivateKey property of the\nCryptoKeyPair object.\ndataArrayBuffer,\nTypedArray, or\nDataView\nthat contains the data to be decrypted (also known as ciphertext)\nсrypto.subtle.deriveBits(algorithm,\nbaseKey,\nlength)Promise\nwhich will be fulfilled with an\nArrayBuffer that contains the derived bits.\nPossible values:\n\nalgorithmHKDF,\npass the object with the following keys:\n\nname is a string,\nshould be set to HKDF\nhash is a string with the digest algorithm to use:\nSHA-1,\nSHA-256,\nSHA-384, or\nSHA-512\nsalt is an\nArrayBuffer,\nTypedArray, or\nDataView\nthat represents random or pseudo-random value\nwith the same length as the output of the digest function.\nUnlike the input key material passed into deriveKey(),\nsalt does not need to be kept secret.\ninfo is an\nArrayBuffer,\nTypedArray, or\nDataView\nthat represents application-specific contextual information\nused to bind the derived key to an application or context,\nand enables deriving different keys for different contexts\nwhile using the same input key material.\nThis property is required but may be an empty buffer.\nPBKDF2,\npass the object with the following keys:\n\nname is a string,\nshould be set to PBKDF2\nhash is a string with the digest algorithm to use:\nSHA-1,\nSHA-256,\nSHA-384, or\nSHA-512\nsalt is an\nArrayBuffer,\nTypedArray, or\nDataView\nthat represents random or pseudo-random value\nof at least 16 bytes.\nUnlike the input key material passed into deriveKey(),\nsalt does not need to be kept secret.\niterations is a number\nthat represents the number of times the hash function will be executed\nin deriveKey()\nECDH,\npass the object with the following keys\n(since 0.9.1):\n\nname is a string,\nshould be set to ECDH\npublic is a CryptoKey\nthat represents the public key of the other party.\nThe key must be generated using the same curve as the base key.\nX25519,\npass the object with the following keys\n(since 0.9.7):\n\nname is a string,\nshould be set to X25519\npublic is a CryptoKey\nthat represents the public key of the other party\nbaseKeyCryptoKey\nthat represents the input to the derivation algorithm\n- the initial key material for the derivation function:\nfor example, for PBKDF2 it might be a password,\nimported as a CryptoKey using\nсrypto.subtle.importKey()\nlength8\nсrypto.subtle.deriveKey(algorithm,\nbaseKey,\nderivedKeyAlgorithm,\nextractable,\nkeyUsages)algorithmHKDF,\npass the object with the following keys:\n\nname is a string,\nshould be set to HKDF\nhash is a string with the digest algorithm to use:\nSHA-1,\nSHA-256,\nSHA-384, or\nSHA-512\nsalt is an\nArrayBuffer,\nTypedArray, or\nDataView\nthat represents random or pseudo-random value\nwith the same length as the output of the digest function.\nUnlike the input key material passed into deriveKey(),\nsalt does not need to be kept secret.\ninfo is an\nArrayBuffer,\nTypedArray, or\nDataView\nthat represents application-specific contextual information\nused to bind the derived key to an application or context,\nand enables deriving different keys for different contexts\nwhile using the same input key material.\nThis property is required but may be an empty buffer.\nPBKDF2,\npass the object with the following keys:\n\nname is a string,\nshould be set to PBKDF2\nhash is a string with the digest algorithm to use:\nSHA-1,\nSHA-256,\nSHA-384, or\nSHA-512\nsalt is an\nArrayBuffer,\nTypedArray, or\nDataView\nthat represents random or pseudo-random value\nof at least 16 bytes.\nUnlike the input key material passed into deriveKey(),\nsalt does not need to be kept secret.\niterations is a number\nthat represents the number of times the hash function will be executed\nin deriveKey()\nECDH,\npass the object with the following keys\n(since 0.9.1):\n\nname is a string,\nshould be set to ECDH\npublic is a CryptoKey\nthat represents the public key of the other party.\nThe key must be generated using the same curve as the base key.\nX25519,\npass the object with the following keys\n(since 0.9.7):\n\nname is a string,\nshould be set to X25519\npublic is a CryptoKey\nthat represents the public key of the other party\nbaseKeyCryptoKey\nthat represents the input to the derivation algorithm\n- the initial key material for the derivation function:\nfor example, for PBKDF2 it might be a password,\nimported as a CryptoKey using\nсrypto.subtle.importKey().\nderivedKeyAlgorithmHMAC,\npass the object with the following keys:\n\nname is a string,\nshould be set to HMAC\nhash is a string with the name of the digest function to use:\nSHA-1,\nSHA-256,\nSHA-384, or\nSHA-512\nlength (optional) is a number\nthat represents the length in bits of the key.\nIf not specified, the length of the key is equal to\nthe block size of the chozen hash function\nAES-CTR,\nAES-CBC,\nAES-GCM, or\nAES-KW\n(since 0.9.7),\npass the object with the following keys:\n\nname is a string,\nshould be set to\nAES-CTR,\nAES-CBC,\nAES-GCM, or\nAES-KW,\ndepending on the algorithm used\nlength is a number that represents\nthe length in bits of the key to generate:\n128,\n192, or\n256\nextractablekeyUsagesArray\nthat indicates what can be done with the derived key.\nThe key usages must be allowed by the algorithm\nset in derivedKeyAlgorithm.\nPossible values:\nencryptdecryptsignverifyderiveKeyderiveBitswrapKeyunwrapKeyсrypto.subtle.digest(algorithm,\ndata)Promise which will be fulfilled with the digest.\nPossible values:\n\nalgorithmSHA-1 (not for cryptographic applications),\nSHA-256,\nSHA-384, or\nSHA-512\ndataArrayBuffer,\nTypedArray, or\nDataView\nthat contains the data to be digested\nсrypto.subtle.exportKey(format,\nkey)CryptoKey object\nand returns the key in an external, portable format\n(since 0.7.10).\nIf the format was jwk,\nthen the Promise fulfills with a JSON object\ncontaining the key.\nOtherwise, the promise fulfills with an\nArrayBuffer containing the key.\nPossible values:\nformatrawpkcs8spkijwkkeyCryptoKey\nthat contains the key to be exported\nсrypto.subtle.generateKey(algorithm,\nextractable,\nusage)Promise that fulfills with the generated key\nas\na CryptoKey\nor CryptoKeyPair object.\nPossible values:\nalgorithmRSASSA-PKCS1-v1_5,\nRSA-PSS, or\nRSA-OAEP,\npass the object with the following keys:\n\nname is a string, should be set to\nRSASSA-PKCS1-v1_5,\nRSA-PSS, or\nRSA-OAEP,\ndepending on the used algorithm\nhash is a string that represents\nthe name of the digest function to use, can be\nSHA-256,\nSHA-384, or\nSHA-512\nECDSA,\npass the object with the following keys:\n\nname is a string, should be set to ECDSA\nnamedCurve is a string that represents\nthe name of the elliptic curve to use, may be\nP-256,\nP-384, or\nP-521\nHMAC,\npass the object with the following keys:\n\nname is a string, should be set to HMAC\nhash is a string that represents\nthe name of the digest function to use, can be\nSHA-256,\nSHA-384, or\nSHA-512\nlength (optional) is a number that represents\nthe length in bits of the key.\nIf omitted, the length of the key is equal to the length of the digest\ngenerated by the chosen digest function.\nAES-CTR,\nAES-CBC,\nAES-GCM, or\nAES-KW\n(since 0.9.7),\npass the string identifying the algorithm or an object\nof the form { \"name\": \"ALGORITHM\" },\nwhere ALGORITHM is the name of the algorithm\nECDH,\npass the object with the following keys\n(since 0.9.1):\n\nname is a string, should be set to ECDH\nnamedCurve is a string that represents\nthe name of the elliptic curve to use, may be\nP-256,\nP-384, or\nP-521\nEd25519,\npass the Ed25519 string\nor an object of the form { \"name\": \"Ed25519\" }\n(since 0.9.7)\nX25519,\npass the X25519 string\nor an object of the form { \"name\": \"X25519\" }\n(since 0.9.7)\nextractableusagearray that indicates possible actions with the key:\nencryptdecryptsignverifyderiveKeyderiveBitswrapKeyunwrapKeyсrypto.subtle.importKey(format,\nkeyData,\nalgorithm,\nextractable,\nkeyUsages)CryptoKey object.\nReturns a Promise that fulfills with the imported key\nas a CryptoKey object.\nPossible values:\nformatrawpkcs8spkijwkkeyDataArrayBuffer,\nTypedArray, or\nDataView\nobject that contains the key in the given format\nalgorithmRSASSA-PKCS1-v1_5,\nRSA-PSS, or\nRSA-OAEP,\npass the object with the following keys:\n\nname is a string, should be set to\nRSASSA-PKCS1-v1_5,\nRSA-PSS, or\nRSA-OAEP,\ndepending on the used algorithm\nhash is a string that represents\nthe name of the digest function to use, can be\nSHA-1,\nSHA-256,\nSHA-384, or\nSHA-512\nECDSA,\npass the object with the following keys:\n\nname is a string, should be set to ECDSA\nnamedCurve is a string that represents\nthe name of the elliptic curve to use, may be\nP-256,\nP-384, or\nP-521\nHMAC,\npass the object with the following keys:\n\nname is a string, should be set to HMAC\nhash is a string that represents\nthe name of the digest function to use, can be\nSHA-256,\nSHA-384, or\nSHA-512\nlength (optional) is a number that represents\nthe length in bits of the key.\nIf omitted, the length of the key is equal to the length of the digest\ngenerated by the chosen digest function.\nAES-CTR,\nAES-CBC,\nAES-GCM, or\nAES-KW\n(since 0.9.7),\npass the string identifying the algorithm or an object\nof the form { \"name\": \"ALGORITHM\" },\nwhere ALGORITHM is the name of the algorithm\nPBKDF2,\npass the PBKDF2 string\nHKDF,\npass the HKDF string\nECDH,\npass the object with the following keys\n(since 0.9.1):\n\nname is a string, should be set to ECDH\nnamedCurve is a string that represents\nthe name of the elliptic curve to use, may be\nP-256,\nP-384, or\nP-521\nEd25519,\npass the Ed25519 string\nor an object of the form { \"name\": \"Ed25519\" }\n(since 0.9.7)\nX25519,\npass the X25519 string\nor an object of the form { \"name\": \"X25519\" }\n(since 0.9.7)\nextractablekeyUsagesarray that indicates possible actions with the key:\nencryptdecryptsignverifyderiveKeyderiveBitswrapKeyunwrapKeyсrypto.subtle.sign(algorithm,\nkey,\ndata)signature as a Promise\nthat fulfills with an ArrayBuffer containing the signature.\nPossible values:\n\nalgorithmRSASSA-PKCS1-v1_5,\npass the string identifying the algorithm or an object\nof the form { \"name\": \"ALGORITHM\" }\nRSA-PSS,\npass the object with the following keys:\nname is a string, should be set to\nRSA-PSS\nsaltLength is a long integer\nthat represents the length of the random salt to use, in bytes\nECDSA,\npass the object with the following keys:\nname is a string, should be set to\nECDSA\nhash is an identifier for the digest algorithm to use,\ncan be\nSHA-256,\nSHA-384, or\nSHA-512\nHMAC,\npass the string identifying the algorithm or an object\nof the form { \"name\": \"ALGORITHM\" }\nEd25519,\npass the Ed25519 string\nor an object of the form { \"name\": \"Ed25519\" }\n(since 0.9.7)\nkeyCryptoKey object\nthat the key to be used for signing.\nIf algorithm identifies a public-key cryptosystem, this is the private key.\ndataArrayBuffer,\nTypedArray, or\nDataView\nobject that contains the data to be signed\nсrypto.subtle.verify(algorithm,\nkey,\nsignature,\ndata)Promise that fulfills with a boolean value:\ntrue if the signature is valid,\notherwise false.\nPossible values:\n\nalgorithmRSASSA-PKCS1-v1_5,\npass the string identifying the algorithm or an object\nof the form { \"name\": \"ALGORITHM\" }\nRSA-PSS,\npass the object with the following keys:\nname is a string, should be set to\nRSA-PSS\nsaltLength is a long integer\nthat represents the length of the random salt to use, in bytes\nECDSA,\npass the object with the following keys:\nname is a string, should be set to\nECDSA\nhash is an identifier for the digest algorithm to use,\ncan be\nSHA-256,\nSHA-384, or\nSHA-512\nHMAC,\npass the string identifying the algorithm or an object\nof the form { \"name\": \"ALGORITHM\" }\nEd25519,\npass the Ed25519 string\nor an object of the form { \"name\": \"Ed25519\" }\n(since 0.9.7)\nkeyCryptoKey object\nthat the key to be used for verifying.\nIt is the secret key for a symmetric algorithm\nand the public key for a public-key system.\nsignatureArrayBuffer,\nTypedArray, or\nDataView\nthat contains the signature to verify\ndataArrayBuffer,\nTypedArray, or\nDataView\nobject that contains the data whose signature is to be verified\nсrypto.subtle.wrapKey(format,\nkey,\nwrappingKey,\nwrapAlgorithm)Promise that fulfills with\nan ArrayBuffer containing the encrypted exported key.\nPossible values:\n\nformatrawpkcs8spkijwkkeyCryptoKey\nthat contains the key to be wrapped.\nThe key must have\nCryptoKey.extractable\nset to true.\nwrappingKeyCryptoKey\nthat contains the key used to encrypt the exported key.\nThe key must have the wrapKey usage set.\nwrapAlgorithmAES-CBC,\nAES-CTR, or\nAES-GCM,\npass the corresponding algorithm parameters\nas described in\nсrypto.subtle.encrypt()\nAES-KW,\npass the AES-KW string\nor an object of the form { \"name\": \"AES-KW\" }\nRSA-OAEP,\npass the corresponding algorithm parameters\nas described in\nсrypto.subtle.encrypt()\nсrypto.subtle.unwrapKey(format,\nwrappedKey,\nunwrappingKey,\nunwrapAlgorithm,\nunwrappedKeyAlgorithm,\nextractable,\nkeyUsages)CryptoKey object\nfrom the result\n(since 0.9.7).\nReturns a Promise that fulfills with\nthe unwrapped key as a CryptoKey.\nPossible values:\n\nformatrawpkcs8spkijwkwrappedKeyArrayBuffer,\nTypedArray, or\nDataView\nthat contains the wrapped key in the given format\nunwrappingKeyCryptoKey\nthat contains the key used to decrypt the wrapped key.\nThe key must have the unwrapKey usage set.\nunwrapAlgorithmAES-CBC,\nAES-CTR, or\nAES-GCM,\npass the corresponding algorithm parameters\nas described in\nсrypto.subtle.encrypt()\nAES-KW,\npass the AES-KW string\nor an object of the form { \"name\": \"AES-KW\" }\nRSA-OAEP,\npass the corresponding algorithm parameters\nas described in\nсrypto.subtle.encrypt()\nunwrappedKeyAlgorithmсrypto.subtle.importKey()\napply.\nextractablekeyUsagesarray that indicates possible actions with the key:\nencryptdecryptsignverifyderiveKeyderiveBitswrapKeyunwrapKey\n
\n
CryptoKey.algorithm |
CryptoKey.extractable |
CryptoKey.type |
CryptoKey.usages |
\nThe CryptoKey object\nrepresents a cryptographic key obtained\nfrom one of the SubtleCrypto methods:\nсrypto.subtle.generateKey(),\nсrypto.subtle.deriveKey(),\nсrypto.subtle.importKey().\n
\n
CryptoKey.algorithmCryptoKey.extractabletrue if the key can be exported\n(since 0.8.0),\nread-only\nCryptoKey.typesecretprivateCryptoKeyPair\npublicCryptoKeyPair.\nCryptoKey.usagesencryptdecryptsignverifyderiveKeyderiveBits\n
\n
CryptoKeyPair.privateKey |
CryptoKeyPair.publicKey |
\nThe CryptoKeyPair is a dictionary object\nof the WebCrypto API\nthat represents an asymmetric key pair.\n
\n
CryptoKeyPair.privateKeyCryptoKey object\nrepresenting the private key.\nCryptoKeyPair.publicKeyCryptoKey object\nrepresenting the public key.\n\n
\n
njs.version |
njs.version_number |
njs.dump() |
njs.memoryStats |
njs.on() |
\nThe njs object is a global object\nthat represents the current VM instance\n(since 0.2.0).\n
\n
njs.versionnjs.version_number0x000704\n(since 0.7.4).\nnjs.dump(value)njs.memoryStatssizenjs.on(event,\ncallback)exit\n
\n
process.argv |
process.env |
process.kill() |
process.pid |
process.ppid |
\nThe process object is a global object\nthat provides information about the current process\n(0.3.3).\n
\n
process.argvprocess.env\nBy default, nginx removes all environment variables inherited\nfrom its parent process except the TZ variable.\nUse the env directive\nto preserve some of the inherited variables.\n\n
process.kill(pid,\nnumber | string)pid.\nSignal names are numbers or strings such as 'SIGINT' or 'SIGHUP'.\nSee kill(2)\nfor more information.\nprocess.pidprocess.ppid\n
\nBy default all strings in njs are Unicode strings.\nThey correspond to ECMAScript strings that contain Unicode characters.\nBefore 0.8.0,\nbyte strings were also supported.\n
\n
\nSince 0.8.0,\nthe support for byte strings and byte string methods were removed.\nWhen working with byte sequence,\nthe Buffer object\nandBufferproperties, such as\nr.requestBuffer,\nr.rawVariables,\nshould be used.\n
\n
\nByte strings contain a sequence of bytes\nand are used to serialize Unicode strings\nto external data and deserialize from external sources.\nFor example, the toUTF8() method serializes\na Unicode string to a byte string using UTF-8 encoding:\n
\n>> '£'.toUTF8().toString('hex')\n'c2a3' /* C2 A3 is the UTF-8 representation of 00A3 ('£') code point */\n \nThe toBytes() method serializes\na Unicode string with code points up to 255 into a byte string,\notherwise, null is returned:\n
\n>> '£'.toBytes().toString('hex')\n'a3' /* a3 is a byte equal to 00A3 ('£') code point */\n\n\n
String.bytesFrom(array\n| string, encoding)Buffer.from method should be used instead:\n\n>> Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]).toString()\n'buffer'\n\n>> Buffer.from('YnVmZmVy', 'base64').toString()\n'buffer'\n\nBefore 0.4.4,\ncreated a byte string either from an array that contained octets,\nor from an encoded string\n(0.2.3),\nthe encoding could be\nhex,\nbase64, and\nbase64url.\nString.prototype.fromBytes(start[,\nend])String.prototype.fromUTF8(start[,\nend])TextDecoder method\nshould be used instead.\nBefore 0.7.7,\nconverted a byte string containing a valid UTF-8 string\ninto a Unicode string,\notherwise null was returned.\nString.prototype.toBytes(start[,\nend])null if a character larger than 255 was\nfound in the string.\nString.prototype.toString(encoding)\nthe property was made obsolete in\n0.7.7\nand was removed in 0.8.0.\nBefore 0.7.7,\nencoded a string to\nhex,\nbase64, or\nbase64url:\n
\n>> 'αβγδ'.toString('base64url')\n'zrHOss6zzrQ'\n\nBefore version 0.4.3,\nonly a byte string could be encoded:\n
\n>> 'αβγδ'.toUTF8().toString('base64url')\n'zrHOss6zzrQ'\n\n
\nString.prototype.toUTF8(start[,\nend])TextEncoder method\nshould be used instead.\nBefore 0.7.7,\nserialized a Unicode string\nto a byte string using UTF-8 encoding:\n\n\n>> 'αβγδ'.toUTF8().length\n8\n>> 'αβγδ'.length\n4\n
\n
\n
TextDecoder() |
TextDecoder.prototype.encoding |
TextDecoder.prototype.fatal |
TextDecoder.prototype.ignoreBOM |
TextDecoder.prototype.decode() |
\nThe TextDecoder\nproduces a stream of code points\nfrom a stream of bytes\n(0.4.3).\n
\n
TextDecoder([[encoding],\noptions])TextDecoder object\nfor specified encoding,\ncurrently, only UTF-8 is supported.\nThe options is\nTextDecoderOptions dictionary with the property:\n\nfatalTextDecoder.decode()\nmust throw the TypeError exception when\na coding error is found, by default is false.\nTextDecoder.prototype.encodingTextDecoder(),\nread-only.\nTextDecoder.prototype.fataltrue if\nthe error mode is fatal,\nread-only.\nTextDecoder.prototype.ignoreBOMtrue if\nthe byte order marker is ignored,\nread-only.\nTextDecoder.prototype.decode(buffer,\n[options])buffer by\nTextDecoder().\nThe buffer can be ArrayBuffer.\nThe options is\nTextDecodeOptions dictionary with the property:\n\nstreamdecode():\ntrue if processing the data in chunks, and\nfalse for the final chunk\nor if the data is not chunked.\nBy default is false.\n\n\n>> (new TextDecoder()).decode(new Uint8Array([206,177,206,178]))\nαβ\n
\n
\n
TextEncoder() |
TextEncoder.prototype.encode() |
TextEncoder.prototype.encodeInto() |
\nThe TextEncoder object\nproduces a byte stream with UTF-8 encoding\nfrom a stream of code points\n(0.4.3).\n
\n
TextEncoder()TextEncoder\nthat will generate a byte stream with UTF-8 encoding.\nTextEncoder.prototype.encode(string)string into a Uint8Array\nwith UTF-8 encoded text.\nTextEncoder.prototype.encodeInto(string,\nuint8Array)string to UTF-8,\nputs the result into destination Uint8Array, and\nreturns a dictionary object that shows the progress of the encoding.\nThe dictionary object contains two members:\n\nreadstring\nconverted to UTF-8\nwrittenUint8Array\n\n
\n
clearTimeout() |
setTimeout() |
\n
clearTimeout(timeout)timeout object\ncreated by setTimeout().\nsetTimeout(function,\nmilliseconds[,\nargument1,\nargumentN])function\nafter a specified number of milliseconds.\nOne or more optional arguments\ncan be passed to the specified function.\nReturns a timeout object.\n\nfunction handler(v)\n{\n // ...\n}\n\nt = setTimeout(handler, 12);\n\n// ...\n\nclearTimeout(t);\n\n\n
\n
atob() |
btoa() |
\n
atob(encodedData)Base64 encoding.\nThe encodedData parameter is a binary string\nthat contains Base64-encoded data.\nReturns a string that contains decoded data from encodedData.\n\nThe similar btoa() method\ncan be used to encode and transmit data\nwhich may otherwise cause communication problems,\nthen transmit it and use the atob() method\nto decode the data again.\nFor example, you can encode, transmit, and decode control characters\nsuch as ASCII values 0 through 31.\n
\nconst encodedData = btoa(\"text to encode\"); // encode a string\nconst decodedData = atob(encodedData); // decode the string\n
\n
\nbtoa(stringToEncode)stringToEncode parameter is a binary string to encode.\nReturns an ASCII string containing the Base64 representation of\nstringToEncode.\n\nThe method can be used to encode data\nwhich may otherwise cause communication problems, transmit it,\nthen use the atob() method\nto decode the data again.\nFor example, you can encode control characters\nsuch as ASCII values 0 through 31.\n
\nconst encodedData = btoa(\"text to encode\"); // encode a string\nconst decodedData = atob(encodedData); // decode the string\n
\n
\n\n
\n
\n
Buffer.alloc(size[,\nfill[,\nencoding]]))\nAllocates a new Buffer of a specified size.\nIf fill is not specified, the Buffer will be zero-filled.\nIf fill is specified,\nthe allocated Buffer will be initialized by calling\nbuf.fill(fill).\nIf fill and encoding are specified,\nthe allocated Buffer will be initialized by calling\nbuf.fill(fill,\nencoding).\n
\nThe fill parameter may be a\nstring,\nBuffer,\nUint8Array, or\ninteger.\n
Buffer.allocUnsafe(size)\nThe same as\nBuffer.alloc(),\nwith the difference that the memory allocated for the buffer is not initialized,\nthe contents of the new buffer is unknown and may contain sensitive data.\n
Buffer.byteLength(value[,\nencoding])encoding.\nThe value can be a\nstring,\nBuffer,\nTypedArray,\nDataView, or\nArrayBuffer.\nIf the value is a string,\nthe encoding parameter is its encoding, can be\nutf8,\nhex,\nbase64,\nbase64url;\nby default is utf8.\nBuffer.compare(buffer1,\nbuffer2)buffer1 with buffer2\nwhen sorting arrays of Buffer instances.\nReturns\n0 if\nbuffer1 is the same as buffer2,\n1 if\nbuffer2 should come before buffer1 when sorted, or\n-1 if\nbuffer2 should come after buffer1 when sorted.\nBuffer.concat(list[,\ntotalLength])totalLength is not specified,\nit is calculated from the Buffer instances in list by adding their lengths.\nIf totalLength is specified,\nit is coerced to an unsigned integer.\nIf the combined length of the Buffers in list exceeds\ntotalLength,\nthe result is truncated to totalLength.\nBuffer.from(array)0 – 255.\nArray entries outside that range will be truncated.\nBuffer.from(arrayBuffer,\nbyteOffset[,\nlength]])ArrayBuffer\nwithout copying the underlying memory.\nThe optional byteOffset and length arguments\nspecify a memory range within the arrayBuffer\nthat will be shared by the Buffer.\nBuffer.from(buffer)Buffer.from(object[,\noffsetOrEncoding[,\nlength]])valueOf() function\nreturns a value not strictly equal to object,\nreturns\nBuffer.from(object.valueOf(),\noffsetOrEncoding,\nlength).\nBuffer.from(string[,\nencoding])string.\nThe encoding parameter identifies the character encoding\nto be used when converting a string into bytes.\nThe encoding can be\nutf8,\nhex,\nbase64,\nbase64url;\nby default is utf8.\nBuffer.isBuffer(object)true if object is a Buffer.\nBuffer.isEncoding(encoding)true\nif encoding is the name of a supported character encoding.\nbuffer[index]index in buffer.\nThe values refer to individual bytes,\nso the legal value range is between 0 and 255 (decimal).\nbuf.bufferArrayBuffer object\nbased on which this Buffer object is created.\nbuf.byteOffsetbyteOffset of the Buffers\nunderlying ArrayBuffer object.\nbuf.compare(target[,\ntargetStart[,\ntargetEnd[,\nsourceStart[,\nsourceEnd]]]])target and returns a number\nindicating whether buffer comes before, after, or is the same\nas target in sort order.\nComparison is based on the actual sequence of bytes in each Buffer.\nThe targetStart is an integer specifying\nthe offset within target at which to begin comparison,\nby default is 0.\nThe targetEnd is an integer specifying\nthe offset within target at which to end comparison,\nby default is target.length.\nThe sourceStart is an integer specifying\nthe offset within buffer at which to begin comparison,\nby default is 0.\nThe sourceEnd is an integer specifying\nthe offset within buffer at which to end comparison (not inclusive),\nby default is buf.length.\nbuf.copy(target[,\ntargetStart[,\nsourceStart[,\nsourceEnd]]])target,\neven if the target memory region overlaps with buffer.\nThe target parameter is a\nBuffer or Uint8Array to copy into.\n\n\nThe targetStart is an integer specifying\nthe offset within target at which to begin writing,\nby default is 0.\nThe sourceStart is an integer specifying\nthe offset within buffer from which to begin copying,\nby default is 0.\nThe sourceEnd is an integer specifying\nthe offset within buffer at which to stop copying (not inclusive)\nby default is buf.length.\n
buf.equals(otherBuffer)true if both Buffer and otherBuffer\nhave exactly the same bytes.\nbuf.fill(value[,\noffset[,\nend]][,\nencoding])value.\nIf the offset and end are not specified,\nthe entire Buffer will be filled.\nThe value is coerced to uint32 if it is not a\nstring,\nBuffer, or\ninteger.\nIf the resulting integer is greater than 255,\nthe Buffer will be filled with value and 255.\nbuf.includes(value[,\nbyteOffset][,\nencoding])buf.indexOf()\n!== -1,\nreturns true if the value was found\nin Buffer.\nbuf.indexOf(value[,\nbyteOffset][,\nencoding])value in Buffer, or -1\nif Buffer does not contain value.\nThe value can be a\nstring with specified encoding\n(by default utf8),\nBuffer,\nUnit8Array,\nor a number between 0 and 255.\nbuf.lastIndexOf(value[,\nbyteOffset][,\nencoding])buf.indexOf(),\nexcept the last occurrence of the value is found\ninstead of the first occurrence.\nThe value can be a string, Buffer, or\ninteger between 1 and 255.\nIf the value is an empty string or empty Buffer,\nbyteOffset will be returned.\nbuf.lengthbuf.readIntBE(offset,\nbyteLength)byteLength from buf\nat the specified offset\nand interprets the result as a big-endian,\ntwo's complement signed value supporting up to 48 bits of accuracy.\nThe byteLength parameter is an integer between 1 and 6\nspecifying the number of bytes to read.\n\nThe similar methods are also supported:\nbuf.readInt8([offset]),\nbuf.readInt16BE([offset]),\nbuf.readInt32BE([offset]).\n
buf.readIntLE(offset,\nbyteLength)byteLength from buf\nat the specified offset\nand interprets the result as a little-endian,\ntwo's complement signed value supporting up to 48 bits of accuracy.\nThe byteLength parameter is an integer between 1 and 6\nspecifying the number of bytes to read.\n\nThe similar methods are also supported:\nbuf.readInt8([offset]),\nbuf.readInt16LE([offset]),\nbuf.readInt32LE([offset]).\n
buf.readUIntBE(offset,\nbyteLength)byteLength from buf\nat the specified offset\nand interprets the result as a big-endian\ninteger supporting up to 48 bits of accuracy.\nThe byteLength parameter is an integer between 1 and 6\nspecifying the number of bytes to read.\n\nThe similar methods are also supported:\nbuf.readUInt8([offset]),\nbuf.readUInt16BE([offset]),\nbuf.readUInt32BE([offset]).\n
buf.readUIntLE(offset,\nbyteLength)byteLength from buf\nat the specified offset\nand interprets the result as a little-endian\ninteger supporting up to 48 bits of accuracy.\nThe byteLength parameter is an integer between 1 and 6\nspecifying the number of bytes to read.\n\nThe similar methods are also supported:\nbuf.readUInt8([offset]),\nbuf.readUInt16LE([offset]),\nbuf.readUInt32LE([offset]).\n
buf.readDoubleBE([offset])buf\nat the specified offset.\nbuf.readDoubleLE([offset])buf\nat the specified offset.\nbuf.readFloatBE([offset])buf\nat the specified offset.\nbuf.readFloatLE([offset])buf\nat the specified offset.\nbuf.subarray([start[,\nend]])buf\nthat references the same memory as the original,\nbut offset and cropped by\nstart and end.\nIf end is greater than\nbuf.length,\nthe same result as that of end equal to\nbuf.length\nis returned.\nbuf.slice([start[,\nend]])buf\nthat references the same memory as the original,\nbut offset and cropped by the\nstart and end values.\nThe method is not compatible with the\nUint8Array.prototype.slice(),\nwhich is a superclass of Buffer.\nTo copy the slice, use\nUint8Array.prototype.slice().\nbuf.swap16()buf as an array of unsigned 16-bit numbers\nand swaps the byte order in-place.\nThrows an error if\nbuf.length\nis not a multiple of 2.\nbuf.swap32()buf as an array of unsigned 32-bit numbers\nand swaps the byte order in-place.\nThrows an error if\nbuf.length\nis not a multiple of 4.\nbuf.swap64()buf as an array of 64-bit numbers\nand swaps byte order in-place.\nThrows an error if\nbuf.length\nis not a multiple of 8.\nbuf.toJSON()buf.\nJSON.stringify()\nimplicitly calls this function when stringifying a Buffer instance.\nbuf.toString([encoding[,\nstart[,\nend]]])buf to a string\naccording to the specified character encoding\nwhich can be utf8,\nhex,\nbase64,\nbase64url.\nThe start and end parameters\nmay be passed to decode only a subset of Buffer.\nbuf.write(string[,\noffset[,\nlength]][,\nencoding])string to buf\nat offset\naccording to the character encoding.\nThe length parameter is the number of bytes to write.\nIf Buffer did not contain enough space to fit the entire string,\nonly part of string will be written,\nhowever, partially encoded characters will not be written.\nThe encoding can be\nutf8,\nhex,\nbase64,\nbase64url.\nbuf.writeIntBE(value,\noffset,\nbyteLength)byteLength bytes of value\nto buf\nat the specified offset as big-endian.\nSupports up to 48 bits of accuracy.\nThe byteLength parameter is an integer between 1 and 6\nspecifying the number of bytes to read.\n\nThe following similar methods are also supported:\nbuf.writeInt8,\nbuf.writeInt16BE,\nbuf.writeInt32BE.\n
buf.writeIntLE(value,\noffset,\nbyteLength)byteLength bytes of value\nto buf\nat the specified offset as little-endian.\nSupports up to 48 bits of accuracy.\nThe byteLength parameter is an integer between 1 and 6\nspecifying the number of bytes to read.\n\nThe following similar methods are also supported:\nbuf.writeInt8,\nbuf.writeInt16LE,\nbuf.writeInt32LE.\n
buf.writeUIntBE(value,\noffset,\nbyteLength)byteLength bytes of value\nto buf\nat the specified offset as big-endian.\nSupports up to 48 bits of accuracy.\nThe byteLength parameter is an integer between 1 and 6\nspecifying the number of bytes to read.\n\nThe following similar methods are also supported:\nbuf.writeUInt8,\nbuf.writeUInt16BE,\nbuf.writeUInt32BE.\n
buf.writeUIntLE(value,\noffset,\nbyteLength)byteLength bytes of value\nto buf\nat the specified offset as little-endian.\nSupports up to 48 bits of accuracy.\nThe byteLength parameter is an integer between 1 and 6\nspecifying the number of bytes to read.\n\nThe following similar methods are also supported:\nbuf.writeUInt8,\nbuf.writeUInt16LE,\nbuf.writeUInt32LE.\n
buf.writeDoubleBE(value,\n[offset])value to buf\nat the specified offset as big-endian.\nbuf.writeDoubleLE(value,\n[offset])value to buf\nat the specified offset as little-endian.\nbuf.writeFloatBE(value,\n[offset])value to buf\nat the specified offset as big-endian.\nbuf.writeFloatLE(value,\n[offset])value to buf\nat the specified offset as little-endian.\n\n
\n
crypto.createHash() |
crypto.createHmac() |
\n
\nSince 0.7.0,\nextended crypto API is available as a global\ncrypto object.\n
\nThe Crypto module provides cryptographic functionality support.\nThe Crypto module object is imported using import crypto from 'crypto'.\n
\nSince 0.9.7,\nthe Crypto module requires OpenSSL\nand uses OpenSSL EVP for hashing,\nmaking any digest algorithm supported by the linked OpenSSL library\navailable to JavaScript code.\n
\n
\n
crypto.createHash(algorithm)algorithm.\nThe algorithm can be\nmd5,\nsha1,\nsha256,\nsha384,\nsha512,\nand any other digest supported by the linked OpenSSL library\n(since 0.9.7).\nBefore version 0.9.7,\nonly md5, sha1,\nand sha256 were supported.\ncrypto.createHmac(algorithm,\nsecret key)algorithm and secret key.\nThe algorithm can be\nmd5,\nsha1,\nsha256,\nsha384,\nsha512,\nand any other digest supported by the linked OpenSSL library\n(since 0.9.7).\nBefore version 0.9.7,\nonly md5, sha1,\nand sha256 were supported.\n\n
\n
hash.update() |
hash.digest() |
\n
hash.update(data)data.\nhash.digest([encoding])hash.update().\nThe encoding can be\nhex,\nbase64, and\nbase64url.\nIf encoding is not provided, a Buffer object\n(0.4.4) is returned.\n\nBefore version (0.4.4),\na byte string was returned instead of a Buffer object.\n\n
hash.copy()\n
\n
\nimport crypto from 'crypto';\n\ncrypto.createHash('sha1').update('A').update('B').digest('base64url');\n/* BtlFlCqiamG-GMPiK_GbvKjdK10 */\n\n
\n
hmac.update() |
hmac.digest() |
\n
hmac.update(data)data.\nhmac.digest([encoding])hmac.update().\nThe encoding can be\nhex,\nbase64, and\nbase64url.\nIf encoding is not provided, a Buffer object\n(0.4.4) is returned.\n\nBefore version 0.4.4,\na byte string was returned instead of a Buffer object.\n\n
\n
\n
\nimport crypto from 'crypto';\n\ncrypto.createHmac('sha1', 'secret.key').update('AB').digest('base64url');\n/* Oglm93xn23_MkiaEq_e9u8zk374 */\n\n
\n
\n
fs.Dirent |
fs.FileHandle |
fs.Stats |
File Access Constants |
File System Flags |
\nThe File System module provides operations with files.\n
\nThe module object is imported using import fs from 'fs'.\nSince 0.3.9,\npromissified versions of file system methods are available through\nfs.promises object after importing with import fs from 'fs':\n
\nimport fs from 'fs';\n\nfs.promises.readFile(\"/file/path\").then((data) => {\n /* <file data> */\n});\n\n
accessSync(path[,\nmode])path\n(0.3.9).\nIf the check fails, an error will be returned,\notherwise, the method will return undefined.\nmodefs.constants.F_OK\n\ntry {\n fs.accessSync('/file/path', fs.constants.R_OK | fs.constants.W_OK);\n console.log('has access');\n} catch (e) {\n console.log('no access');)\n}\n\nappendFileSync(filename,\ndata[, options])data\nto a file with provided filename.\nThe data is expected to be a string\nor a Buffer object (0.4.4).\nIf the file does not exist, it will be created.\nThe options parameter is expected to be\nan object with the following keys:\nmode0o666\nflaga\ncloseSync(fd)fd file descriptor represented by an integer\nused by the method.\nReturns undefined.\nexistsSync(path)true if the specified path exists.\n(0.8.2)\nfstatSync(fd)fs.Stats object\nfor the file descriptor\n(0.7.7).\nThe fd parameter is an integer\nrepresenting the file descriptor used by the method.\nlstatSync(path[,\noptions])fs.Stats object\nfor the symbolic link referred to by path\n(0.7.1).\nThe options parameter is expected to be\nan object with the following keys:\nthrowIfNoEntryundefined,\nby default is false.\nmkdirSync(path[,\noptions])path\n(0.4.2).\nThe options parameter is expected to be an\ninteger that specifies\nthe mode,\nor an object with the following keys:\nmode0o777.\nopenSync(path[,\nflags[, mode]])path\n(0.7.7).\nflagsr\nmode0o666\npromises.open(path[,\nflags[, mode]])FileHandle object\nrepresenting the opened file path\n(0.7.7).\nflagsr\nmode0o666\nreaddirSync(path[,\noptions])path\n(0.4.2).\nThe options parameter is expected to be\na string that specifies encoding\nor an object with the following keys:\n\nreadFileSync(filename[,\noptions])filename.\nThe options parameter holds\nstring that specifies encoding.\nIf an encoding is specified, a string is returned,\notherwise, a Buffer object\n(0.4.4) is returned.\n\nBefore version 0.4.4,\na byte string was returned\nif encoding was not specified.\n\nOtherwise,
options is expected to be\nan object with the following keys:\nencodingutf8,\nhex\n(0.4.4),\nbase64\n(0.4.4),\nbase64url\n(0.4.4).\nflagr\n\nimport fs from 'fs';\n\nvar file = fs.readFileSync('/file/path.tar.gz');\nconsole.log(file.slice(0,2).toString('hex')) /* '1f8b' */\n\nreadlinkSync(path[,\noptions])path\nusing\nreadlink(2)\n(0.8.7).\nThe options argument can be a string specifying an encoding,\nor an object with encoding property\nspecifying the character encoding to use.\nIf the encoding is buffer,\nthe result is returned as a Buffer object,\notherwise as a string.\nreadSync(fd,\nbuffer, offset[,\nlength[, position]])fd,\nreturns the number of bytes read\n(0.7.7).\n\nbufferbuffer value can be a\nBuffer,\nTypedArray, or\nDataView\noffsetinteger representing\nthe position in buffer to write the data to\nlengthinteger representing\nthe number of bytes to read\npositioninteger or\nnull,\nby default is null.\nIf position is null,\ndata will be read from the current file position,\nand the file position will be updated.\nIf position is an integer,\nthe file position will be unchanged\nrealpathSync(path[,\noptions])., .. and symbolic links using\nrealpath(3).\nThe options argument can be a string specifying an encoding,\nor an object with an encoding property specifying the character encoding\nto use for the path passed to the callback\n(0.3.9).\nrenameSync(oldPath,\nnewPath)oldPath to newPath\n(0.3.4).\n\nimport fs from 'fs';\n\nfs.renameSync('hello.txt', 'HelloWorld.txt');\n\nrmdirSync(path)path\n(0.4.2).\nstatSync(path,[\noptions])fs.Stats object\nfor the specified path\n(0.7.1).\nThe path can be a\nstring or\nbuffer.\nThe options parameter is expected to be\nan object with the following keys:\nthrowIfNoEntryundefined,\nby default is true.\nsymlinkSync(target,\npath)path\npointing to target using\nsymlink(2)\n(0.3.9).\nRelative targets are relative to the link’s parent directory.\nunlinkSync(path)path\n(0.3.9).\nwriteFileSync(filename,\ndata[,\noptions])data to a file\nwith provided filename.\nThe data is expected to be a string\nor a Buffer object (0.4.4).\nIf the file does not exist, it will be created,\nif the file exists, it will be replaced.\nThe options parameter is expected to be\nan object with the following keys:\nmode0o666\nflagw\n\nimport fs from 'fs';\n\nfs.writeFileSync('hello.txt', 'Hello world');\n\nwriteSync(fd,\nbuffer, offset[,\nlength[, position]])number of bytes written\n(0.7.7).\n\nfdinteger representing the file descriptor\nbufferbuffer value can be a\nBuffer,\nTypedArray, or\nDataView\noffsetinteger that determines\nthe part of the buffer to be written,\nby default 0\nlengthinteger specifying the number of bytes to write,\nby default is an offset of\nBuffer.byteLength\npositioninteger or\nnull,\nby default is null.\nSee also\npwrite(2).\nwriteSync(fd,\nstring[,\nposition[,\nencoding]])string to a file\nusing file descriptor fd,\nreturns the number of bytes written\n(0.7.7).\n\nfdinteger representing a file descriptor\npositioninteger or\nnull, by default is null.\nSee also\npwrite(2)\nencodingstring,\nby default is utf8\n\n
\nfs.Dirent is a representation of a directory entry — \na file or a subdirectory.\nWhen\nreaddirSync()\nis called with the\nwithFileTypes\noption,\nthe resulting array contains fs.Dirent objects.\n\n
dirent.isBlockDevice() — returns\ntrue if the fs.Dirent object describes\na block device.\ndirent.isCharacterDevice() — returns\ntrue if the fs.Dirent object describes\na character device.\ndirent.isDirectory() — returns\ntrue if the fs.Dirent object describes\na file system directory.\ndirent.isFIFO() — returns\ntrue if the fs.Dirent object describes\na first-in-first-out (FIFO) pipe.\ndirent.isFile() — returns\ntrue if the fs.Dirent object describes\na regular file.\ndirent.isSocket() — returns\ntrue if the fs.Dirent object describes\na socket.\ndirent.isSymbolicLink() — returns\ntrue if the fs.Dirent object describes\na symbolic link.\ndirent.name — \nthe name of the file fs.Dirent object refers to.\n\n
\n
filehandle.close() |
filehandle.fd |
filehandle.read() |
filehandle.stat() |
filehandle.write( |
filehandle.write( |
\nThe FileHandle object is an object wrapper\nfor a numeric file descriptor\n(0.7.7).\nInstances of the FileHandle object are created by the\nfs.promises.open() method.\nIf a FileHandle is not closed using the\nfilehandle.close() method,\nit will try to automatically close the file descriptor,\nhelping to prevent memory leaks.\nPlease do not rely on this behavior because it can be unreliable.\nInstead, always explicitly close a FileHandle.\n
\n
filehandle.close()promise, fulfills with undefined upon success.\nfilehandle.fdFileHandle object.\nfilehandle.read(buffer,\noffset[,\nlength[,\nposition]])bufferBuffer,\nTypedArray, or\nDataView\noffsetinteger\nrepresenting the location in the buffer at which to start filling\nlengthinteger\nrepresenting the number of bytes to read\npositioninteger,\nnull.\nIf null, data will be read from the current file position\nand the position will be updated.\nIf position is an integer,\nthe current file position will remain unchanged.\nPromise which fulfills upon success\nwith an object with two properties:\nbytesReadinteger representing the number of bytes read\nbufferBuffer,\nTypedArray, or\nDataView\nfilehandle.stat()promise.\nfilehandle.write(buffer,\noffset[,\nlength[,\nposition]])bufferbuffer value can be a\nBuffer,\nTypedArray, or\nDataView\noffsetinteger representing\nthe start position from within buffer where the data to write begins\nlengthinteger representing\nthe number of bytes from buffer to write, by default\nis an offset of\nBuffer.byteLength\npositioninteger or\nnull,\nby default is null.\nIf position is not a number,\nthe data will be written at the current position.\nSee the POSIX\npwrite(2)\ndocumentation for details.\nPromise which is resolved with an object\ncontaining two properties:\nbytesWritteninteger representing the number of bytes written\nbufferBuffer,\nTypedArray, or\nDataView\n\n
\nIt is unsafe to use filehandle.write() multiple times\non the same file without waiting for the promise to be resolved or rejected.\n\n
\n\nfilehandle.write(string[,\nposition[,\nencoding]])string to the file.\n\npositioninteger or\nnull,\nby default is null.\nIf position is not a number,\nthe data will be written at the current position.\nSee the POSIX\npwrite(2)\ndocumentation for details.\nencodingutf8\nPromise which is resolved with an object\ncontaining two properties:\nbytesWritteninteger representing the number of bytes written\nbufferBuffer,\nTypedArray, or\nDataView\n\n
\nIt is unsafe to use filehandle.write() multiple times\non the same file without waiting for the promise to be resolved or rejected.\n\n
\n\n\n
\nThe fs.Stats object provides information about a file.\nThe object is returned from\nfs.statSync() and\nfs.lstatSync().\n\n
stats.isBlockDevice() — returns\ntrue if the fs.Stats object describes\na block device.\nstats.isDirectory() — returns\ntrue if the fs.Stats object describes\na file system directory.\nstats.isFIFO() — returns\ntrue if the fs.Stats object describes\na first-in-first-out (FIFO) pipe.\nstats.isFile() — returns\ntrue if the fs.Stats object describes\na regular file.\nstats.isSocket() — returns\ntrue if the fs.Stats object describes\na socket.\nstats.isSymbolicLink() — returns\ntrue if the fs.Stats object describes\na symbolic link.\nstats.dev — \nthe numeric identifier of the device containing the file.\nstats.ino — \nthe file system specific Inode number for the file.\nstats.mode — \na bit-field describing the file type and mode.\nstats.nlink — \nthe number of hard-links that exist for the file.\nstats.uid — \nthe numeric user identifier of the user that owns the file (POSIX).\nstats.gid — \nthe numeric group identifier of the group that owns the file (POSIX).\nstats.rdev — \nthe numeric device identifier if the file represents a device.\nstats.size — \nthe size of the file in bytes.\nstats.blksize — \nthe file system block size for i/o operations.\nstats.blocks — \nthe number of blocks allocated for this file.\nstats.atimeMs — \nthe timestamp indicating the last time this file was accessed expressed\nin milliseconds since the POSIX Epoch.\nstats.mtimeMs — \nthe timestamp indicating the last time this file was modified expressed\nin milliseconds since the POSIX Epoch.\nstats.ctimeMs — \nthe timestamp indicating the last time this file was changed expressed\nin milliseconds since the POSIX Epoch.\nstats.birthtimeMs — \nthe timestamp indicating the creation time of this file expressed\nin milliseconds since the POSIX Epoch.\nstats.atime — \nthe timestamp indicating the last time this file was accessed.\nstats.mtime — \nthe timestamp indicating the last time this file was modified.\nstats.ctime — \nthe timestamp indicating the last time this file was changed.\nstats.birthtime — \nthe timestamp indicating the creation time of this file.\n\n
\nThe access() method\ncan accept the following flags.\nThese flags are exported by fs.constants:\n\n
F_OK — indicates that the file\nis visible to the calling process,\nused by default if no mode is specified\nR_OK — indicates that the file can be\nread by the calling process\nW_OK — indicates that the file can be\nwritten by the calling process\nX_OK — indicates that the file can be\nexecuted by the calling process\n\n
\nThe flag option can accept the following values:\n\n
a — open a file for appending.\nThe file is created if it does not exist\nax — the same as a\nbut fails if the file already exists\na+ — open a file for reading and appending.\nIf the file does not exist, it will be created\nax+ — the same as a+\nbut fails if the file already exists\nas — open a file for appending\nin synchronous mode.\nIf the file does not exist, it will be created\nas+ — open a file for reading and appending\nin synchronous mode.\nIf the file does not exist, it will be created\nr — open a file for reading.\nAn exception occurs if the file does not exist\nr+ — open a file for reading and writing.\nAn exception occurs if the file does not exist\nrs+ — open a file for reading and writing\nin synchronous mode.\nInstructs the operating system to bypass the local file system cache\nw — open a file for writing.\nIf the file does not exist, it will be created.\nIf the file exists, it will be replaced\nwx — the same as w\nbut fails if the file already exists\nw+ — open a file for reading and writing.\nIf the file does not exist, it will be created.\nIf the file exists, it will be replaced\nwx+ — the same as w+\nbut fails if the file already exists\n\n
\n
querystring.decode() |
querystring.encode() |
querystring.escape() |
querystring.parse() |
querystring.stringify() |
querystring.unescape() |
\nThe Query String module provides support\nfor parsing and formatting URL query strings\n(0.4.3).\nThe Query String module object is imported using\nimport qs from 'querystring'.\n
\n
querystring.decode()querystring.parse().\nquerystring.encode()querystring.stringify().\nquerystring.escape(string)\nPerforms URL encoding of the given string,\nreturns an escaped query string.\nThe method is used by\nquerystring.stringify()\nand should not be used directly.\n
querystring.parse(string[,\nseparator[,\nequal[,\noptions]]])\nParses the query string URL and returns an object.\n
\n\n\nThe separator parameter is a substring\nfor delimiting key and value pairs in the query string,\nby default is “&”.\n
\nThe equal parameter is a substring\nfor delimiting keys and values in the query string,\nby default is “=”.\n
\nThe options parameter is expected to be\nan object with the following keys:\n
decodeURIComponent\nfunctionquerystring.unescape()\nmaxKeys\nnumber1000.\nThe 0 value removes limitations for counting keys.\n \nBy default, percent-encoded characters within the query string are assumed\nto use the UTF-8 encoding,\ninvalid UTF-8 sequences will be replaced with\nthe U+FFFD replacement character.\n
\nFor example, for the following query string\n
\n'foo=bar&abc=xyz&abc=123'\n
\nthe output will be:\n
\n{\n foo: 'bar',\n abc: ['xyz', '123']\n}\n\n
\n\nquerystring.stringify(object[,\nseparator[,\nequal[,\noptions]]])\nSerializes an object and returns a URL query string.\n
\n\n\nThe separator parameter is a substring\nfor delimiting key and value pairs in the query string,\nby default is “&”.\n
\nThe equal parameter is a substring\nfor delimiting keys and values in the query string,\nby default is “=”.\n
\nThe options parameter is expected to be\nan object with the following keys:\n
encodeURIComponent\nfunctionquerystring.escape().\n\n
\n\n\nBy default, characters that require percent-encoding within the query string\nare encoded as UTF-8.\nIf other encoding is required, then\nencodeURIComponent option should be specified.\n
\nFor example, for the following command\n
\nquerystring.stringify({ foo: 'bar', baz: ['qux', 'quux'], 123: '' });\n\nthe query string will be:\n
\n'foo=bar&baz=qux&baz=quux&123='\n
\n
\n\nquerystring.unescape(string)\nPerforms decoding of URL percent-encoded characters\nof the string,\nreturns an unescaped query string.\nThe method is used by\nquerystring.parse()\nand should not be used directly.\n
\n
\n
xml.parse() |
xml.c14n() |
xml.exclusiveC14n() |
xml.serialize() |
xml.serializeToString() |
XMLDoc |
XMLNode |
XMLAttr |
\nThe XML module allows working with XML documents\n(since 0.7.10).\nThe XML module object is imported using\nimport xml from 'xml'.\n
\nExample:\n
\nimport xml from 'xml';\n\nlet data = `<note><to b=\"bar\" a= \"foo\" >Tove</to><from>Jani</from></note>`;\nlet doc = xml.parse(data);\n\nconsole.log(doc.note.to.$text) /* 'Tove' */\nconsole.log(doc.note.to.$attr$b) /* 'bar' */\nconsole.log(doc.note.$tags[1].$text) /* 'Jani' */\n\nlet dec = new TextDecoder();\nlet c14n = dec.decode(xml.exclusiveC14n(doc.note));\nconsole.log(c14n) /* '<note><to a=\"foo\" b=\"bar\">Tove</to><from>Jani</from></note>' */\n\nc14n = dec.decode(xml.exclusiveC14n(doc.note.to));\nconsole.log(c14n) /* '<to a=\"foo\" b=\"bar\">Tove</to>' */\n\nc14n = dec.decode(xml.exclusiveC14n(doc.note, doc.note.to /* excluding 'to' */));\nconsole.log(c14n) /* '<note><from>Jani</from></note>' */\n
\n
\n
parse(string |\nBuffer)XMLDoc wrapper object\nrepresenting the parsed XML document.\nc14n(root_node[,\nexcluding_node])root_node and its children according to\nCanonical XML Version 1.1.\nThe root_node can be\nXMLNode or\nXMLDoc wrapper object\naround XML structure.\nReturns Buffer object that contains canonicalized output.\n\n\n
excluding_node\n
\n\nexclusiveC14n(root_node[,\nexcluding_node[,\nwithComments\n[,prefix_list]]])root_node and its children according to\nExclusive XML\nCanonicalization Version 1.0.\n\n\n
root_nodeXMLNode or\nXMLDoc wrapper object\naround XML structure\nexcluding_nodewithCommentsfalse by default.\nIf true, canonicalization corresponds to\nExclusive XML\nCanonicalization Version 1.0.\nReturns Buffer object that contains canonicalized output.\nprefix_list\n
\n\nserialize()xml.c14n()\n(since 0.7.11).\nserializeToString()xml.c14n()\nexcept it returns the result as a string\n(since 0.7.11).\nXMLDoc\n
doc.$rootdoc.abcabc as\nXMLNode wrapper object\n\n
\n\nXMLNode\n
node.abcnode.$tag$abc\nnode.$attr$abcabc,\nwritable\nsince 0.7.11\nnode.$attr$abc=xyznode.setAttribute('abc',\nxyz)\n(since 0.7.11)\nnode.$attrsXMLAttr wrapper object\nfor all attributes of the node\nnode.$namenode.$nsnode.$parentnode.$tag$abcabc,\nwritable\nsince 0.7.11\nnode.removeChildren();\nnode.addChild(node1);\nnode.addChild(node2)\n(since 0.7.11).\nabc of the node,\nwritable\nsince 0.7.11\nnode.$textnode.$text = 'abc' node.setText('abc')\n(since 0.7.11)\nnode.addChild(nd)nd is recursively copied before adding to the node\nnode.removeAllAttributes()node.removeAttribute(attr_name)attr_name\n(since 0.7.11)\nnode.removeChildren(tag_name)tag_name\n(since 0.7.11).\nIf tag_name is absent, all children tags are removed\nnode.removeText()node.setAttribute(attr_name,\nvalue)attr_name\n(since 0.7.11).\nWhen the value is null,\nthe attribute named attr_name is deleted\nnode.setText(value)null, the text of the node is deleted.\n\n
\n\nXMLAttr\n
attr.abcabc\n\n
\n\n\n
\n
zlib.deflateRawSync() |
zlib.deflateSync() |
zlib.inflateRawSync() |
zlib.inflateSync() |
\nThe zlib module provides compression functionality using the\n“deflate” and “inflate” algorithms\n(since 0.7.12).\nThe zlib module object is imported using\nimport zlib from 'zlib'.\n
\n
deflateRawSync(string |\nBuffer[,\noptions])Buffer,\nTypedArray, or\nDataView.\nOptions is an optional object that contains\nzlib_options.\nReturns Buffer instance that contains the compressed data.\ndeflateSync(string |\nBuffer[,\noptions])Buffer,\nTypedArray, or\nDataView.\nOptions is an optional object that contains\nzlib_options.\nReturns Buffer instance that contains the compressed data.\ninflateRawSync(string |\nBuffer)inflateSync(string |\nBuffer)\n
\n
chunkSize — is an integer,\nby default is 1024\ndictionary — is a\nBuffer,\nTypedArray, or\nDataView.\nby default is empty\nlevel — is an integer, compression only,\nsee zlib_compression_levels\nmemLevel — is an integer\nfrom 1 to 9, compression only\nstrategy — is an integer, compression only,\nsee zlib_compression_strategy\nwindowBits — is an integer\nfrom -15 to -9\nfor raw data,\nfrom 9 to 15\nfor an ordinary stream\n\n
\n
| Name | Description |
zlib.constants.Z_NO_COMPRESSION | no compression |
zlib.constants.Z_BEST_SPEED | fastest, produces the least compression |
zlib.constants.Z_DEFAULT_COMPRESSION | trade-off between speed and compression |
zlib.constants.Z_BEST_COMPRESSION | slowest, produces the most compression |
\n
| Name | Description |
zlib.constants.Z_FILTERED | Filtered strategy: for the data produced by a filter or predictor |
zlib.constants.Z_HUFFMAN_ONLY | Huffman-only strategy: only Huffman encoding, no string matching |
zlib.constants.Z_RLE | Run Length Encoding strategy: limit match distances to one, better compression of PNG image data |
zlib.constants.Z_FIXED | Fixed table strategy: prevents the use of dynamic Huffman codes, a simpler decoder for special applications |
zlib.constants.Z_DEFAULT_STRATEGY | Default strategy, suitable for general purpose compression |
\nAll nginx security issues should be reported to\nF5SIRT@f5.com\nor via one of the methods listed\nhere.\n
\nPatches are signed using one of the\nPGP public keys.\n
\nnjs does not evaluate dynamic code,\nespecially code received from the network, in any way.\nThe only way to evaluate that code using njs\nis to configure the\njs_import\ndirective in nginx.\nJavaScript code is loaded once during nginx start.\n
\nIn the nginx/njs threat model, JavaScript code is considered a trusted source\nin the same way as nginx.conf and sites certificates.\nWhat this means in practice:\n\n
nginx.conf,\nnginx is safe from JavaScript-related vulnerabilities\n\n
Heap buffer overflow in js_fetch_proxy
Severity: medium
Advisory
CVE-2026-8711
Not vulnerable: 0.9.9+
Vulnerable: 0.9.4-0.9.8
| Compiling TypeScript definition files API checks and autocompletions Writing njs type-safe code |
\nTypeScript is\na typed superset of JavaScript\nthat compiles to plain JavaScript.\n
\nTypeScript supports definition files that contain\ntype information of existing JavaScript libraries.\nThis enables other programs to use the values defined in the files\nas if they were statically typed TypeScript entities.\n
\nnjs provides TypeScript definition files for its\nAPI which can be used to:\n
\n
\n
\n$ git clone https://github.com/nginx/njs\n$ cd njs && ./configure && make ts\n$ ls build/ts/\nnjs_core.d.ts\nnjs_shell.d.ts\nngx_http_js_module.d.ts\nngx_stream_js_module.d.ts\n
\n
\nPut *.d.ts files to a place where you editor can find it.\n
\ntest.js:\n
\n/// <reference path=\"ngx_http_js_module.d.ts\" />\n/**\n * @param {NginxHTTPRequest} r\n * */\nfunction content_handler(r) {\n r.headersOut['content-type'] = 'text/plain';\n r.return(200, \"Hello\");\n}\n\n
\ntest.ts:\n
\n/// <reference path=\"ngx_http_js_module.d.ts\" />\nfunction content_handler(r: NginxHTTPRequest) {\n r.headersOut['content-type'] = 'text/plain';\n r.return(200, \"Hello from TypeScript\");\n}\n\nTypeScript installation:\n
\n# npm install -g typescript\n
\nTypeScript compilation:\n
\n$ tsc test.ts\n$ cat test.js\n
\nThe resulting test.js file can be used directly with njs.\n
| Example Configuration Directives allow deny |
\nThe ngx_stream_access_module module (1.9.2) allows\nlimiting access to certain client addresses.\n
\n
\nserver {\n ...\n deny 192.168.1.1;\n allow 192.168.1.0/24;\n allow 10.1.1.0/16;\n allow 2001:0db8::/32;\n deny all;\n}\n\n
\nThe rules are checked in sequence until the first match is found.\nIn this example, access is allowed only for IPv4 networks\n10.1.1.0/16 and 192.168.1.0/24\nexcluding the address 192.168.1.1,\nand for IPv6 network 2001:0db8::/32.\n
| \n Syntax:\n | \n\n allow \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nAllows access for the specified network or address.\nIf the special value unix: is specified,\nallows access for all UNIX-domain sockets.\n
| \n Syntax:\n | \n\n deny \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nDenies access for the specified network or address.\nIf the special value unix: is specified,\ndenies access for all UNIX-domain sockets.\n
\nThe ngx_stream_core_module module\nis available since version 1.9.0.\nThis module is not built by default, it should be enabled with the\n--with-stream\nconfiguration parameter.\n
\n
\nworker_processes auto;\n\nerror_log /var/log/nginx/error.log info;\n\nevents {\n worker_connections 1024;\n}\n\nstream {\n upstream backend {\n hash $remote_addr consistent;\n\n server backend1.example.com:12345 weight=5;\n server 127.0.0.1:12345 max_fails=3 fail_timeout=30s;\n server unix:/tmp/backend3;\n }\n\n upstream dns {\n server 192.168.0.1:53535;\n server dns.example.com:53;\n }\n\n server {\n listen 12345;\n proxy_connect_timeout 1s;\n proxy_timeout 3s;\n proxy_pass backend;\n }\n\n server {\n listen 127.0.0.1:53 udp reuseport;\n proxy_timeout 20s;\n proxy_pass dns;\n }\n\n server {\n listen [::1]:12345;\n proxy_pass unix:/tmp/stream.socket;\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n listen \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server\n | \n
\nSets the address and port for the socket\non which the server will accept connections.\nIt is possible to specify just the port.\nThe address can also be a hostname, for example:\n
\nlisten 127.0.0.1:12345;\nlisten *:12345;\nlisten 12345; # same as *:12345\nlisten localhost:12345;\n
\nIPv6 addresses are specified in square brackets:\n
\nlisten [::1]:12345;\nlisten [::]:12345;\n
\nUNIX-domain sockets are specified with the “unix:”\nprefix:\n
\nlisten unix:/var/run/nginx.sock;\n
\n
\nPort ranges (1.15.10) are specified with the\nfirst and last port separated by a hyphen:\n
\nlisten 127.0.0.1:12345-12399;\nlisten 12345-12399;\n
\n
\nThe default_server parameter, if present,\nwill cause the server to become the default server for the specified\naddress:port pair (1.25.5).\nIf none of the directives have the default_server\nparameter then the first server with the\naddress:port pair will be\nthe default server for this pair.\n
\nThe ssl parameter allows specifying that all\nconnections accepted on this port should work in SSL mode.\n
\nThe udp parameter configures a listening socket\nfor working with datagrams (1.9.13).\nIn order to handle packets from the same address and port in the same session,\nthe reuseport parameter\nshould also be specified.\n
\nThe proxy_protocol parameter (1.11.4)\nallows specifying that all connections accepted on this port should use the\nPROXY\nprotocol.\n
\nThe PROXY protocol version 2 is supported since version 1.13.11.\n
\n
\nThe listen directive\ncan have several additional parameters specific to socket-related system calls.\nThese parameters can be specified in any\nlisten directive, but only once for a given\naddress:port pair.\n
setfib=number\nSO_SETFIB option) for the listening socket.\nThis currently works only on FreeBSD.\nfastopen=number\n\nDo not enable this feature unless the server can handle\nreceiving the\n\nsame SYN packet with data more than once.\n\n
backlog=number\nbacklog parameter in the\nlisten() call that limits\nthe maximum length for the queue of pending connections (1.9.2).\nBy default,\nbacklog is set to -1 on FreeBSD, DragonFly BSD, and macOS,\nand to 511 on other platforms.\nrcvbuf=size\nSO_RCVBUF option) for the listening socket (1.11.13).\nsndbuf=size\nSO_SNDBUF option) for the listening socket (1.11.13).\naccept_filter=filter\nSO_ACCEPTFILTER option) for the listening socket\nthat filters incoming connections before passing them to\naccept() (1.25.5).\nThis works only on FreeBSD and NetBSD 5.0+.\nPossible values are\ndataready\nand\nhttpready.\ndeferred\naccept()\n(the TCP_DEFER_ACCEPT socket option) on Linux (1.25.5).\nbind\nbind()\ncall for a given address:port pair.\nThe fact is that if there are several listen directives with\nthe same port but different addresses, and one of the\nlisten directives listens on all addresses\nfor the given port (*:port), nginx will\nbind() only to *:port.\nIt should be noted that the getsockname() system call will be\nmade in this case to determine the address that accepted the connection.\nIf the setfib,\nfastopen,\nbacklog, rcvbuf,\nsndbuf, accept_filter,\ndeferred, ipv6only,\nreuseport, multipath,\nor so_keepalive parameters\nare used then for a given\naddress:port pair\na separate bind() call will always be made.\nipv6only=on|off\nIPV6_V6ONLY socket option)\nwhether an IPv6 socket listening on a wildcard address [::]\nwill accept only IPv6 connections or both IPv6 and IPv4 connections.\nThis parameter is turned on by default.\nIt can only be set once on start.\nreuseport\nSO_REUSEPORT socket option on Linux 3.9+ and DragonFly BSD,\nor SO_REUSEPORT_LB on FreeBSD 12+), allowing a kernel\nto distribute incoming connections between worker processes.\nThis currently works only on Linux 3.9+, DragonFly BSD,\nand FreeBSD 12+ (1.15.1).\n\nInappropriate use of this option may have its security\nimplications.\n\n
multipath\nIPPROTO_MPTCP) for the listening socket.\nThis currently works only on Linux 5.6+.\n\nAdding or removing this parameter will also enable\nthe SO_REUSEPORT socket option, which may have its security\nimplications.\n\nso_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]\non”, the\nSO_KEEPALIVE option is turned on for the socket.\nIf it is set to the value “off”, the\nSO_KEEPALIVE option is turned off for the socket.\nSome operating systems support setting of TCP keepalive parameters on\na per-socket basis using the TCP_KEEPIDLE,\nTCP_KEEPINTVL, and TCP_KEEPCNT socket options.\nOn such systems\n(currently, Linux, NetBSD, Dragonfly, FreeBSD, and macOS),\nthey can be configured\nusing the keepidle, keepintvl, and\nkeepcnt parameters.\nOne or two parameters may be omitted, in which case the system default setting\nfor the corresponding socket option will be in effect.\nFor example,\n\nwill set the idle timeout (so_keepalive=30m::10
TCP_KEEPIDLE) to 30 minutes,\nleave the probe interval (TCP_KEEPINTVL) at its system default,\nand set the probes count (TCP_KEEPCNT) to 10 probes.\n\n
\n
\nBefore version 1.25.5, different servers must listen on different\naddress:portpairs.\n
\n
| \n Syntax:\n | \n\n preread_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n preread_buffer_size 16k;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.11.5.\n
\nSpecifies a size of the\npreread buffer.\n
| \n Syntax:\n | \n\n preread_timeout \n | \n
|---|---|
| \n Default:\n | \n\n preread_timeout 30s;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.11.5.\n
\nSpecifies a timeout of the\npreread phase.\n
| \n Syntax:\n | \n\n proxy_protocol_timeout \n | \n
|---|---|
| \n Default:\n | \n\n proxy_protocol_timeout 30s;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.11.4.\n
\nSpecifies a timeout for\nreading the PROXY protocol header to complete.\nIf no entire header is transmitted within this time,\nthe connection is closed.\n
| \n Syntax:\n | \n\n resolver \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.11.3.\n
\nConfigures name servers used to resolve names of upstream servers\ninto addresses, for example:\n
\nresolver 127.0.0.1 [::1]:5353;\n
\nThe address can be specified as a domain name or IP address,\nwith an optional port.\nIf port is not specified, the port 53 is used.\nName servers are queried in a round-robin fashion.\n
\nBy default, nginx will look up both IPv4 and IPv6 addresses while resolving.\nIf looking up of IPv4 or IPv6 addresses is not desired,\nthe ipv4=off (1.23.1) or\nthe ipv6=off parameter can be specified.\n
\nBy default, nginx caches answers using the TTL value of a response.\nThe optional valid parameter allows overriding it:\n
\nresolver 127.0.0.1 [::1]:5353 valid=30s;\n
\n
\nTo prevent DNS spoofing, it is recommended\nconfiguring DNS servers in a properly secured trusted local network.\n
\n
\nThe optional status_zone parameter (1.17.1)\nenables\ncollection\nof DNS server statistics of requests and responses\nin the specified zone.\nThe parameter is available as part of our\ncommercial subscription.\n
\n
\nBefore version 1.11.3, this directive was available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n resolver_timeout \n | \n
|---|---|
| \n Default:\n | \n\n resolver_timeout 30s;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.11.3.\n
\nSets a timeout for name resolution, for example:\n
\nresolver_timeout 5s;\n
\n
\nBefore version 1.11.3, this directive was available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n server { ... }\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nSets the configuration for a virtual server.\nThere is no clear separation between IP-based (based on the IP address)\nand name-based (based on the\nTLS\nServer Name Indication extension (SNI, RFC 6066)) (1.25.5)\nvirtual servers.\nInstead, the listen directives describe all\naddresses and ports that should accept connections for the server, and the\nserver_name directive lists all server names.\n
| \n Syntax:\n | \n\n server_name \n | \n
|---|---|
| \n Default:\n | \n\n server_name \"\";\n | \n
| \n Context:\n | \n\n server\n | \n
This directive appeared in version 1.25.5.\n
\nSets names of a virtual server, for example:\n
\nserver {\n server_name example.com www.example.com;\n}\n\n
\nThe first name becomes the primary server name.\n
\nServer names can include an asterisk (“*”)\nreplacing the first or last part of a name:\n
\nserver {\n server_name example.com *.example.com www.example.*;\n}\n\nSuch names are called wildcard names.\n
\nThe first two of the names mentioned above can be combined in one:\n
\nserver {\n server_name .example.com;\n}\n\n
\nIt is also possible to use regular expressions in server names,\npreceding the name with a tilde (“~”):\n
\nserver {\n server_name www.example.com ~^www\\d+\\.example\\.com$;\n}\n\n
\nRegular expressions can contain captures that can later\nbe used in other directives:\n
\nserver {\n server_name ~^(www\\.)?(.+)$;\n\n proxy_pass www.$2:12345;\n}\n\n
\nNamed captures in regular expressions create variables\nthat can later be used in other directives:\n
\nserver {\n server_name ~^(www\\.)?(?<domain>.+)$;\n\n proxy_pass www.$domain:12345;\n}\n\n
\nIf the directive’s parameter is set to “$hostname”, the\nmachine’s hostname is inserted.\n
\nThe search is performed in the following order of priority\nand terminates on the first matching variant:\n
*.example.com”\nmail.*”\n\n
| \n Syntax:\n | \n\n server_names_hash_bucket_size \n | \n
|---|---|
| \n Default:\n | \n\n server_names_hash_bucket_size 32|64|128;\n | \n
| \n Context:\n | \n\n stream\n | \n
This directive appeared in version 1.25.5.\n
\nSets the bucket size for the server names hash tables.\nThe default value depends on the size of the processor’s cache line.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
| \n Syntax:\n | \n\n server_names_hash_max_size \n | \n
|---|---|
| \n Default:\n | \n\n server_names_hash_max_size 512;\n | \n
| \n Context:\n | \n\n stream\n | \n
This directive appeared in version 1.25.5.\n
\nSets the maximum size of the server names hash tables.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
| \n Syntax:\n | \n\n stream { ... }\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
\nProvides the configuration file context in which the stream server directives\nare specified.\n
| \n Syntax:\n | \n\n tcp_nodelay \n | \n
|---|---|
| \n Default:\n | \n\n tcp_nodelay on;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.9.4.\n
\nEnables or disables the use of the TCP_NODELAY option.\nThe option is enabled for both client and proxied server connections.\n
| \n Syntax:\n | \n\n variables_hash_bucket_size \n | \n
|---|---|
| \n Default:\n | \n\n variables_hash_bucket_size 64;\n | \n
| \n Context:\n | \n\n stream\n | \n
This directive appeared in version 1.11.2.\n
\nSets the bucket size for the variables hash table.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
| \n Syntax:\n | \n\n variables_hash_max_size \n | \n
|---|---|
| \n Default:\n | \n\n variables_hash_max_size 1024;\n | \n
| \n Context:\n | \n\n stream\n | \n
This directive appeared in version 1.11.2.\n
\nSets the maximum size of the variables hash table.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
\nThe ngx_stream_core_module module supports variables\nsince 1.11.2.\n
$binary_remote_addr$bytes_received$bytes_sent$connection$hostname$msec$nginx_version$pid$protocolTCP or UDP (1.11.4)\n$proxy_protocol_addr\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
$proxy_protocol_port\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
$proxy_protocol_server_addr\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
$proxy_protocol_server_port\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
$proxy_protocol_tlv_namename can be a TLV type name or its numeric value.\nIn the latter case, the value is hexadecimal\nand should be prefixed with 0x:\n\n\nSSL TLVs can also be accessed by TLV type name or its numeric value,\nboth prefixed by\n$proxy_protocol_tlv_alpn\n$proxy_protocol_tlv_0x01\n
ssl_:\n\n\n\n$proxy_protocol_tlv_ssl_version\n$proxy_protocol_tlv_ssl_0x21\n
\nThe following TLV type names are supported:\n
alpn (0x01) - \nupper layer protocol used over the connection\nauthority (0x02) - \nhost name value passed by the client\nunique_id (0x05) - \nunique connection id\nnetns (0x30) - \nname of the namespace\nssl (0x20) - \nbinary SSL TLV structure\n\n
\n\n\nThe following SSL TLV type names are supported:\n
ssl_version (0x21) - \nSSL version used in client connection\nssl_cn (0x22) - \nSSL certificate Common Name\nssl_cipher (0x23) - \nname of the used cipher\nssl_sig_alg (0x24) - \nalgorithm used to sign the certificate\nssl_key_alg (0x25) - \npublic-key algorithm\n\n
\n\n\nAlso, the following special SSL TLV type name is supported:\n
ssl_verify - \nclient SSL certificate verification result,\nzero if the client presented a certificate\nand it was successfully verified, and non-zero otherwise\n\n
\n\n\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
$remote_addr$remote_port$server_addr\nComputing a value of this variable usually requires one system call.\nTo avoid a system call, the listen directives\nmust specify addresses and use the bind parameter.\n
$server_port$session_time$status200400403500502503$time_iso8601$time_iso8601_ms\n
\nThis variable is available as part of our\ncommercial subscription.\n
\n
\n$time_local\n
\n\n| Example Configuration Directives geoip_country geoip_city geoip_org |
\nThe ngx_stream_geoip_module module (1.11.3) creates variables\nwith values depending on the client IP address, using the precompiled\nMaxMind databases.\n
\nWhen using the databases with IPv6 support,\nIPv4 addresses are looked up as IPv4-mapped IPv6 addresses.\n
\nThis module is not built by default, it should be enabled with the\n--with-stream_geoip_module\nconfiguration parameter.\n
\nThis module requires the\nMaxMind GeoIP library.\n
\n
\n\n\n\n
\nstream {\n geoip_country GeoIP.dat;\n geoip_city GeoLiteCity.dat;\n\n map $geoip_city_continent_code $nearest_server {\n default example.com;\n EU eu.example.com;\n NA na.example.com;\n AS as.example.com;\n }\n ...\n}\n\n
\n\n\n| \n Syntax:\n | \n\n geoip_country \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nSpecifies a database used to determine the country\ndepending on the client IP address.\nThe following variables are available when using this database:\n
$geoip_country_codeRU”, “US”.\n$geoip_country_code3\nRUS”, “USA”.\n$geoip_country_nameRussian Federation”, “United States”.\n\n
| \n Syntax:\n | \n\n geoip_city \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nSpecifies a database used to determine the country, region, and city\ndepending on the client IP address.\nThe following variables are available when using this database:\n
$geoip_area_code\nThis variable may contain outdated information since\nthe corresponding database field is deprecated.\n\n
$geoip_city_continent_codeEU”, “NA”.\n$geoip_city_country_code\nRU”, “US”.\n$geoip_city_country_code3\nRUS”, “USA”.\n$geoip_city_country_name\nRussian Federation”, “United States”.\n$geoip_dma_code$geoip_latitude$geoip_longitude$geoip_region48”, “DC”.\n$geoip_region_nameMoscow City”, “District of Columbia”.\n$geoip_cityMoscow”, “Washington”.\n$geoip_postal_code\n
| \n Syntax:\n | \n\n geoip_org \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nSpecifies a database used to determine the organization\ndepending on the client IP address.\nThe following variable is available when using this database:\n
$geoip_org\n
\n\n| Example Configuration Directives geo |
\nThe ngx_stream_geo_module module (1.11.3) creates variables\nwith values depending on the client IP address.\n
\n
\ngeo $geo {\n default 0;\n\n 127.0.0.1 2;\n 192.168.1.0/24 1;\n 10.1.0.0/16 1;\n\n ::1 2;\n 2001:0db8::/32 1;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n geo [\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nDescribes the dependency of values of the specified variable\non the client IP address.\nBy default, the address is taken from the $remote_addr variable,\nbut it can also be taken from another variable, for example:\n
\ngeo $arg_remote_addr $geo {\n ...;\n}\n\n
\n
\nSince variables are evaluated only when used, the mere existence\nof even a large number of declared “geo” variables\ndoes not cause any extra costs for connection processing.\n\n
\nIf the value of a variable does not represent a valid IP address\nthen the “255.255.255.255” address is used.\n
\nAddresses are specified either as prefixes in CIDR notation\n(including individual addresses) or as ranges.\n
\nThe following special parameters are also supported:\n
deletedefault0.0.0.0/0” and “::/0”\ncan be used instead of default.\nWhen default is not specified, the default\nvalue will be an empty string.\nincluderangesvolatile\n
\nExample:\n
\ngeo $country {\n default ZZ;\n include conf/geo.conf;\n delete 127.0.0.0/16;\n\n 127.0.0.0/24 US;\n 127.0.0.1/32 RU;\n 10.1.0.0/16 RU;\n 192.168.1.0/24 UK;\n}\n\n
\nThe conf/geo.conf file could contain the following lines:\n
\n10.2.0.0/16 RU;\n192.168.2.0/24 RU;\n
\n
\nA value of the most specific match is used.\nFor example, for the 127.0.0.1 address the value “RU”\nwill be chosen, not “US”.\n
\nExample with ranges:\n
\ngeo $country {\n ranges;\n default ZZ;\n 127.0.0.0-127.0.0.0 US;\n 127.0.0.1-127.0.0.1 RU;\n 127.0.0.1-127.0.0.255 US;\n 10.1.0.0-10.1.255.255 RU;\n 192.168.1.0-192.168.1.255 UK;\n}\n\n
\n\n\nThe ngx_stream_js_module module is used to implement\nhandlers in njs —\na subset of the JavaScript language.\n
\nDownload and install instructions are available\nhere.\n
\n\n\n\nThe example works since\n0.4.0.\n
\nstream {\n js_import stream.js;\n\n js_set $bar stream.bar;\n js_set $req_line stream.req_line;\n\n server {\n listen 12345;\n\n js_preread stream.preread;\n return $req_line;\n }\n\n server {\n listen 12346;\n\n js_access stream.access;\n proxy_pass 127.0.0.1:8000;\n js_filter stream.header_inject;\n }\n}\n\nhttp {\n server {\n listen 8000;\n location / {\n return 200 $http_foo\\n;\n }\n }\n}\n\n
\nThe stream.js file:\n
\nvar line = '';\n\nfunction bar(s) {\n var v = s.variables;\n s.log(\"hello from bar() handler!\");\n return \"bar-var\" + v.remote_port + \"; pid=\" + v.pid;\n}\n\nfunction preread(s) {\n s.on('upload', function (data, flags) {\n var n = data.indexOf('\\n');\n if (n != -1) {\n line = data.substr(0, n);\n s.done();\n }\n });\n}\n\nfunction req_line(s) {\n return line;\n}\n\n// Read HTTP request line.\n// Collect bytes in 'req' until\n// request line is read.\n// Injects HTTP header into a client's request\n\nvar my_header = 'Foo: foo';\nfunction header_inject(s) {\n var req = '';\n s.on('upload', function(data, flags) {\n req += data;\n var n = req.search('\\n');\n if (n != -1) {\n var rest = req.substr(n + 1);\n req = req.substr(0, n + 1);\n s.send(req + my_header + '\\r\\n' + rest, flags);\n s.off('upload');\n }\n });\n}\n\nfunction access(s) {\n if (s.remoteAddress.match('^192.*')) {\n s.deny();\n return;\n }\n\n s.allow();\n}\n\nexport default {bar, preread, req_line, header_inject, access};\n\n
\n\n\n| \n Syntax:\n | \n\n js_access \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets an njs function which will be called at the\naccess phase.\nSince 0.4.0,\na module function can be referenced.\n
\nThe function is called once at the moment when the stream session reaches\nthe access phase\nfor the first time.\nThe function is called with the following arguments:\n\n
s\n
\nAt this phase, it is possible to perform initialization\nor register a callback with\nthe s.on()\nmethod\nfor each incoming data chunk until one of the following methods are called:\ns.allow(),\ns.decline(),\ns.done().\nAs soon as one of these methods is called, the stream session processing\nswitches to the next phase\nand all current\ns.on()\ncallbacks are dropped.\n
| \n Syntax:\n | \n\n js_context_reuse \n | \n
|---|---|
| \n Default:\n | \n\n js_context_reuse 128;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.8.6.\n
\nSets a maximum number of JS context to be reused for\nQuickJS engine.\nEach context is used for a single stream session.\nThe finished context is put into a pool of reusable contexts.\nIf the pool is full, the context is destroyed.\n
| \n Syntax:\n | \n\n js_engine \n | \n
|---|---|
| \n Default:\n | \n\n js_engine njs;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.8.6.\n
\nSets a JavaScript engine\nto be used for njs scripts.\nThe njs parameter sets the njs engine, also used by default.\nThe qjs parameter sets the QuickJS engine.\n
| \n Syntax:\n | \n\n js_fetch_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_buffer_size 16k;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.7.4.\n
\nSets the size of the buffer used for reading and writing\nwith Fetch API.\n
| \n Syntax:\n | \n\n js_fetch_ciphers \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_ciphers HIGH:!aNULL:!MD5;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.7.0.\n
\nSpecifies the enabled ciphers for HTTPS connections\nwith Fetch API.\nThe ciphers are specified in the format understood by the OpenSSL library.\n
\nThe full list can be viewed using the\n“openssl ciphers” command.\n
| \n Syntax:\n | \n\n js_fetch_max_response_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_max_response_buffer_size 1m;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.7.4.\n
\nSets the maximum size of the response received\nwith Fetch API.\n
| \n Syntax:\n | \n\n js_fetch_protocols \n [\n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_protocols TLSv1 TLSv1.1 TLSv1.2;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.7.0.\n
\nEnables the specified protocols for HTTPS connections\nwith Fetch API.\n
| \n Syntax:\n | \n\n js_fetch_timeout \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_timeout 60s;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.7.4.\n
\nDefines a timeout for reading and writing\nfor Fetch API.\nThe timeout is set only between two successive read/write operations,\nnot for the whole response.\nIf no data is transmitted within this time, the connection is closed.\n
| \n Syntax:\n | \n\n js_fetch_trusted_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.7.0.\n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to\nverify\nthe HTTPS certificate\nwith Fetch API.\n
| \n Syntax:\n | \n\n js_fetch_verify \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_verify on;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.7.4.\n
\nEnables or disables verification of the HTTPS server certificate\nwith Fetch API.\n
| \n Syntax:\n | \n\n js_fetch_verify_depth \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_verify_depth 100;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.7.0.\n
\nSets the verification depth in the HTTPS server certificates chain\nwith Fetch API.\n
| \n Syntax:\n | \n\n js_fetch_proxy \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.9.4.\n
\nConfigures a forward proxy URL\nwith Fetch API.\nThe url supports the HTTP scheme only\nand can contain optional user credentials\nin the format http://[user:password@]host:port\nfor Basic authentication.\nSupports both HTTP and HTTPS connections to destination servers.\nIf the url is empty, proxy routing is disabled.\nThe parameter value can contain variables.\n
\nExample:\n
\nserver {\n listen 12345;\n js_fetch_proxy http://user:pass@proxy.example.com:3128;\n js_preread main.fetch_handler;\n}\n\n
| \n Syntax:\n | \n\n js_fetch_keepalive \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_keepalive 0;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.9.2.\n
\nActivates the cache for connections to destination servers.\nWhen the value is greater than 0,\nenables keepalive connections for\nFetch API.\n
\nThe connections parameter sets the maximum number of idle\nkeepalive connections to destination servers that are preserved in the cache\nof each worker process.\nWhen this number is exceeded, the least recently used connections are closed.\n
\nExample:\n
\nserver {\n listen 12345;\n js_fetch_keepalive 32;\n js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;\n js_preread main.fetch_handler;\n}\n\n
| \n Syntax:\n | \n\n js_fetch_keepalive_requests \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_keepalive_requests 1000;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.9.2.\n
\nSets the maximum number of requests that can be served through one keepalive\nconnection with Fetch API.\nAfter the maximum number of requests is made, the connection is closed.\n
\nClosing connections periodically is necessary to free per-connection memory\nallocations.\nTherefore, using too high maximum number of requests could result in\nexcessive memory usage and not recommended.\n
| \n Syntax:\n | \n\n js_fetch_keepalive_time \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_keepalive_time 1h;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.9.2.\n
\nLimits the maximum time during which requests can be processed through one\nkeepalive connection with Fetch API.\nAfter this time is reached, the connection is closed following the subsequent\nrequest processing.\n
| \n Syntax:\n | \n\n js_fetch_keepalive_timeout \n | \n
|---|---|
| \n Default:\n | \n\n js_fetch_keepalive_timeout 60s;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.9.2.\n
\nSets a timeout during which an idle keepalive connection to a destination server\nwill stay open with Fetch API.\n
| \n Syntax:\n | \n\n js_filter \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets a data filter.\nSince 0.4.0,\na module function can be referenced.\nThe filter function is called once at the moment when the stream session reaches\nthe content phase.\n
\nThe filter function is called with the following arguments:\n
s\n
\nAt this phase, it is possible to perform initialization\nor register a callback with\nthe s.on()\nmethod for each incoming data chunk.\nThe\ns.off()\nmethod may be used to unregister a callback and stop filtering.\n
\n
\nAs thejs_filterhandler\nreturns its result immediately, it supports\nonly synchronous operations.\nThus, asynchronous operations such as\nngx.fetch()\nor\nsetTimeout()\nare not supported.\n
\n
| \n Syntax:\n | \n\n js_import \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.4.0.\n
\nImports a module that implements location and variable handlers in njs.\nThe export_name is used as a namespace\nto access module functions.\nIf the export_name is not specified,\nthe module name will be used as a namespace.\n
\njs_import stream.js;\n
\nHere, the module name stream is used as a namespace\nwhile accessing exports.\nIf the imported module exports foo(),\nstream.foo is used to refer to it.\n
\nSeveral js_import directives can be specified.\n
\n
\nThe directive can be specified on the\nserver level\nsince 0.7.7.\n\n
| \n Syntax:\n | \n\n js_include \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nSpecifies a file that implements server and variable handlers in njs:\n
\nnginx.conf:\njs_include stream.js;\njs_set $js_addr address;\nserver {\n listen 127.0.0.1:12345;\n return $js_addr;\n}\n\nstream.js:\nfunction address(s) {\n return s.remoteAddress;\n}\n\n
\nThe directive was made obsolete in version\n0.4.0\nand was removed in version\n0.7.1.\nThe js_import directive should be used instead.\n
| \n Syntax:\n | \n\n js_load_stream_native_module \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n main\n | \n
This directive appeared in version 0.9.5.\n
\nLoads a native module\n(shared library) for use in Stream JavaScript code.\nThe directive is\nQuickJS-only\nand is not available when using the njs built-in JavaScript engine.\n
\nThe path parameter\nspecifies the absolute path to the shared library file.\nThe optional as name parameter\nprovides an alias name for importing the module in JavaScript code.\nIf not specified, the module can be imported using its filename.\n
\nExample:\n
\njs_load_stream_native_module /path/to/mylib.so;\njs_load_stream_native_module /path/to/other.so as myalias;\n\nstream {\n js_import main.js;\n # ... rest of stream configuration\n}\n\nIn JavaScript code:\n
\n// Import by filename\nimport * as mylib from 'mylib.so';\n\n// Import by alias\nimport * as myalias from 'myalias';\n\n// Use exported functions\nlet result = mylib.add(5, 10);\n
\n
\n
\nFor security reasons, this directive is only allowed\nin the main configuration context.\nNative modules run with full process privileges;\nuse absolute paths and ensure proper code review.\n\n
| \n Syntax:\n | \n\n js_path \n\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.3.0.\n
\nSets an additional path for njs modules.\n
\n
\nThe directive can be specified on the\nserver level\nsince 0.7.7.\n\n
| \n Syntax:\n | \n\n js_periodic \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server\n | \n
This directive appeared in version 0.8.1.\n
\nSpecifies a content handler to run at regular interval.\nThe handler receives a\nsession object\nas its first argument,\nit also has access to global objects such as\nngx.\n
\nThe optional interval parameter\nsets the interval between two consecutive runs,\nby default, 5 seconds.\n
\nThe optional jitter parameter sets the time within which\nthe location content handler will be randomly delayed,\nby default, there is no delay.\n
\nBy default, the js_handler is executed on worker process 0.\nThe optional worker_affinity parameter\nallows specifying particular worker processes\nwhere the location content handler should be executed.\nEach worker process set is represented by a bitmask of allowed worker processes.\nThe all mask allows the handler to be executed\nin all worker processes.\n
\nExample:\n
\nexample.conf:\n\nlocation @periodics {\n # to be run at 1 minute intervals in worker process 0\n js_periodic main.handler interval=60s;\n\n # to be run at 1 minute intervals in all worker processes\n js_periodic main.handler interval=60s worker_affinity=all;\n\n # to be run at 1 minute intervals in worker processes 1 and 3\n js_periodic main.handler interval=60s worker_affinity=0101;\n\n resolver 10.0.0.1;\n js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;\n}\n\nexample.js:\n\nasync function handler(s) {\n let reply = await ngx.fetch('https://nginx.org/en/docs/njs/');\n let body = await reply.text();\n\n ngx.log(ngx.INFO, body);\n}\n\n
| \n Syntax:\n | \n\n js_preload_object \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.7.8.\n
\nPreloads an\nimmutable object\nat configure time.\nThe name is used as a name of the global variable\nthough which the object is available in njs code.\nIf the name is not specified,\nthe file name will be used instead.\n
\njs_preload_object map.json;\n
\nHere, the map is used as a name\nwhile accessing the preloaded object.\n
\nSeveral js_preload_object directives can be specified.\n
| \n Syntax:\n | \n\n js_preread \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets an njs function which will be called at the\npreread phase.\nSince 0.4.0,\na module function can be referenced.\n
\nThe function is called once\nat the moment when the stream session reaches the\npreread phase\nfor the first time.\nThe function is called with the following arguments:\n\n
s\n
\nAt this phase, it is possible to perform initialization\nor register a callback with\nthe s.on()\nmethod\nfor each incoming data chunk until one of the following methods are called:\ns.allow(),\ns.decline(),\ns.done().\nWhen one of these methods is called,\nthe stream session switches to the\nnext phase\nand all current\ns.on()\ncallbacks are dropped.\n
\n
\nAs thejs_prereadhandler\nreturns its result immediately, it supports\nonly synchronous callbacks.\nThus, asynchronous callbacks such as\nngx.fetch()\nor\nsetTimeout()\nare not supported.\nNevertheless, asynchronous operations are supported in\ns.on()\ncallbacks in the\npreread phase.\nSee\nthis example for more information.\n
\n
| \n Syntax:\n | \n\n js_set \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets an njs function\nfor the specified variable.\nSince 0.4.0,\na module function can be referenced.\n
\nThe function is called when\nthe variable is referenced for the first time for a given request.\nThe exact moment depends on a\nphase\nat which the variable is referenced.\nThis can be used to perform some logic\nnot related to variable evaluation.\nFor example, if the variable is referenced only in the\nlog_format directive,\nits handler will not be executed until the log phase.\nThis handler can be used to do some cleanup\nright before the request is freed.\n
\nSince 0.8.6, when\noptional argument nocache is provided the handler\nis called every time it is referenced.\nDue to current limitations\nof the rewrite module,\nwhen a nocache variable is referenced by the\nset directive\nits handler should always return a fixed-length value.\n
\n
\nAs the js_set handler\nreturns its result immediately, it supports\nonly synchronous callbacks.\nThus, asynchronous callbacks such as\nngx.fetch()\nor\nsetTimeout()\nare not supported.\n\n
\n
\nThe directive can be specified on the\nserver level\nsince 0.7.7.\n\n
| \n Syntax:\n | \n\n js_shared_dict_zone \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
This directive appeared in version 0.8.0.\n
\nSets the name and size of the shared memory zone\nthat keeps the\nkey-value dictionary\nshared between worker processes.\n
\nBy default the shared dictionary uses a string as a key and a value.\nThe optional type parameter\nallows redefining the value type to number.\n
\nThe optional timeout parameter sets\nthe time in milliseconds\nafter which all shared dictionary entries are removed from the zone.\nIf some entries require a different removal time, it can be set\nwith the timeout argument of the\nadd,\nincr, and\nset\nmethods\n(0.8.5).\n
\nThe optional evict parameter removes the oldest\nkey-value pair when the zone storage is exhausted.\n
\nThe optional state parameter specifies a file\nthat keeps the shared dictionary state\nin JSON format and makes it persistent across nginx restarts\n(0.9.1).\n
\nExample:\n
\nexample.conf:\n # Creates a 1Mb dictionary with string values,\n # removes key-value pairs after 60 seconds of inactivity:\n js_shared_dict_zone zone=foo:1M timeout=60s;\n\n # Creates a 512Kb dictionary with string values,\n # forcibly removes oldest key-value pairs when the zone is exhausted:\n js_shared_dict_zone zone=bar:512K timeout=30s evict;\n\n # Creates a 32Kb permanent dictionary with number values:\n js_shared_dict_zone zone=num:32k type=number;\n\n # Creates a 1Mb dictionary with string values and persistent state:\n js_shared_dict_zone zone=persistent:1M state=/tmp/dict.json;\n\nexample.js:\n function get(r) {\n r.return(200, ngx.shared.foo.get(r.args.key));\n }\n\n function set(r) {\n r.return(200, ngx.shared.foo.set(r.args.key, r.args.value));\n }\n\n function del(r) {\n r.return(200, ngx.shared.bar.delete(r.args.key));\n }\n\n function increment(r) {\n r.return(200, ngx.shared.num.incr(r.args.key, 2));\n }\n\n
| \n Syntax:\n | \n\n js_var \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 0.5.3.\n
\nDeclares\na writable\nvariable.\nThe value can contain text, variables, and their combination.\n
\n
\nThe directive can be specified on the\nserver level\nsince 0.7.7.\n\n
\n\n\n\nEach stream njs handler receives one argument, a stream session\nobject.\n
\n\n| Example Configuration Directives keyval keyval_zone |
\nThe ngx_stream_keyval_module module (1.13.7) creates variables\nwith values taken from key-value pairs managed by the\nAPI\nor a variable that can also be set with\nnjs.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nhttp {\n\n server {\n ...\n location /api {\n api write=on;\n }\n }\n}\n\nstream {\n\n keyval_zone zone=one:32k state=/var/lib/nginx/state/one.keyval;\n keyval $ssl_server_name $name zone=one;\n\n server {\n listen 12345 ssl;\n proxy_pass $name;\n ssl_certificate /usr/local/nginx/conf/cert.pem;\n ssl_certificate_key /usr/local/nginx/conf/cert.key;\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n keyval \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nCreates a new $variable whose value\nis looked up by the key in the key-value database.\nMatching rules are defined by the\ntype parameter of the\nkeyval_zone directive.\nThe database is stored in a shared memory zone\nspecified by the zone parameter.\n
| \n Syntax:\n | \n\n keyval_zone \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nSets the name and size of the shared memory zone\nthat keeps the key-value database.\nKey-value pairs are managed by the\nAPI.\n
\nThe optional state parameter specifies a file\nthat keeps the current state of the key-value database in the JSON format\nand makes it persistent across nginx restarts.\nChanging the file content directly should be avoided.\n
\nExamples:\n
\nkeyval_zone zone=one:32k state=/var/lib/nginx/state/one.keyval; # path for Linux\nkeyval_zone zone=one:32k state=/var/db/nginx/state/one.keyval; # path for FreeBSD\n
\n
\nThe optional timeout parameter (1.15.0) sets\nthe time after which key-value pairs are removed from the zone.\n
\nThe optional type parameter (1.17.1) activates\nan extra index optimized for matching the key of a certain type\nand defines matching rules when evaluating\na keyval $variable.\n
\nThe index is stored in the same shared memory zone\nand thus requires additional storage.\n
\n\n
type=stringtype=iptype=prefix\n
\nThe optional sync parameter (1.15.0) enables\nsynchronization\nof the shared memory zone.\nThe synchronization requires the\ntimeout parameter to be set.\n
\nIf the synchronization is enabled, removal of key-value pairs (no matter\none\nor\nall)\nwill be performed only on a target cluster node.\nThe same key-value pairs on other cluster nodes\nwill be removed upon timeout.\n\n
\n\n| Example Configuration Directives limit_conn limit_conn_dry_run limit_conn_log_level limit_conn_zone Embedded Variables |
\nThe ngx_stream_limit_conn_module module (1.9.3) is used to\nlimit the number of connections per the defined key, in\nparticular, the number of connections from a single IP address.\n
\n
\nstream {\n limit_conn_zone $binary_remote_addr zone=addr:10m;\n\n ...\n\n server {\n\n ...\n\n limit_conn addr 1;\n limit_conn_log_level error;\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n limit_conn \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets the shared memory zone\nand the maximum allowed number of connections for a given key value.\nWhen this limit is exceeded, the server will close the connection.\nFor example, the directives\n
\nlimit_conn_zone $binary_remote_addr zone=addr:10m;\n\nserver {\n ...\n limit_conn addr 1;\n}\n\nallow only one connection per an IP address at a time.\n
\nWhen several limit_conn directives are specified,\nany configured limit will apply.\n
\nThese directives are inherited from the previous configuration level\nif and only if there are no limit_conn directives\ndefined on the current level.\n
| \n Syntax:\n | \n\n limit_conn_dry_run \n | \n
|---|---|
| \n Default:\n | \n\n limit_conn_dry_run off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.17.6.\n
\nEnables the dry run mode.\nIn this mode, the number of connections is not limited, however,\nin the shared memory zone, the number of excessive connections is accounted\nas usual.\n
| \n Syntax:\n | \n\n limit_conn_log_level \n\n | \n
|---|---|
| \n Default:\n | \n\n limit_conn_log_level error;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets the desired logging level for cases when the server\nlimits the number of connections.\n
| \n Syntax:\n | \n\n limit_conn_zone \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nSets parameters for a shared memory zone\nthat will keep states for various keys.\nIn particular, the state includes the current number of connections.\nThe key can contain text, variables,\nand their combinations (1.11.2).\nConnections with an empty key value are not accounted.\nUsage example:\n
\nlimit_conn_zone $binary_remote_addr zone=addr:10m;\n
\nHere, the key is a client IP address set by the\n$binary_remote_addr variable.\nThe size of $binary_remote_addr\nis 4 bytes for IPv4 addresses or 16 bytes for IPv6 addresses.\nThe stored state always occupies 32 or 64 bytes\non 32-bit platforms and 64 bytes on 64-bit platforms.\nOne megabyte zone can keep about 32 thousand 32-byte states\nor about 16 thousand 64-byte states.\nIf the zone storage is exhausted, the server will close the connection.\n
\n
\nAdditionally, as part of our\ncommercial subscription,\nthe\nstatus information\nfor each such shared memory zone can be\nobtained or\nreset\nwith the API since 1.17.7.\n
\n
\n\n\n\n
$limit_conn_statusPASSED,\nREJECTED, or\nREJECTED_DRY_RUN\n\n
\n\n| Example Configuration Directives access_log log_format open_log_file_cache |
\nThe ngx_stream_log_module module (1.11.4) writes session logs\nin the specified format.\n
\n
\nlog_format basic '$remote_addr [$time_local] '\n '$protocol $status $bytes_sent $bytes_received '\n '$session_time';\n\naccess_log /spool/logs/nginx-access.log basic buffer=32k;\n
\n
\n\n\n| \n Syntax:\n | \n\n access_log \n access_log \n | \n
|---|---|
| \n Default:\n | \n\n access_log off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets the path, format,\nand configuration for a buffered log write.\nSeveral logs can be specified on the same configuration level.\nLogging to syslog\ncan be configured by specifying\nthe “syslog:” prefix in the first parameter.\nThe special value off cancels all\naccess_log directives on the current level.\n
\nIf either the buffer or gzip\nparameter is used, writes to log will be buffered.\n
\nThe buffer size must not exceed the size of an atomic write to a disk file.\nFor FreeBSD this size is unlimited.\n
\n
\nWhen buffering is enabled, the data will be written to the file:\n
flush\nparameter;\n\n
\nIf the gzip parameter is used, then the buffered data will\nbe compressed before writing to the file.\nThe compression level can be set between 1 (fastest, less compression)\nand 9 (slowest, best compression).\nBy default, the buffer size is equal to 64K bytes, and the compression level\nis set to 1.\nSince the data is compressed in atomic blocks, the log file can be decompressed\nor read by “zcat” at any time.\n
\nExample:\n
\naccess_log /path/to/log.gz basic gzip flush=5m;\n
\n
\n
\nFor gzip compression to work, nginx must be built with the zlib library.\n
\n
\nThe file path can contain variables,\nbut such logs have some constraints:\n
valid parameter\n\n
\nThe if parameter enables conditional logging.\nA session will not be logged if the condition evaluates to “0”\nor an empty string.\n
| \n Syntax:\n | \n\n log_format \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nSpecifies the log format, for example:\n
\nlog_format proxy '$remote_addr [$time_local] '\n '$protocol $status $bytes_sent $bytes_received '\n '$session_time \"$upstream_addr\" '\n '\"$upstream_bytes_sent\" \"$upstream_bytes_received\" \"$upstream_connect_time\"';\n
\n
\nThe escape parameter (1.11.8) allows setting\njson or default characters escaping\nin variables, by default, default escaping is used.\nThe none parameter (1.13.10) disables escaping.\n
\nFor default escaping,\ncharacters “\"”, “\\”,\nand other characters with values less than 32 or above 126\nare escaped as “\\xXX”.\nIf the variable value is not found,\na hyphen (“-”) will be logged.\n
\nFor json escaping,\nall characters not allowed\nin JSON strings\nwill be escaped:\ncharacters “\"” and\n“\\” are escaped as\n“\\\"” and “\\\\”,\ncharacters with values less than 32 are escaped as\n“\\n”,\n“\\r”,\n“\\t”,\n“\\b”,\n“\\f”, or\n“\\u00XX”.\n
| \n Syntax:\n | \n\n open_log_file_cache \nopen_log_file_cache \n | \n
|---|---|
| \n Default:\n | \n\n open_log_file_cache off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nDefines a cache that stores the file descriptors of frequently used logs\nwhose names contain variables.\nThe directive has the following parameters:\n
maxinactivemin_usesinactive parameter\nto let the descriptor stay open in a cache;\nby default, 1\nvalidoff\n
\nUsage example:\n
\nopen_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;\n
\n
\n\n| Example Configuration Directives map map_hash_bucket_size map_hash_max_size |
\nThe ngx_stream_map_module module (1.11.2) creates variables\nwhose values depend on values of other variables.\n
\n
\nmap $remote_addr $limit {\n 127.0.0.1 \"\";\n default $binary_remote_addr;\n}\n\nlimit_conn_zone $limit zone=addr:10m;\nlimit_conn addr 1;\n\n
\n\n\n| \n Syntax:\n | \n\n map \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nCreates a new variable whose value\ndepends on values of one or more of the source variables\nspecified in the first parameter.\n
\n
\nSince variables are evaluated only when they are used, the mere declaration\neven of a large number of “map” variables\ndoes not add any extra costs to connection processing.\n\n
\nParameters inside the map block specify a mapping\nbetween source and resulting values.\n
\nSource values are specified as strings or regular expressions.\n
\nStrings are matched ignoring the case.\n
\nA regular expression should either start from the “~”\nsymbol for a case-sensitive matching, or from the “~*”\nsymbols for case-insensitive matching.\nA regular expression can contain named and positional captures\nthat can later be used in other directives along with the\nresulting variable.\n
\nIf a source value matches one of the names of special parameters\ndescribed below, it should be prefixed with the “\\” symbol.\n
\nThe resulting value can contain text,\nvariable, and their combination.\n
\nThe following special parameters are also supported:\n
default valuedefault is not specified, the default\nresulting value will be an empty string.\nhostnames\nThe following two records\n\n*.example.com 1;\nexample.* 1;\n
\ncan be combined:\n\nexample.com 1;\n*.example.com 1;\n
\nThis parameter should be specified before the list of values.\n\n.example.com 1;\n
include filevolatile\n
\nThe search is performed in the following order of priority\nand terminates on the first matching variant:\n
*.example.com”\nmail.*”\n\n
| \n Syntax:\n | \n\n map_hash_bucket_size \n | \n
|---|---|
| \n Default:\n | \n\n map_hash_bucket_size 32|64|128;\n | \n
| \n Context:\n | \n\n stream\n | \n
\nSets the bucket size for the map variables hash tables.\nDefault value depends on the processor’s cache line size.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
| \n Syntax:\n | \n\n map_hash_max_size \n | \n
|---|---|
| \n Default:\n | \n\n map_hash_max_size 2048;\n | \n
| \n Context:\n | \n\n stream\n | \n
\nSets the maximum size of the map variables\nhash tables.\nThe details of setting up hash tables are provided in a separate\ndocument.\n
| Example Configuration Directives mqtt mqtt_buffers mqtt_rewrite_buffer_size mqtt_set_connect |
\nThe ngx_stream_mqtt_filter_module module (1.23.4) provides\nsupport for Message Queuing Telemetry Transport protocol (MQTT) versions\n3.1.1\nand\n5.0.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nlisten 127.0.0.1:18883;\nproxy_pass backend;\nproxy_buffer_size 16k;\n\nmqtt on;\nmqtt_set_connect clientid \"$client\";\nmqtt_set_connect username \"$name\";\n
\n
\n\n\n| \n Syntax:\n | \n\n mqtt \n | \n
|---|---|
| \n Default:\n | \n\n mqtt off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nEnables the MQTT protocol for the given virtual server.\n
| \n Syntax:\n | \n\n mqtt_buffers \n | \n
|---|---|
| \n Default:\n | \n\n mqtt_buffers 100 1k;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.25.1.\n
\nSets the number and size of the buffers\nused for handling MQTT messages,\nfor a single connection.\n
| \n Syntax:\n | \n\n mqtt_rewrite_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n mqtt_rewrite_buffer_size 4k|8k;\n | \n
| \n Context:\n | \n\n server\n | \n
\n
\nThis directive is obsolete since version 1.25.1.\nThe mqtt_buffers\ndirective should be used instead.\n
\n
\nSets the size of the buffer\nused for writing a modified message.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\nIt can be made smaller, however.\n
| \n Syntax:\n | \n\n mqtt_set_connect \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server\n | \n
\nSets the message field\nto the given value for CONNECT message.\nThe following fields are supported:\nclientid,\nusername, and\npassword.\nThe value can contain text, variables, and their combination.\n
\nSeveral mqtt_set_connect directives\ncan be specified on the same level:\n
\nmqtt_set_connect clientid \"$client\";\nmqtt_set_connect username \"$name\";\n
\n
\n\n| Example Configuration Directives mqtt_preread Embedded Variables |
\nThe ngx_stream_mqtt_preread_module module (1.23.4) allows\nextracting information from the CONNECT message\nof the Message Queuing Telemetry Transport protocol (MQTT) versions\n3.1.1\nand\n5.0,\nfor example, a username or a client ID.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nmqtt_preread on;\nreturn $mqtt_preread_clientid;\n
\n
\n\n\n| \n Syntax:\n | \n\n mqtt_preread \n | \n
|---|---|
| \n Default:\n | \n\n mqtt_preread off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nEnables extracting information from the MQTT CONNECT message at\nthe preread phase.\n
\n\n\n\n
$mqtt_preread_clientidclientid value from the CONNECT message\n$mqtt_preread_usernameusername value from the CONNECT message\n\n
\n\n| Example Configuration Directives num_map |
\nThe ngx_stream_num_map_module module (1.29.3)\ncreates variables whose values depend on numeric values\nor numeric value ranges.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nnum_map $remote_port $port_allow {\n default 0;\n\n 80 1;\n 443 1;\n <=1023 0;\n 8080-8090 1;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n num_map \n [\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nDescribes how the values of the specified variable depend on numeric values\nor numeric value ranges.\n
\n
\nSince variables are evaluated only when used, the mere existence\nof even a large number of declared “num_map” variables\ndoes not cause any extra costs for connection processing.\n\n
\nParameters inside the num_map block specify a mapping\nbetween source and resulting values.\n
\nSource values are specified as numbers or as numeric ranges.\n
\nThe following special parameters are also supported:\n
defaultdefault is not specified, the default\nresulting value will be an empty string.\nincludevolatile\n
\n\n| Example Configuration Directives pass |
\nThe ngx_stream_pass_module module (1.25.5) allows\npassing the accepted connection directly to any configured listening socket\nin http, stream, mail,\nand other similar modules.\n
\n
\nhttp {\n server {\n listen 8000;\n\n location / {\n root html;\n }\n }\n}\n\nstream {\n server {\n listen 12345 ssl;\n\n ssl_certificate domain.crt;\n ssl_certificate_key domain.key;\n\n pass 127.0.0.1:8000;\n }\n}\n \nIn the example,\nafter terminating SSL/TLS in the stream module\nthe connection is passed to the http module.\n
| \n Syntax:\n | \n\n pass \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server\n | \n
\nSets server address to pass client connection to.\nThe address can be specified as an IP address\nand a port:\n
\npass 127.0.0.1:12345;\n
\nor as a UNIX-domain socket path:\n
\npass unix:/tmp/stream.socket;\n
\n
\nThe address can also be specified using variables:\n
\npass $upstream;\n
\n
\n\n\nThe ngx_stream_proxy_module module (1.9.0) allows proxying\ndata streams over TCP, UDP (1.9.13), and UNIX-domain sockets.\n
\n
\nserver {\n listen 127.0.0.1:12345;\n proxy_pass 127.0.0.1:8080;\n}\n\nserver {\n listen 12345;\n proxy_connect_timeout 1s;\n proxy_timeout 1m;\n proxy_pass example.com:12345;\n}\n\nserver {\n listen 53 udp reuseport;\n proxy_timeout 20s;\n proxy_pass dns.example.com:53;\n}\n\nserver {\n listen [::1]:12345;\n proxy_pass unix:/tmp/stream.socket;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n proxy_bind \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.9.2.\n
\nMakes outgoing connections to a proxied server originate\nfrom the specified local IP address.\nParameter value can contain variables (1.11.2).\nThe special value off cancels the effect\nof the proxy_bind directive\ninherited from the previous configuration level, which allows the\nsystem to auto-assign the local IP address.\n
\nThe transparent parameter (1.11.0) allows\noutgoing connections to a proxied server originate\nfrom a non-local IP address,\nfor example, from a real IP address of a client:\n
\nproxy_bind $remote_addr transparent;\n
\nIn order for this parameter to work,\nit is usually necessary to run nginx worker processes with the\nsuperuser privileges.\nOn Linux it is not required (1.13.8) as if\nthe transparent parameter is specified, worker processes\ninherit the CAP_NET_RAW capability from the master process.\nIt is also necessary to configure kernel routing table\nto intercept network traffic from the proxied server.\n
| \n Syntax:\n | \n\n proxy_bind_dynamic \n | \n
|---|---|
| \n Default:\n | \n\n proxy_bind_dynamic off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.29.3.\n
\nWhen enabled, makes the bind operation\nat each connection attempt.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n proxy_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n proxy_buffer_size 16k;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.9.4.\n
\nSets the size of the buffer used for reading data\nfrom the proxied server.\nAlso sets the size of the buffer used for reading data\nfrom the client.\n
| \n Syntax:\n | \n\n proxy_connect_timeout \n | \n
|---|---|
| \n Default:\n | \n\n proxy_connect_timeout 60s;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nDefines a timeout for establishing a connection with a proxied server.\n
| \n Syntax:\n | \n\n proxy_download_rate \n | \n
|---|---|
| \n Default:\n | \n\n proxy_download_rate 0;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.9.3.\n
\nLimits the speed of reading the data from the proxied server.\nThe rate is specified in bytes per second.\nThe zero value disables rate limiting.\nThe limit is set per a connection, so if nginx simultaneously opens\ntwo connections to the proxied server,\nthe overall rate will be twice as much as the specified limit.\n
\nParameter value can contain variables (1.17.0).\nIt may be useful in cases where rate should be limited\ndepending on a certain condition:\n
\nmap $slow $rate {\n 1 4k;\n 2 8k;\n}\n\nproxy_download_rate $rate;\n\n
| \n Syntax:\n | \n\n proxy_half_close \n | \n
|---|---|
| \n Default:\n | \n\n proxy_half_close off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.21.4.\n
\nEnables or disables closing\neach direction of a TCP connection independently (“TCP half-close”).\nIf enabled, proxying over TCP will be kept\nuntil both sides close the connection.\n
| \n Syntax:\n | \n\n proxy_next_upstream \n | \n
|---|---|
| \n Default:\n | \n\n proxy_next_upstream on;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nWhen a connection to the proxied server cannot be established, determines\nwhether a client connection will be passed to the next server.\n
\nPassing a connection to the next server can be limited by\nthe number of tries\nand by time.\n
| \n Syntax:\n | \n\n proxy_next_upstream_timeout \n | \n
|---|---|
| \n Default:\n | \n\n proxy_next_upstream_timeout 0;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nLimits the time allowed to pass a connection to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n proxy_next_upstream_tries \n | \n
|---|---|
| \n Default:\n | \n\n proxy_next_upstream_tries 0;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nLimits the number of possible tries for passing a connection to the\nnext server.\nThe 0 value turns off this limitation.\n
| \n Syntax:\n | \n\n proxy_pass \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server\n | \n
\nSets the address of a proxied server.\nThe address can be specified as a domain name or IP address,\nand a port:\n
\nproxy_pass localhost:12345;\n
\nor as a UNIX-domain socket path:\n
\nproxy_pass unix:/tmp/stream.socket;\n
\n
\nIf a domain name resolves to several addresses, all of them will be\nused in a round-robin fashion.\nIn addition, an address can be specified as a\nserver group.\n
\nThe address can also be specified using variables (1.11.3):\n
\nproxy_pass $upstream;\n
\nIn this case, the server name is searched among the described\nserver groups,\nand, if not found, is determined using a\nresolver.\n
| \n Syntax:\n | \n\n proxy_protocol \n | \n
|---|---|
| \n Default:\n | \n\n proxy_protocol off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.9.2.\n
\nEnables the\nPROXY\nprotocol for connections to a proxied server.\n
| \n Syntax:\n | \n\n proxy_requests \n | \n
|---|---|
| \n Default:\n | \n\n proxy_requests 0;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.15.7.\n
\nSets the number of client datagrams at which\nbinding between a client and existing UDP stream session is dropped.\nAfter receiving the specified number of datagrams, next datagram\nfrom the same client starts a new session.\nThe session terminates when all client datagrams are transmitted\nto a proxied server and the expected number of\nresponses is received,\nor when it reaches a timeout.\n
| \n Syntax:\n | \n\n proxy_responses \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.9.13.\n
\nSets the number of datagrams expected from the proxied server\nin response to a client datagram\nif the UDP\nprotocol is used.\nThe number serves as a hint for session termination.\nBy default, the number of datagrams is not limited.\n
\nIf zero value is specified, no response is expected.\nHowever, if a response is received and the\nsession is still not finished, the response will be handled.\n
| \n Syntax:\n | \n\n proxy_session_drop \n | \n
|---|---|
| \n Default:\n | \n\n proxy_session_drop off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.15.8.\n
\nEnables terminating all sessions to a proxied server\nafter it was removed from the group or marked as permanently unavailable.\nThis can occur because of\nre-resolve\nor with the API\nDELETE\ncommand.\nA server can be marked as permanently unavailable if it is considered\nunhealthy\nor with the API\nPATCH\ncommand.\nEach session is terminated when the next\nread or write event is processed for the client or proxied server.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n proxy_socket_keepalive \n | \n
|---|---|
| \n Default:\n | \n\n proxy_socket_keepalive off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.15.6.\n
\nConfigures the “TCP keepalive” behavior\nfor outgoing connections to a proxied server.\nBy default, the operating system’s settings are in effect for the socket.\nIf the directive is set to the value “on”, the\nSO_KEEPALIVE socket option is turned on for the socket.\n
| \n Syntax:\n | \n\n proxy_ssl \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nEnables the SSL/TLS protocol for connections to a proxied server.\n
| \n Syntax:\n | \n\n proxy_ssl_alpn \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.31.0.\n
\nSpecifies the list of protocols to advertise via the\nALPN\nextension when establishing a connection with the proxied server.\nFor example:\n
\nproxy_ssl_alpn h2 http/1.1;\n
\n
\nParameter value can contain variables:\n
\nproxy_ssl_alpn $ssl_alpn_protocol;\n
\n
| \n Syntax:\n | \n\n proxy_ssl_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a file with the certificate in the PEM format\nused for authentication to a proxied server.\n
\nSince version 1.21.0, variables can be used in the file name.\n
| \n Syntax:\n | \n\n proxy_ssl_certificate_cache proxy_ssl_certificate_cache \n \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_certificate_cache off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.27.4.\n
\nDefines a cache that stores\nSSL certificates and\nsecret keys\nspecified with variables.\n
\nThe directive has the following parameters:\n
max\ninactive\nvalid\noff\n\n
\nExample:\n
\nproxy_ssl_certificate $proxy_ssl_server_name.crt;\nproxy_ssl_certificate_key $proxy_ssl_server_name.key;\nproxy_ssl_certificate_cache max=1000 inactive=20s valid=1m;\n
\n
| \n Syntax:\n | \n\n proxy_ssl_certificate_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nThe value\nstore:scheme:id\ncan be specified instead of the file (1.29.0),\nwhich is used to load a secret key with a specified id\nand OpenSSL provider registered URI scheme, such as\npkcs11.\n
\nSpecifies a file with the secret key in the PEM format\nused for authentication to a proxied server.\n
\nSince version 1.21.0, variables can be used in the file name.\n
| \n Syntax:\n | \n\n proxy_ssl_ciphers \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_ciphers DEFAULT;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies the enabled ciphers for connections to a proxied server.\nThe ciphers are specified in the format understood by the OpenSSL library.\n
\nThe full list can be viewed using the\n“openssl ciphers” command.\n
| \n Syntax:\n | \n\n proxy_ssl_conf_command \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.19.4.\n
\nSets arbitrary OpenSSL configuration\ncommands\nwhen establishing a connection with the proxied server.\n
\nThe directive is supported when using OpenSSL 1.0.2 or higher.\n
\n
\nSeveral proxy_ssl_conf_command directives\ncan be specified on the same level.\nThese directives are inherited from the previous configuration level\nif and only if there are\nno proxy_ssl_conf_command directives\ndefined on the current level.\n
\n
\nNote that configuring OpenSSL directly\nmight result in unexpected behavior.\n
\n
| \n Syntax:\n | \n\n proxy_ssl_crl \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a file with revoked certificates (CRL)\nin the PEM format used to verify\nthe certificate of the proxied server.\nWhen using intermediate certificates, their CRLs should be\nspecified in the same file.\n
| \n Syntax:\n | \n\n proxy_ssl_key_log path;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.27.2.\n
\nEnables logging of proxied server connection SSL keys\nand specifies the path to the key log file.\nKeys are logged in the\nSSLKEYLOGFILE\nformat compatible with Wireshark.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n proxy_ssl_name \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_name host from proxy_pass;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nAllows overriding the server name used to\nverify\nthe certificate of the proxied server and to be\npassed through SNI\nwhen establishing a connection with the proxied server.\nThe server name can also be specified using variables (1.11.3).\n
\nBy default, the host part of the proxy_pass address is used.\n
| \n Syntax:\n | \n\n proxy_ssl_password_file \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a file with passphrases for\nsecret keys\nwhere each passphrase is specified on a separate line.\nPassphrases are tried in turn when loading the key.\n
| \n Syntax:\n | \n\n proxy_ssl_protocols \n [\n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_protocols TLSv1.2 TLSv1.3;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nEnables the specified protocols for connections to a proxied server.\n
\n
\nThe TLSv1.3 parameter is used by default\nsince 1.23.4.\n\n
| \n Syntax:\n | \n\n proxy_ssl_server_name \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_server_name off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nEnables or disables passing of the server name through\nTLS\nServer Name Indication extension (SNI, RFC 6066)\nwhen establishing a connection with the proxied server.\n
| \n Syntax:\n | \n\n proxy_ssl_session_reuse \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_session_reuse on;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nDetermines whether SSL sessions can be reused when working with\nthe proxied server.\nIf the errors\n“digest check failed”\nappear in the logs, try disabling session reuse.\n
| \n Syntax:\n | \n\n proxy_ssl_trusted_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to verify\nthe certificate of the proxied server.\n
| \n Syntax:\n | \n\n proxy_ssl_verify \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_verify off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nEnables or disables verification of the proxied server certificate.\n
| \n Syntax:\n | \n\n proxy_ssl_verify_depth \n | \n
|---|---|
| \n Default:\n | \n\n proxy_ssl_verify_depth 1;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets the verification depth in the proxied server certificates chain.\n
| \n Syntax:\n | \n\n proxy_timeout \n | \n
|---|---|
| \n Default:\n | \n\n proxy_timeout 10m;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets the timeout between two successive\nread or write operations on client or proxied server connections.\nIf no data is transmitted within this time, the connection is closed.\n
| \n Syntax:\n | \n\n proxy_upload_rate \n | \n
|---|---|
| \n Default:\n | \n\n proxy_upload_rate 0;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.9.3.\n
\nLimits the speed of reading the data from the client.\nThe rate is specified in bytes per second.\nThe zero value disables rate limiting.\nThe limit is set per a connection, so if the client simultaneously opens\ntwo connections,\nthe overall rate will be twice as much as the specified limit.\n
\nParameter value can contain variables (1.17.0).\nIt may be useful in cases where rate should be limited\ndepending on a certain condition:\n
\nmap $slow $rate {\n 1 4k;\n 2 8k;\n}\n\nproxy_upload_rate $rate;\n\n
\n\n| Example Configuration Embedded Variables |
\nThe ngx_stream_proxy_protocol_vendor_module module (1.23.3)\nallows obtaining additional information about a connection in\ncloud platforms from application-specific TLVs of the\nPROXY\nprotocol\nheader.\n
\nSupported cloud platforms:\n
\n
\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nserver {\n listen 12345 proxy_protocol;\n return $proxy_protocol_tlv_gcp_conn_id;\n}\n\n
\n\n\n\n
$proxy_protocol_tlv_aws_vpce_id$proxy_protocol_tlv_azure_pel_id$proxy_protocol_tlv_gcp_conn_id\n
\n\n| Example Configuration Directives set_real_ip_from Embedded Variables |
\nThe ngx_stream_realip_module module is used\nto change the client address and port\nto the ones sent in the PROXY protocol header (1.11.4).\nThe PROXY protocol must be previously enabled by setting the\nproxy_protocol parameter\nin the listen directive.\n
\nThis module is not built by default, it should be enabled with the\n--with-stream_realip_module\nconfiguration parameter.\n
\n
\nlisten 12345 proxy_protocol;\n\nset_real_ip_from 192.168.1.0/24;\nset_real_ip_from 192.168.2.1;\nset_real_ip_from 2001:0db8::/32;\n
\n
\n\n\n| \n Syntax:\n | \n\n set_real_ip_from \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nDefines trusted addresses that are known to send correct\nreplacement addresses.\nIf the special value unix: is specified,\nall UNIX-domain sockets will be trusted.\n
\n
$realip_remote_addr$realip_remote_port\n
\n\n| Example Configuration Directives return |
\nThe ngx_stream_return_module module (1.11.2) allows\nsending a specified value to the client and then closing the connection.\n
\n
\nserver {\n listen 12345;\n return $time_iso8601;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n return \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server\n | \n
\nSpecifies a value to send to the client.\nThe value can contain text, variables, and their combination.\n
| Example Configuration Directives set |
\nThe ngx_stream_set_module module (1.19.3) allows\nsetting a value for a variable.\n
\n
\nserver {\n listen 12345;\n set $true 1;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n set \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server\n | \n
\nSets a value for the specified variable.\nThe value can contain text, variables, and their combination.\n
| Example Configuration Directives split_clients |
\nThe ngx_stream_split_clients_module module (1.11.3) creates\nvariables suitable for A/B testing, also known as split testing.\n
\n
\nstream {\n ...\n split_clients \"${remote_addr}AAA\" $upstream {\n 0.5% feature_test1;\n 2.0% feature_test2;\n * production;\n }\n\n server {\n ...\n proxy_pass $upstream;\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n split_clients \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nCreates a variable for A/B testing, for example:\n
\nsplit_clients \"${remote_addr}AAA\" $variant {\n 0.5% .one;\n 2.0% .two;\n * \"\";\n}\n \nThe value of the original string is hashed using MurmurHash2.\nIn the example given, hash values from 0 to 21474835 (0.5%)\ncorrespond to the\nvalue \".one\" of the $variant variable,\nhash values from 21474836 to 107374180 (2%) correspond to\nthe value \".two\",\nand hash values from 107374181 to 4294967295 correspond to\nthe value \"\" (an empty string).\n
\nThe ngx_stream_ssl_module module (1.9.0)\nprovides the necessary support for a stream proxy server to work with\nthe SSL/TLS protocol.\n
\nThis module is not built by default, it should be enabled with the\n--with-stream_ssl_module\nconfiguration parameter.\n
\nThis module requires the\nOpenSSL library.\n
\n
\n\n\n\nTo reduce the processor load, it is recommended to\n
\n\n
\nworker_processes auto;\n\nstream {\n\n ...\n\n server {\n listen 12345 ssl;\n\n ssl_protocols TLSv1.2 TLSv1.3;\n ssl_ciphers AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;\n ssl_certificate /usr/local/nginx/conf/cert.pem;\n ssl_certificate_key /usr/local/nginx/conf/cert.key;\n ssl_session_cache shared:SSL:10m;\n ssl_session_timeout 10m;\n\n ...\n }\n\n
\n\n\n| \n Syntax:\n | \n\n ssl_alpn \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.21.4.\n
\nSpecifies the list of supported\nALPN protocols.\nOne of the protocols must be\nnegotiated if the client uses ALPN:\n
\nmap $ssl_alpn_protocol $proxy {\n h2 127.0.0.1:8001;\n http/1.1 127.0.0.1:8002;\n}\n\nserver {\n listen 12346;\n proxy_pass $proxy;\n ssl_alpn h2 http/1.1;\n}\n\n
| \n Syntax:\n | \n\n ssl_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a file with the certificate in the PEM format\nfor the given virtual server.\nIf intermediate certificates should be specified in addition to a primary\ncertificate, they should be specified in the same file in the following\norder: the primary certificate comes first, then the intermediate certificates.\nA secret key in the PEM format may be placed in the same file.\n
\nSince version 1.11.0,\nthis directive can be specified multiple times\nto load certificates of different types, for example, RSA and ECDSA:\n
\nserver {\n listen 12345 ssl;\n\n ssl_certificate example.com.rsa.crt;\n ssl_certificate_key example.com.rsa.key;\n\n ssl_certificate example.com.ecdsa.crt;\n ssl_certificate_key example.com.ecdsa.key;\n\n ...\n}\n\n
\nOnly OpenSSL 1.0.2 or higher supports separate\ncertificate\nchains\nfor different certificates.\nWith older versions, only one certificate chain can be used.\n
\n
\nSince version 1.15.9, variables can be used in the file name\nwhen using OpenSSL 1.0.2 or higher:\n
\nssl_certificate $ssl_server_name.crt;\nssl_certificate_key $ssl_server_name.key;\n
\nNote that using variables implies that\na certificate will be loaded for each SSL handshake,\nand this may have a negative impact on performance.\n
\nThe value\ndata:$variable\ncan be specified instead of the file (1.15.10),\nwhich loads a certificate from a variable\nwithout using intermediate files.\nNote that inappropriate use of this syntax may have its security implications,\nsuch as writing secret key data to\nerror log.\n
\nIt should be kept in mind that due to the SSL/TLS protocol limitations,\nfor maximum interoperability with clients that do not use\nSNI,\nvirtual servers with different certificates should listen on\ndifferent\nIP addresses.\n
| \n Syntax:\n | \n\n ssl_certificate_cache ssl_certificate_cache \n \n | \n
|---|---|
| \n Default:\n | \n\n ssl_certificate_cache off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.27.4.\n
\nDefines a cache that stores\nSSL certificates and\nsecret keys\nspecified with variables.\n
\nThe directive has the following parameters:\n
max\ninactive\nvalid\noff\n\n
\nExample:\n
\nssl_certificate $ssl_server_name.crt;\nssl_certificate_key $ssl_server_name.key;\nssl_certificate_cache max=1000 inactive=20s valid=1m;\n
\n
| \n Syntax:\n | \n\n ssl_certificate_compression \n | \n
|---|---|
| \n Default:\n | \n\n ssl_certificate_compression off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.29.1.\n
\nEnables TLS 1.3\ncompression\nof server certificates.\n
\nThe directive is supported when using OpenSSL 3.2 or higher;\nthe list of supported compression algorithms is provided by the library.\n
\n
\nThe directive is supported when using BoringSSL;\nthe list of supported compression algorithms includes\nzlib (1.29.3).\n\n
| \n Syntax:\n | \n\n ssl_certificate_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a file with the secret key in the PEM format\nfor the given virtual server.\n
\nThe value\nengine:name:id\ncan be specified instead of the file,\nwhich loads a secret key with a specified id\nfrom the OpenSSL engine name.\n
\nThe value\nstore:scheme:id\ncan be specified instead of the file (1.29.0),\nwhich is used to load a secret key with a specified id\nand OpenSSL provider registered URI scheme, such as\npkcs11.\n
\nThe value\ndata:$variable\ncan be specified instead of the file (1.15.10),\nwhich loads a secret key from a variable without using intermediate files.\nNote that inappropriate use of this syntax may have its security implications,\nsuch as writing secret key data to\nerror log.\n
\nSince version 1.15.9, variables can be used in the file name\nwhen using OpenSSL 1.0.2 or higher.\n
| \n Syntax:\n | \n\n ssl_ciphers \n | \n
|---|---|
| \n Default:\n | \n\n ssl_ciphers HIGH:!aNULL:!MD5;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies the enabled ciphers.\nThe ciphers are specified in the format understood by the\nOpenSSL library, for example:\n
\nssl_ciphers ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;\n
\n
\nThe full list can be viewed using the\n“openssl ciphers” command.\n
| \n Syntax:\n | \n\n ssl_client_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.11.8.\n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to verify client certificates and\nOCSP responses if ssl_stapling is enabled.\n
\nThe list of certificates will be sent to clients.\nIf this is not desired, the ssl_trusted_certificate\ndirective can be used.\n
| \n Syntax:\n | \n\n ssl_conf_command \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.19.4.\n
\nSets arbitrary OpenSSL configuration\ncommands.\n
\nThe directive is supported when using OpenSSL 1.0.2 or higher.\n
\n
\nSeveral ssl_conf_command directives\ncan be specified on the same level:\n
\nssl_conf_command Options PrioritizeChaCha;\nssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;\n
\nThese directives are inherited from the previous configuration level\nif and only if there are no ssl_conf_command directives\ndefined on the current level.\n
\n
\nNote that configuring OpenSSL directly\nmight result in unexpected behavior.\n
\n
| \n Syntax:\n | \n\n ssl_crl \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.11.8.\n
\nSpecifies a file with revoked certificates (CRL)\nin the PEM format used to verify\nclient certificates.\nWhen using intermediate certificates, their CRLs should be\nspecified in the same file.\n
| \n Syntax:\n | \n\n ssl_dhparam \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a file with DH parameters for DHE ciphers.\n
\nBy default no parameters are set,\nand therefore DHE ciphers will not be used.\n
\nPrior to version 1.11.0, builtin parameters were used by default.\n
\n
| \n Syntax:\n | \n\n ssl_ecdh_curve \n | \n
|---|---|
| \n Default:\n | \n\n ssl_ecdh_curve auto;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a curve for ECDHE ciphers.\n
\nWhen using OpenSSL 1.0.2 or higher,\nit is possible to specify multiple curves (1.11.0), for example:\n
\nssl_ecdh_curve prime256v1:secp384r1;\n
\n
\nThe special value auto (1.11.0) instructs nginx to use\na list built into the OpenSSL library when using OpenSSL 1.0.2 or higher,\nor prime256v1 with older versions.\n
\n
\nPrior to version 1.11.0,\nthe prime256v1 curve was used by default.\n\n
\n
\nWhen using OpenSSL 1.0.2 or higher,\nthis directive sets the list of curves supported by the server.\nThus, in order for ECDSA certificates to work,\nit is important to include the curves used in the certificates.\n
\n
| \n Syntax:\n | \n\n ssl_ech_file \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.29.4.\n
\nSpecifies a file with encrypted ClientHello configuration\n(ECHConfig) in the\nPEM\nformat used to enable TLS 1.3\nECH\nin shared mode.\n
\n
\nThe directive is currently supported only when using OpenSSL\nECH\nfeature branch.\n
\n
| \n Syntax:\n | \n\n ssl_handshake_timeout \n | \n
|---|---|
| \n Default:\n | \n\n ssl_handshake_timeout 60s;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a timeout for the SSL handshake to complete.\n
| \n Syntax:\n | \n\n ssl_key_log path;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.27.2.\n
\nEnables logging of client connection SSL keys\nand specifies the path to the key log file.\nKeys are logged in the\nSSLKEYLOGFILE\nformat compatible with Wireshark.\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n ssl_ocsp \n | \n
|---|---|
| \n Default:\n | \n\n ssl_ocsp off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.27.2.\n
\nEnables OCSP validation of the client certificate chain.\nThe leaf parameter\nenables validation of the client certificate only.\n
\nFor the OCSP validation to work,\nthe ssl_verify_client directive should be set to\non or optional.\n
\nTo resolve the OCSP responder hostname,\nthe resolver directive\nshould also be specified.\n
\nExample:\n
\nssl_verify_client on;\nssl_ocsp on;\nresolver 192.0.2.1;\n
\n
| \n Syntax:\n | \n\n ssl_ocsp_cache \n \n | \n
|---|---|
| \n Default:\n | \n\n ssl_ocsp_cache off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.27.2.\n
\nSets name and size of the cache\nthat stores client certificates status for OCSP validation.\nThe cache is shared between all worker processes.\nA cache with the same name can be used in several\nvirtual servers.\n
\nThe off parameter prohibits the use of the cache.\n
| \n Syntax:\n | \n\n ssl_ocsp_responder \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.27.2.\n
\nOverrides the URL of the OCSP responder specified in the\n“Authority\nInformation Access” certificate extension\nfor validation of client certificates.\n
\nOnly “http://” OCSP responders are supported:\n
\nssl_ocsp_responder http://ocsp.example.com/;\n
\n
| \n Syntax:\n | \n\n ssl_password_file \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a file with passphrases for\nsecret keys\nwhere each passphrase is specified on a separate line.\nPassphrases are tried in turn when loading the key.\n
\nExample:\n
\nstream {\n ssl_password_file /etc/keys/global.pass;\n ...\n\n server {\n listen 127.0.0.1:12345;\n ssl_certificate_key /etc/keys/first.key;\n }\n\n server {\n listen 127.0.0.1:12346;\n\n # named pipe can also be used instead of a file\n ssl_password_file /etc/keys/fifo;\n ssl_certificate_key /etc/keys/second.key;\n }\n}\n\n
| \n Syntax:\n | \n\n ssl_prefer_server_ciphers \n | \n
|---|---|
| \n Default:\n | \n\n ssl_prefer_server_ciphers off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies that server ciphers should be preferred over client ciphers\nwhen the SSLv3 and TLS protocols are used.\n
| \n Syntax:\n | \n\n ssl_protocols \n [\n | \n
|---|---|
| \n Default:\n | \n\n ssl_protocols TLSv1.2 TLSv1.3;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nEnables the specified protocols.\n
\nIf the directive is specified\non the server level,\nthe value from the default server can be used.\nDetails are provided in the\n“Virtual\nserver selection” section.\n
\n
\nTheTLSv1.1andTLSv1.2parameters\nwork only when OpenSSL 1.0.1 or higher is used.\n
\n
\nThe TLSv1.3 parameter (1.13.0) works only when\nOpenSSL 1.1.1 or higher is used.\n\n
\nThe TLSv1.3 parameter is used by default\nsince 1.23.4.\n\n
| \n Syntax:\n | \n\n ssl_reject_handshake \n | \n
|---|---|
| \n Default:\n | \n\n ssl_reject_handshake off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.25.5.\n
\nIf enabled, SSL handshakes in\nthe server block will be rejected.\n
\nFor example, in the following configuration, SSL handshakes with\nserver names other than example.com are rejected:\n
\nserver {\n listen 443 ssl default_server;\n ssl_reject_handshake on;\n}\n\nserver {\n listen 443 ssl;\n server_name example.com;\n ssl_certificate example.com.crt;\n ssl_certificate_key example.com.key;\n}\n\n
| \n Syntax:\n | \n\n ssl_session_cache \n \n | \n
|---|---|
| \n Default:\n | \n\n ssl_session_cache none;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets the types and sizes of caches that store session parameters.\nA cache can be of any of the following types:\n
offnonebuiltin\n
\nBoth cache types can be used simultaneously, for example:\n
\nssl_session_cache builtin:1000 shared:SSL:10m;\n
\nbut using only shared cache without the built-in cache should\nbe more efficient.\n
| \n Syntax:\n | \n\n ssl_session_ticket_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets a file with the secret key used to encrypt\nand decrypt TLS session tickets.\nThe directive is necessary if the same key has to be shared between\nmultiple servers.\nBy default, a randomly generated key is used.\n
\nIf several keys are specified, only the first key is\nused to encrypt TLS session tickets.\nThis allows configuring key rotation, for example:\n
\nssl_session_ticket_key current.key;\nssl_session_ticket_key previous.key;\n
\n
\nThe file must contain 80 or 48 bytes\nof random data and can be created using the following command:\n
\nopenssl rand 80 > ticket.key\n
\nDepending on the file size either AES256 (for 80-byte keys, 1.11.8)\nor AES128 (for 48-byte keys) is used for encryption.\n
| \n Syntax:\n | \n\n ssl_session_tickets \n | \n
|---|---|
| \n Default:\n | \n\n ssl_session_tickets on;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nEnables or disables session resumption through\nTLS session tickets.\n
| \n Syntax:\n | \n\n ssl_session_timeout \n | \n
|---|---|
| \n Default:\n | \n\n ssl_session_timeout 5m;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a time during which a client may reuse the\nsession parameters.\n
| \n Syntax:\n | \n\n ssl_stapling \n | \n
|---|---|
| \n Default:\n | \n\n ssl_stapling off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.27.2.\n
\nEnables or disables\nstapling\nof OCSP responses by the server.\nExample:\n
\nssl_stapling on;\nresolver 192.0.2.1;\n
\n
\nFor the OCSP stapling to work, the certificate of the server certificate\nissuer should be known.\nIf the ssl_certificate file does\nnot contain intermediate certificates,\nthe certificate of the server certificate issuer should be\npresent in the\nssl_trusted_certificate file.\n
\nFor a resolution of the OCSP responder hostname,\nthe resolver directive\nshould also be specified.\n
| \n Syntax:\n | \n\n ssl_stapling_file \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.27.2.\n
\nWhen set, the stapled OCSP response will be taken from the\nspecified file instead of querying\nthe OCSP responder specified in the server certificate.\n
\nThe file should be in the DER format as produced by the\n“openssl ocsp” command.\n
| \n Syntax:\n | \n\n ssl_stapling_responder \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.27.2.\n
\nOverrides the URL of the OCSP responder specified in the\n“Authority\nInformation Access” certificate extension.\n
\nOnly “http://” OCSP responders are supported:\n
\nssl_stapling_responder http://ocsp.example.com/;\n
\n
| \n Syntax:\n | \n\n ssl_stapling_verify \n | \n
|---|---|
| \n Default:\n | \n\n ssl_stapling_verify off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.27.2.\n
\nEnables or disables verification of OCSP responses by the server.\n
\nFor verification to work, the certificate of the server certificate\nissuer, the root certificate, and all intermediate certificates\nshould be configured as trusted using the\nssl_trusted_certificate directive.\n
| \n Syntax:\n | \n\n ssl_trusted_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.11.8.\n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to verify client certificates and\nOCSP responses if ssl_stapling is enabled.\n
\nIn contrast to the certificate set by ssl_client_certificate,\nthe list of these certificates will not be sent to clients.\n
| \n Syntax:\n | \n\n ssl_verify_client \n \n | \n
|---|---|
| \n Default:\n | \n\n ssl_verify_client off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.11.8.\n
\nEnables verification of client certificates.\nThe verification result is stored in the\n$ssl_client_verify variable.\nIf an error has occurred during the client certificate verification\nor a client has not presented the required certificate,\nthe connection is closed.\n
\nThe optional parameter requests the client\ncertificate and verifies it if the certificate is present.\n
\nThe optional_no_ca parameter\nrequests the client\ncertificate but does not require it to be signed by a trusted CA certificate.\nThis is intended for the use in cases when a service that is external to nginx\nperforms the actual certificate verification.\nThe contents of the certificate is accessible through the\n$ssl_client_cert variable.\n
| \n Syntax:\n | \n\n ssl_verify_depth \n | \n
|---|---|
| \n Default:\n | \n\n ssl_verify_depth 1;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.11.8.\n
\nSets the verification depth in the client certificates chain.\n
\n\n\n\nThe ngx_stream_ssl_module module supports variables\nsince 1.11.2.\n
$ssl_alpn_protocol$ssl_cipher$ssl_ciphers\n\nAES128-SHA:AES256-SHA:0x00ff\n
\nThe variable is fully supported only when using OpenSSL version 1.0.2 or higher.\nWith older versions, the variable is available\nonly for new sessions and lists only known ciphers.\n\n
$ssl_client_cert$ssl_client_fingerprint$ssl_client_i_dn$ssl_client_raw_cert\n$ssl_client_s_dn$ssl_client_serial$ssl_client_sigalg\nThe variable is supported only when using OpenSSL version 3.5 or higher.\nWith older versions, the variable value will be an empty string.\n\n
\nThe variable is available only for new sessions.\n\n
$ssl_client_v_end$ssl_client_v_remain$ssl_client_v_start$ssl_client_verifySUCCESS”, “FAILED:reason”,\nand “NONE” if a certificate was not present;\n$ssl_curve\n\nprime256v1\n
\nThe variable is supported only when using OpenSSL version 3.0 or higher.\nWith older versions, the variable value will be an empty string.\n\n
$ssl_curves\n\n0x001d:prime256v1:secp521r1:secp384r1\n
\nThe variable is supported only when using OpenSSL version 1.0.2 or higher.\nWith older versions, the variable value will be an empty string.\n\n
\nThe variable is available only for new sessions.\n\n
$ssl_ech_outer_server_name$ssl_ech_statusFAILED”,\n“BACKEND”,\n“GREASE”,\n“SUCCESS”, or\n“NOT_TRIED” (1.29.4);\n\nThe variable is currently supported only when using OpenSSL\nECH feature branch\nand is therefore subject to change.\nThe variable value will otherwise be an empty string.\n\n
$ssl_protocol$ssl_server_name$ssl_session_id$ssl_session_reusedr” if an SSL session was reused,\nor “.” otherwise.\n$ssl_sigalg\nThe variable is supported only when using OpenSSL version 3.5 or higher.\nWith older versions, the variable value will be an empty string.\n\n
\nThe variable is available only for new sessions.\n\n
\n
\n\n| Example Configuration Directives ssl_preread Embedded Variables |
\nThe ngx_stream_ssl_preread_module module (1.11.5) allows\nextracting information from the\nClientHello\nmessage without terminating SSL/TLS,\nfor example, the server name requested through\nSNI\nor protocols advertised in\nALPN.\nThis module is not built by default, it should be enabled with the\n--with-stream_ssl_preread_module\nconfiguration parameter.\n
\nSelecting an upstream based on server name:\n
\nmap $ssl_preread_server_name $name {\n backend.example.com backend;\n default backend2;\n}\n\nupstream backend {\n server 192.168.0.1:12345;\n server 192.168.0.2:12345;\n}\n\nupstream backend2 {\n server 192.168.0.3:12345;\n server 192.168.0.4:12345;\n}\n\nserver {\n listen 12346;\n proxy_pass $name;\n ssl_preread on;\n}\n\n
\nSelecting an upstream based on protocol:\n
\nmap $ssl_preread_alpn_protocols $proxy {\n ~\\bh2\\b 127.0.0.1:8001;\n ~\\bhttp/1.1\\b 127.0.0.1:8002;\n ~\\bxmpp-client\\b 127.0.0.1:8003;\n}\n\nserver {\n listen 9000;\n proxy_pass $proxy;\n ssl_preread on;\n}\n\n
\nSelecting an upstream based on SSL protocol version:\n
\nmap $ssl_preread_protocol $upstream {\n \"\" ssh.example.com:22;\n \"TLSv1.2\" new.example.com:443;\n default tls.example.com:443;\n}\n\n# ssh and https on the same port\nserver {\n listen 192.168.0.1:443;\n proxy_pass $upstream;\n ssl_preread on;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n ssl_preread \n | \n
|---|---|
| \n Default:\n | \n\n ssl_preread off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nEnables extracting information from the ClientHello message at\nthe preread phase.\n
\n\n\n\n
$ssl_preread_protocol$ssl_preread_server_name$ssl_preread_alpn_protocols\n
\n\n| Example Configuration Directives health_check health_check_timeout match |
\nThe ngx_stream_upstream_hc_module module (1.9.0)\nallows enabling periodic health checks of the servers in a\ngroup.\nThe server group must reside in the\nshared memory.\n
\nIf a health check fails, the server will be considered unhealthy.\nIf several health checks are defined for the same group of servers,\na single failure of any check will make the corresponding server be\nconsidered unhealthy.\nClient connections are not passed to unhealthy servers\nand servers in the “checking” state.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\n
\nupstream tcp {\n zone upstream_tcp 64k;\n\n server backend1.example.com:12345 weight=5;\n server backend2.example.com:12345 fail_timeout=5s slow_start=30s;\n server 192.0.2.1:12345 max_fails=3;\n\n server backup1.example.com:12345 backup;\n server backup2.example.com:12345 backup;\n}\n\nserver {\n listen 12346;\n proxy_pass tcp;\n health_check;\n}\n \nWith this configuration, nginx\nwill check the ability to establish a TCP connection to each server\nin the tcp group every five seconds.\nWhen a connection to the server cannot be established,\nthe health check will fail, and the server will\nbe considered unhealthy.\n
\nHealth checks can be configured for the UDP protocol:\n
\nupstream dns_upstream {\n\n zone dns_zone 64k;\n\n server dns1.example.com:53;\n server dns2.example.com:53;\n server dns3.example.com:53;\n}\n\nserver {\n listen 53 udp;\n proxy_pass dns_upstream;\n health_check udp;\n}\n \nIn this case, the absence of\nICMP “Destination Unreachable” message is expected\nin reply to the sent string “nginx health check”.\n
\nHealth checks can also be configured to test data obtained from the server.\nTests are configured separately using the match directive\nand referenced in the match parameter\nof the health_check directive.\n
| \n Syntax:\n | \n\n health_check [\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server\n | \n
\nEnables periodic health checks of the servers in a\ngroup.\n
\nThe following optional parameters are supported:\n
interval=time\njitter=time\nfails=number\npasses=number\nmandatory [persistent]\n\nsets the initial “checking” state for a server\nuntil the first health check is completed (1.11.7).\nClient connections are not passed to servers in the “checking” state.\nIf the parameter is not specified,\nthe server will be initially considered healthy.\n
\n\n\nThe persistent parameter (1.21.1)\nsets the initial “up” state for a server after reload\nif the server was considered healthy before reload.\n
match=name\nmatch block configuring the tests that a\nsuccessful connection should pass in order for a health check to pass.\nBy default, for TCP, only the ability\nto establish a TCP connection with the server is checked.\nFor UDP, the absence of\nICMP “Destination Unreachable” message is expected\nin reply to the sent string “nginx health check”.\n\nPrior to version 1.11.7, by default, UDP health check\nrequired a match block with the\nsend and expect\nparameters.\n\n
port=number\nudp\nUDP protocol should be used for\nhealth checks instead of the default TCP protocol (1.9.13).\n\n
| \n Syntax:\n | \n\n health_check_timeout \n | \n
|---|---|
| \n Default:\n | \n\n health_check_timeout 5s;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nOverrides the\nproxy_timeout\nvalue for health checks.\n
| \n Syntax:\n | \n\n match \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nDefines the named test set used to verify server responses to health checks.\n
\nThe following parameters can be configured:\n
send string;\nstring to the server;\nexpect string |\n~ regex;\n~*” modifier (for case-insensitive matching), or the\n“~” modifier (for case-sensitive matching).\n \nBoth send and expect parameters\ncan contain hexadecimal literals with the prefix “\\x”\nfollowed by two hex digits, for example, “\\x80” (1.9.12).\n
\nHealth check is passed if:\n
string from the send parameter,\nif specified, was sent;\nexpect parameter, if specified;\n\n
\nExample:\n
\nupstream backend {\n zone upstream_backend 10m;\n server 127.0.0.1:12345;\n}\n\nmatch http {\n send \"GET / HTTP/1.0\\r\\nHost: localhost\\r\\n\\r\\n\";\n expect ~ \"200 OK\";\n}\n\nserver {\n listen 12346;\n proxy_pass backend;\n health_check match=http;\n}\n\n
\n
\nOnly the first\nproxy_buffer_size\nbytes of data obtained from the server are examined.\n
\n
\n\n| Example Configuration Directives upstream server zone state hash least_conn least_time random resolver resolver_timeout Embedded Variables |
\nThe ngx_stream_upstream_module module (1.9.0)\nis used to define groups of servers that can be referenced\nby the proxy_pass\ndirective.\n
\n
\nupstream backend {\n hash $remote_addr consistent;\n\n server backend1.example.com:12345 weight=5;\n server backend2.example.com:12345;\n server unix:/tmp/backend3;\n\n server backup1.example.com:12345 backup;\n server backup2.example.com:12345 backup;\n}\n\nserver {\n listen 12346;\n proxy_pass backend;\n}\n\n
\nDynamically configurable group with\nperiodic health checks is\navailable as part of our\ncommercial subscription:\n
\nresolver 10.0.0.1;\n\nupstream dynamic {\n zone upstream_dynamic 64k;\n\n server backend1.example.com:12345 weight=5;\n server backend2.example.com:12345 fail_timeout=5s slow_start=30s;\n server 192.0.2.1:12345 max_fails=3;\n server backend3.example.com:12345 resolve;\n server backend4.example.com service=http resolve;\n\n server backup1.example.com:12345 backup;\n server backup2.example.com:12345 backup;\n}\n\nserver {\n listen 12346;\n proxy_pass dynamic;\n health_check;\n}\n\n
\n\n\n| \n Syntax:\n | \n\n upstream \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream\n | \n
\nDefines a group of servers.\nServers can listen on different ports.\nIn addition, servers listening on TCP and UNIX-domain sockets\ncan be mixed.\n
\nExample:\n
\nupstream backend {\n server backend1.example.com:12345 weight=5;\n server 127.0.0.1:12345 max_fails=3 fail_timeout=30s;\n server unix:/tmp/backend2;\n server backend3.example.com:12345 resolve;\n\n server backup1.example.com:12345 backup;\n}\n\n
\nBy default, connections are distributed between the servers using a\nweighted round-robin balancing method.\nIn the above example, each 7 connections will be distributed as follows:\n5 connections go to backend1.example.com:12345\nand one connection to each of the second and third servers.\nIf an error occurs during communication with a server, the connection will\nbe passed to the next server, and so on until all of the functioning\nservers will be tried.\nIf communication with all servers fails, the connection will be closed.\n
| \n Syntax:\n | \n\n server \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
\nDefines the address and other parameters\nof a server.\nThe address can be specified as a domain name or IP address\nwith an obligatory port, or as a UNIX-domain socket path\nspecified after the “unix:” prefix.\nA domain name that resolves to several IP addresses defines\nmultiple servers at once.\n
\nThe following parameters can be defined:\n
weight=number\nmax_conns=number\nnumber of simultaneous\nconnections to the proxied server (1.11.5).\nDefault value is zero, meaning there is no limit.\nIf the server group does not reside in the shared memory,\nthe limitation works per each worker process.\n\nPrior to version 1.11.5, this parameter was available as part of our\ncommercial subscription.\n\n
max_fails=number\nfail_timeout\nparameter to consider the server unavailable for a duration also set by the\nfail_timeout parameter.\nBy default, the number of unsuccessful attempts is set to 1.\nThe zero value disables the accounting of attempts.\nHere, an unsuccessful attempt is an error or timeout\nwhile establishing a connection with the server.\nfail_timeout=time\nbackup\n\nThe parameter cannot be used along with the\nhash and random load balancing methods.\n\n
down\nresolve\n\nIn order for this parameter to work,\nthe resolver directive\nmust be specified in the\nstream block\nor in the corresponding upstream block.\n
\n
\nPrior to version 1.27.3, this parameter was available only as part of our\ncommercial subscription.\n
\n
\nservice=name\nname (1.9.13).\nIn order for this parameter to work, it is necessary to specify\nthe resolve parameter for the server\nand specify a hostname without a port number.\n\nIf the service name does not contain a dot (“.”), then\nthe RFC-compliant name\nis constructed\nand the TCP protocol is added to the service prefix.\nFor example, to look up the\n_http._tcp.backend.example.com SRV record,\nit is necessary to specify the directive:\n
\nserver backend.example.com service=http resolve;\n
\nIf the service name contains one or more dots, then the name is constructed\nby joining the service prefix and the server name.\nFor example, to look up the _http._tcp.backend.example.com\nand server1.backend.example.com SRV records,\nit is necessary to specify the directives:\n
\nserver backend.example.com service=_http._tcp resolve;\nserver example.com service=server1.backend resolve;\n
\n
\n\n\nHighest-priority SRV records\n(records with the same lowest-number priority value)\nare resolved as primary servers,\nthe rest of SRV records are resolved as backup servers.\nIf the backup parameter is specified for the server,\nhigh-priority SRV records are resolved as backup servers,\nthe rest of SRV records are ignored.\n
\n\n\n
\nPrior to version 1.27.3, this parameter was available only as part of our\ncommercial subscription.\n
\n
\n\n
\nAdditionally,\nthe following parameters are available as part of our\ncommercial subscription:\n
slow_start=time\ntime during which the server will recover its weight\nfrom zero to a nominal value, when unhealthy server becomes\nhealthy,\nor when the server becomes available after a period of time\nit was considered unavailable.\nDefault value is zero, i.e. slow start is disabled.\n\nThe parameter cannot be used along with the\nhash and random load balancing methods.\n\n
\n
\n
\nIf there is only a single server in a group,max_fails,\nfail_timeoutandslow_startparameters\nare ignored, and such a server will never be considered unavailable.\n
\n
| \n Syntax:\n | \n\n zone \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
\nDefines the name and size of the shared\nmemory zone that keeps the group’s configuration and run-time state that are\nshared between worker processes.\nSeveral groups may share the same zone.\nIn this case, it is enough to specify the size only once.\n
\nAdditionally,\nas part of our commercial subscription,\nsuch groups allow changing the group membership\nor modifying the settings of a particular server\nwithout the need of restarting nginx.\nThe configuration is accessible via the\nAPI module (1.13.3).\n
\nPrior to version 1.13.3,\nthe configuration was accessible only via a special location\nhandled by\nupstream_conf.\n
\n
| \n Syntax:\n | \n\n state \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.9.7.\n
\nSpecifies a file that keeps the state\nof the dynamically configurable group.\n
\nExamples:\n
\nstate /var/lib/nginx/state/servers.conf; # path for Linux\nstate /var/db/nginx/state/servers.conf; # path for FreeBSD\n
\n
\nThe state is currently limited to the list of servers with their parameters.\nThe file is read when parsing the configuration and is updated each time\nthe upstream configuration is\nchanged.\nChanging the file content directly should be avoided.\nThe directive cannot be used\nalong with the server directive.\n
\n
\nChanges made during\nconfiguration reload\nor binary upgrade\ncan be lost.\n
\n
\n
\nThis directive is available as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n hash \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
\nSpecifies a load balancing method for a server group\nwhere the client-server mapping is based on the hashed key value.\nThe key can contain text, variables,\nand their combinations (1.11.2).\nUsage example:\n
\nhash $remote_addr;\n
\nNote that adding or removing a server from the group\nmay result in remapping most of the keys to different servers.\nThe method is compatible with the\nCache::Memcached\nPerl library.\n
\nIf the consistent parameter is specified,\nthe ketama\nconsistent hashing method will be used instead.\nThe method ensures that only a few keys\nwill be remapped to different servers\nwhen a server is added to or removed from the group.\nThis helps to achieve a higher cache hit ratio for caching servers.\nThe method is compatible with the\nCache::Memcached::Fast\nPerl library with the ketama_points parameter set to 160.\n
| \n Syntax:\n | \n\n least_conn;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
\nSpecifies that a group should use a load balancing method where a connection\nis passed to the server with the least number of active connections,\ntaking into account weights of servers.\nIf there are several such servers, they are tried in turn using a\nweighted round-robin balancing method.\n
| \n Syntax:\n | \n\n least_time \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.7.11.\n
\nSpecifies that a group should use a load balancing method where a connection\nis passed to the server with the least average time and\nleast number of active connections, taking into account weights of servers.\nIf there are several such servers, they are tried in turn using a\nweighted round-robin balancing method.\n
\nIf the connect parameter is specified,\ntime to\nconnect\nto the upstream server is used.\nIf the first_byte parameter is specified,\ntime to receive the\nfirst byte of data is used.\nIf the last_byte is specified,\ntime to receive the\nlast byte of data is used.\nIf the inflight parameter is specified (1.11.6),\nincomplete connections are also taken into account.\n
\nPrior to version 1.11.6,\nincomplete connections were taken into account by default.\n
\n
\n
\nPrior to version 1.31.0,\nthis directive was available only as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n random [\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.15.1.\n
\nSpecifies that a group should use a load balancing method where a connection\nis passed to a randomly selected server, taking into account weights\nof servers.\n
\nThe optional two parameter\ninstructs nginx to randomly select\ntwo\nservers and then choose a server\nusing the specified method.\nThe default method is least_conn\nwhich passes a connection to a server\nwith the least number of active connections.\n
\nThe least_time method passes a connection to a server\nwith the least average time and least number of active connections.\nIf least_time=connect parameter is specified,\ntime to\nconnect\nto the upstream server is used.\nIf least_time=first_byte parameter is specified,\ntime to receive the\nfirst byte of data is used.\nIf least_time=last_byte is specified,\ntime to receive the\nlast byte of data is used.\n
\nThe least_time method is available as a part of our\ncommercial subscription.\n\n
| \n Syntax:\n | \n\n resolver \n \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.27.3.\n
\nConfigures name servers used to resolve names of upstream servers\ninto addresses, for example:\n
\nresolver 127.0.0.1 [::1]:5353;\n
\nThe address can be specified as a domain name or IP address,\nwith an optional port.\nIf port is not specified, the port 53 is used.\nName servers are queried in a round-robin fashion.\n
\nBy default, nginx will look up both IPv4 and IPv6 addresses while resolving.\nIf looking up of IPv4 or IPv6 addresses is not desired,\nthe ipv4=off (1.23.1) or\nthe ipv6=off parameter can be specified.\n
\nBy default, nginx caches answers using the TTL value of a response.\nThe optional valid parameter allows overriding it:\n
\nresolver 127.0.0.1 [::1]:5353 valid=30s;\n
\n
\nTo prevent DNS spoofing, it is recommended\nconfiguring DNS servers in a properly secured trusted local network.\n
\n
\nThe optional status_zone parameter (1.17.5)\nenables\ncollection\nof DNS server statistics of requests and responses\nin the specified zone.\nThe parameter is available as part of our\ncommercial subscription.\n
\n
\nSince version 1.17.5 and prior to version 1.27.3,\nthis directive was available only as part of our\ncommercial subscription.\n
\n
| \n Syntax:\n | \n\n resolver_timeout \n | \n
|---|---|
| \n Default:\n | \n\n resolver_timeout 30s;\n | \n
| \n Context:\n | \n\n upstream\n | \n
This directive appeared in version 1.27.3.\n
\nSets a timeout for name resolution, for example:\n
\nresolver_timeout 5s;\n
\n
\n
\nSince version 1.17.5 and prior to version 1.27.3,\nthis directive was available only as part of our\ncommercial subscription.\n
\n
\n\n\n\nThe ngx_stream_upstream_module module\nsupports the following embedded variables:\n
$upstream_addr192.168.1.1:12345, 192.168.1.2:12345, unix:/tmp/sock”.\nIf a server cannot be selected,\nthe variable keeps the name of the server group.\n$upstream_bytes_received$upstream_bytes_sent$upstream_connect_time$upstream_first_byte_time$upstream_last_addr\n
\nThis variable is available as part of our\ncommercial subscription.\n
\n
\n\n$upstream_session_time\n
\n\n\nThe ngx_stream_zone_sync_module module (1.13.8)\nprovides the necessary support for synchronizing contents of\nshared memory zones\nbetween nodes of a cluster.\nTo enable synchronization for a particular zone, a corresponding module\nmust support this feature.\nCurrently, it is possible to synchronize HTTP\nsticky\nsessions, information about\nexcessive HTTP requests,\nand key-value pairs both in\nhttp\nand stream.\n
\n
\nThis module is available as part of our\ncommercial subscription.\n
\n
\n\n\n\nMinimal configuration:\n
\nhttp {\n ...\n\n upstream backend {\n server backend1.example.com:8080;\n server backend2.example.com:8081;\n\n sticky learn\n create=$upstream_cookie_examplecookie\n lookup=$cookie_examplecookie\n zone=client_sessions:1m sync;\n }\n\n ...\n}\n\nstream {\n ...\n\n\n server {\n zone_sync;\n\n listen 127.0.0.1:12345;\n\n # cluster of 2 nodes\n zone_sync_server a.example.com:12345;\n zone_sync_server b.example.com:12345;\n\n }\n\nA more complex configuration with SSL enabled\nand with cluster members defined by DNS:\n
\n...\n\nstream {\n ...\n\n resolver 127.0.0.1 valid=10s;\n\n server {\n zone_sync;\n\n # the name resolves to multiple addresses that correspond to cluster nodes\n zone_sync_server cluster.example.com:12345 resolve;\n\n listen 127.0.0.1:4433 ssl;\n\n ssl_certificate localhost.crt;\n ssl_certificate_key localhost.key;\n\n zone_sync_ssl on;\n\n zone_sync_ssl_certificate localhost.crt;\n zone_sync_ssl_certificate_key localhost.key;\n }\n}\n\n
\n\n\n| \n Syntax:\n | \n\n zone_sync;\n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server\n | \n
\nEnables the synchronization of shared memory zones between cluster nodes.\nCluster nodes are defined using zone_sync_server directives.\n
| \n Syntax:\n | \n\n zone_sync_buffers \n | \n
|---|---|
| \n Default:\n | \n\n zone_sync_buffers 8 4k|8k;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets the number and size of the\nper-zone buffers used for pushing zone contents.\nBy default, the buffer size is equal to one memory page.\nThis is either 4K or 8K, depending on a platform.\n
\n
\nA single buffer must be large enough to hold any entry of each zone being\nsynchronized.\n
\n
| \n Syntax:\n | \n\n zone_sync_connect_retry_interval \n | \n
|---|---|
| \n Default:\n | \n\n zone_sync_connect_retry_interval 1s;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nDefines an interval between connection attempts to another cluster node.\n
| \n Syntax:\n | \n\n zone_sync_connect_timeout \n | \n
|---|---|
| \n Default:\n | \n\n zone_sync_connect_timeout 5s;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nDefines a timeout for establishing a connection with another cluster node.\n
| \n Syntax:\n | \n\n zone_sync_interval \n | \n
|---|---|
| \n Default:\n | \n\n zone_sync_interval 1s;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nDefines an interval for polling updates in a shared memory zone.\n
| \n Syntax:\n | \n\n zone_sync_recv_buffer_size \n | \n
|---|---|
| \n Default:\n | \n\n zone_sync_recv_buffer_size 4k|8k;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets size of a per-connection receive buffer used to parse\nincoming stream of synchronization messages.\nThe buffer size must be equal or greater than one of the\nzone_sync_buffers.\nBy default, the buffer size is equal to\nzone_sync_buffers size\nmultiplied by number.\n
| \n Syntax:\n | \n\n zone_sync_server \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n server\n | \n
\nDefines the address of a cluster node.\nThe address can be specified as a domain name or IP address\nwith a mandatory port, or as a UNIX-domain socket path\nspecified after the “unix:” prefix.\nA domain name that resolves to several IP addresses defines\nmultiple nodes at once.\n
\nThe resolve parameter instructs nginx to monitor\nchanges of the IP addresses that correspond to a domain name of the node\nand automatically modify the configuration\nwithout the need of restarting nginx.\n
\nCluster nodes are specified either dynamically as a single\nzone_sync_server directive with\nthe resolve parameter, or statically as a series of several\ndirectives without the parameter.\n
\nEach cluster node should be specified only once.\n
\n
\nAll cluster nodes should use the same configuration.\n
\n
\nIn order for the resolve parameter to work,\nthe resolver directive\nmust be specified in the\nstream block.\nExample:\n
\nstream {\n resolver 10.0.0.1;\n\n server {\n zone_sync;\n zone_sync_server cluster.example.com:12345 resolve;\n ...\n }\n}\n\n
| \n Syntax:\n | \n\n zone_sync_ssl \n | \n
|---|---|
| \n Default:\n | \n\n zone_sync_ssl off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nEnables the SSL/TLS protocol for connections to another cluster server.\n
| \n Syntax:\n | \n\n zone_sync_ssl_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a file with the certificate in the PEM format\nused for authentication to another cluster server.\n
| \n Syntax:\n | \n\n zone_sync_ssl_certificate_key \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a file with the secret key in the PEM format\nused for authentication to another cluster server.\n
| \n Syntax:\n | \n\n zone_sync_ssl_ciphers \n | \n
|---|---|
| \n Default:\n | \n\n zone_sync_ssl_ciphers DEFAULT;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies the enabled ciphers for connections to another cluster server.\nThe ciphers are specified in the format understood by the OpenSSL library.\n
\nThe full list can be viewed using the\n“openssl ciphers” command.\n
| \n Syntax:\n | \n\n zone_sync_ssl_conf_command \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.19.4.\n
\nSets arbitrary OpenSSL configuration\ncommands\nwhen establishing a connection with another cluster server.\n
\nThe directive is supported when using OpenSSL 1.0.2 or higher.\n
\n
\nSeveral zone_sync_ssl_conf_command directives\ncan be specified on the same level.\nThese directives are inherited from the previous configuration level\nif and only if there are\nno zone_sync_ssl_conf_command directives\ndefined on the current level.\n
\n
\nNote that configuring OpenSSL directly\nmight result in unexpected behavior.\n
\n
| \n Syntax:\n | \n\n zone_sync_ssl_crl \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a file with revoked certificates (CRL)\nin the PEM format used to verify\nthe certificate of another cluster server.\nWhen using intermediate certificates, their CRLs should be\nspecified in the same file.\n
| \n Syntax:\n | \n\n zone_sync_ssl_name \n | \n
|---|---|
| \n Default:\n | \n\n zone_sync_ssl_name host from zone_sync_server;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.15.7.\n
\nAllows overriding the server name used to\nverify\nthe certificate of a cluster server and to be\npassed through SNI\nwhen establishing a connection with the cluster server.\n
\nBy default, the host part of the zone_sync_server address is used,\nor resolved IP address if the resolve parameter is specified.\n
| \n Syntax:\n | \n\n zone_sync_ssl_password_file \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a file with passphrases for\nsecret keys\nwhere each passphrase is specified on a separate line.\nPassphrases are tried in turn when loading the key.\n
| \n Syntax:\n | \n\n zone_sync_ssl_protocols \n [\n | \n
|---|---|
| \n Default:\n | \n\n zone_sync_ssl_protocols TLSv1.2 TLSv1.3;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nEnables the specified protocols for connections to another cluster server.\n
| \n Syntax:\n | \n\n zone_sync_ssl_server_name \n | \n
|---|---|
| \n Default:\n | \n\n zone_sync_ssl_server_name off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
This directive appeared in version 1.15.7.\n
\nEnables or disables passing of the server name through\nTLS\nServer Name Indication extension (SNI, RFC 6066)\nwhen establishing a connection with another cluster server.\n
| \n Syntax:\n | \n\n zone_sync_ssl_trusted_certificate \n | \n
|---|---|
| \n Default:\n | \n\n \n —\n \n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSpecifies a file with trusted CA certificates in the PEM format\nused to verify\nthe certificate of another cluster server.\n
| \n Syntax:\n | \n\n zone_sync_ssl_verify \n | \n
|---|---|
| \n Default:\n | \n\n zone_sync_ssl_verify off;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nEnables or disables verification of another cluster server certificate.\n
| \n Syntax:\n | \n\n zone_sync_ssl_verify_depth \n | \n
|---|---|
| \n Default:\n | \n\n zone_sync_ssl_verify_depth 1;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets the verification depth in another cluster server certificates chain.\n
| \n Syntax:\n | \n\n zone_sync_timeout \n | \n
|---|---|
| \n Default:\n | \n\n zone_sync_timeout 5s;\n | \n
| \n Context:\n | \n\n stream, server\n | \n
\nSets the timeout between two successive\nread or write operations on connection to another cluster node.\nIf no data is transmitted within this time, the connection is closed.\n
\nThe synchronization status of a node is available via the\n/stream/zone_sync/\nendpoint of the API which returns the\nfollowing\nmetrics.\n
\n\n\n\nTo start a new node, update a DNS record of a cluster hostname\nwith the IP address of the new node and start an instance.\nThe new node will discover other nodes from DNS or static configuration\nand will start sending updates to them.\nOther nodes will eventually discover the new node using DNS and\nstart pushing updates to it.\nIn case of static configuration,\nother nodes need to be reloaded in order to send updates to the new node.\n
\nTo stop a node, send the QUIT signal to the instance.\nThe node will finish zone synchronization\nand gracefully close open connections.\n
\nTo remove a node, update a DNS record of a cluster hostname\nand remove the IP address of the node.\nAll other nodes will eventually discover that the node is removed,\nclose connections to the node, and will no longer try to connect to it.\nAfter the node is removed, it can be stopped as described above.\nIn case of static configuration, other nodes need to be reloaded\nin order to stop sending updates to the removed node.\n
\n\n\nA TCP/UDP session from a client is processed\nin successive steps called phases:\n\n
Post-accept\nPre-access\nAccess\nSSL\nPreread\nContent\nLog\n\n\n