Path: blob/main/xml/en/docs/http/ngx_http_proxy_module.xml
1 views
<?xml version="1.0"?>12<!--3Copyright (C) Igor Sysoev4Copyright (C) Nginx, Inc.5-->67<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">89<module name="Module ngx_http_proxy_module"10link="/en/docs/http/ngx_http_proxy_module.html"11lang="en"12rev="88">1314<section id="summary">1516<para>17The <literal>ngx_http_proxy_module</literal> module allows passing18requests to another server.19</para>2021</section>222324<section id="example" name="Example Configuration">2526<para>27<example>28location / {29proxy_pass http://localhost:8000;30proxy_set_header Host $host;31proxy_set_header X-Real-IP $remote_addr;32}33</example>34</para>3536</section>373839<section id="directives" name="Directives">4041<directive name="proxy_allow_upstream">42<syntax><value>string</value> ...</syntax>43<default/>44<context>http</context>45<context>server</context>46<context>location</context>47<appeared-in>1.29.3</appeared-in>4849<para>50Defines conditions under which access to a proxied server51is allowed or <link id="denied">denied</link>.52If all string parameters are not empty53and not equal to “0” then the access is allowed.54The conditions are evaluated each time55before a connection to a proxied server is established.56Parameter values can contain variables:57<example>58geo $upstream_last_addr $allow {59volatile;6010.10.0.0/24 1;61}6263server {64listen 127.0.0.1:8080;6566location / {67proxy_pass localhost:8000;68proxy_allow_upstream $allow;69...70}71}72</example>73</para>7475<para>76<note>77This directive is available as part of our78<commercial_version>commercial subscription</commercial_version>.79</note>80</para>8182</directive>838485<directive name="proxy_bind">86<syntax>87<value>address</value>88[<literal>transparent</literal>] |89<literal>off</literal></syntax>90<default/>91<context>http</context>92<context>server</context>93<context>location</context>94<appeared-in>0.8.22</appeared-in>9596<para>97Makes outgoing connections to a proxied server originate98from the specified local IP address with an optional port (1.11.2).99Parameter value can contain variables (1.3.12).100The special value <literal>off</literal> (1.3.12) cancels the effect101of the <literal>proxy_bind</literal> directive102inherited from the previous configuration level, which allows the103system to auto-assign the local IP address and port.104</para>105106<para id="proxy_bind_transparent">107The <literal>transparent</literal> parameter (1.11.0) allows108outgoing connections to a proxied server originate109from a non-local IP address,110for example, from a real IP address of a client:111<example>112proxy_bind $remote_addr transparent;113</example>114In order for this parameter to work,115it is usually necessary to run nginx worker processes with the116<link doc="../ngx_core_module.xml" id="user">superuser</link> privileges.117On Linux it is not required (1.13.8) as if118the <literal>transparent</literal> parameter is specified, worker processes119inherit the <literal>CAP_NET_RAW</literal> capability from the master process.120It is also necessary to configure kernel routing table121to intercept network traffic from the proxied server.122</para>123124</directive>125126127<directive name="proxy_bind_dynamic">128<syntax><literal>on</literal> | <literal>off</literal></syntax>129<default>off</default>130<context>http</context>131<context>server</context>132<context>location</context>133<appeared-in>1.29.3</appeared-in>134135<para>136When enabled, makes the <link id="proxy_bind">bind</link> operation137at each connection attempt.138</para>139140<para>141<note>142This directive is available as part of our143<commercial_version>commercial subscription</commercial_version>.144</note>145</para>146147</directive>148149150<directive name="proxy_buffer_size">151<syntax><value>size</value></syntax>152<default>4k|8k</default>153<context>http</context>154<context>server</context>155<context>location</context>156157<para>158Sets the <value>size</value> of the buffer used for reading the first part159of the response received from the proxied server.160This part usually contains a small response header;161if it exceeds the buffer size, the response is considered162<link id="invalid_header">invalid</link>.163By default, the buffer size is equal to one memory page.164This is either 4K or 8K, depending on a platform.165It can be made smaller, however.166</para>167168</directive>169170171<directive name="proxy_buffering">172<syntax><literal>on</literal> | <literal>off</literal></syntax>173<default>on</default>174<context>http</context>175<context>server</context>176<context>location</context>177178<para>179Enables or disables buffering of responses from the proxied server.180</para>181182<para>183When buffering is enabled, nginx receives a response from the proxied server184as soon as possible, saving it into the buffers set by the185<link id="proxy_buffer_size"/> and <link id="proxy_buffers"/> directives.186If the whole response does not fit into memory, a part of it can be saved187to a <link id="proxy_temp_path">temporary file</link> on the disk.188Writing to temporary files is controlled by the189<link id="proxy_max_temp_file_size"/> and190<link id="proxy_temp_file_write_size"/> directives.191</para>192193<para>194When buffering is disabled, the response is passed to a client synchronously,195immediately as it is received.196nginx will not try to read the whole response from the proxied server.197The maximum size of the data that nginx can receive from the server198at a time is set by the <link id="proxy_buffer_size"/> directive.199</para>200201<para>202Buffering can also be enabled or disabled by passing203“<literal>yes</literal>” or “<literal>no</literal>” in the204<header>X-Accel-Buffering</header> response header field.205This capability can be disabled using the206<link id="proxy_ignore_headers"/> directive.207</para>208209</directive>210211212<directive name="proxy_buffers">213<syntax><value>number</value> <value>size</value></syntax>214<default>8 4k|8k</default>215<context>http</context>216<context>server</context>217<context>location</context>218219<para>220Sets the <value>number</value> and <value>size</value> of the221buffers used for reading a response from the proxied server,222for a single connection.223By default, the buffer size is equal to one memory page.224This is either 4K or 8K, depending on a platform.225</para>226227</directive>228229230<directive name="proxy_busy_buffers_size">231<syntax><value>size</value></syntax>232<default>8k|16k</default>233<context>http</context>234<context>server</context>235<context>location</context>236237<para>238When <link id="proxy_buffering">buffering</link> of responses from the proxied239server is enabled, limits the total <value>size</value> of buffers that240can be busy sending a response to the client while the response is not241yet fully read.242In the meantime, the rest of the buffers can be used for reading the response243and, if needed, buffering part of the response to a temporary file.244By default, <value>size</value> is limited by the size of two buffers set by the245<link id="proxy_buffer_size"/> and <link id="proxy_buffers"/> directives.246</para>247248</directive>249250251<directive name="proxy_cache">252<syntax><value>zone</value> | <literal>off</literal></syntax>253<default>off</default>254<context>http</context>255<context>server</context>256<context>location</context>257258<para>259Defines a shared memory zone used for caching.260The same zone can be used in several places.261Parameter value can contain variables (1.7.9).262The <literal>off</literal> parameter disables caching inherited263from the previous configuration level.264</para>265266</directive>267268269<directive name="proxy_cache_background_update">270<syntax><literal>on</literal> | <literal>off</literal></syntax>271<default>off</default>272<context>http</context>273<context>server</context>274<context>location</context>275<appeared-in>1.11.10</appeared-in>276277<para>278Allows starting a background subrequest279to update an expired cache item,280while a stale cached response is returned to the client.281Note that it is necessary to282<link id="proxy_cache_use_stale_updating">allow</link>283the usage of a stale cached response when it is being updated.284</para>285286</directive>287288289<directive name="proxy_cache_bypass">290<syntax><value>string</value> ...</syntax>291<default/>292<context>http</context>293<context>server</context>294<context>location</context>295296<para>297Defines conditions under which the response will not be taken from a cache.298If at least one value of the string parameters is not empty and is not299equal to “0” then the response will not be taken from the cache:300<example>301proxy_cache_bypass $cookie_nocache $arg_nocache$arg_comment;302proxy_cache_bypass $http_pragma $http_authorization;303</example>304Can be used along with the <link id="proxy_no_cache"/> directive.305</para>306307</directive>308309<directive name="proxy_cache_convert_head">310<syntax><literal>on</literal> | <literal>off</literal></syntax>311<default>on</default>312<context>http</context>313<context>server</context>314<context>location</context>315<appeared-in>1.9.7</appeared-in>316317<para>318Enables or disables the conversion of the “<literal>HEAD</literal>” method319to “<literal>GET</literal>” for caching.320When the conversion is disabled, the321<link id="proxy_cache_key">cache key</link> should be configured322to include the <var>$request_method</var>.323</para>324325</directive>326327328<directive name="proxy_cache_key">329<syntax><value>string</value></syntax>330<default>$scheme$proxy_host$request_uri</default>331<context>http</context>332<context>server</context>333<context>location</context>334335<para>336Defines a key for caching, for example337<example>338proxy_cache_key "$host$request_uri $cookie_user";339</example>340By default, the directive’s value is close to the string341<example>342proxy_cache_key $scheme$proxy_host$uri$is_args$args;343</example>344</para>345346</directive>347348349<directive name="proxy_cache_lock">350<syntax><literal>on</literal> | <literal>off</literal></syntax>351<default>off</default>352<context>http</context>353<context>server</context>354<context>location</context>355<appeared-in>1.1.12</appeared-in>356357<para>358When enabled, only one request at a time will be allowed to populate359a new cache element identified according to the <link id="proxy_cache_key"/>360directive by passing a request to a proxied server.361Other requests of the same cache element will either wait362for a response to appear in the cache or the cache lock for363this element to be released, up to the time set by the364<link id="proxy_cache_lock_timeout"/> directive.365</para>366367</directive>368369370<directive name="proxy_cache_lock_age">371<syntax><value>time</value></syntax>372<default>5s</default>373<context>http</context>374<context>server</context>375<context>location</context>376<appeared-in>1.7.8</appeared-in>377378<para>379If the last request passed to the proxied server380for populating a new cache element381has not completed for the specified <value>time</value>,382one more request may be passed to the proxied server.383</para>384385</directive>386387388<directive name="proxy_cache_lock_timeout">389<syntax><value>time</value></syntax>390<default>5s</default>391<context>http</context>392<context>server</context>393<context>location</context>394<appeared-in>1.1.12</appeared-in>395396<para>397Sets a timeout for <link id="proxy_cache_lock"/>.398When the <value>time</value> expires,399the request will be passed to the proxied server,400however, the response will not be cached.401<note>402Before 1.7.8, the response could be cached.403</note>404</para>405406</directive>407408409<directive name="proxy_cache_max_range_offset">410<syntax><value>number</value></syntax>411<default/>412<context>http</context>413<context>server</context>414<context>location</context>415<appeared-in>1.11.6</appeared-in>416417<para>418Sets an offset in bytes for byte-range requests.419If the range is beyond the offset,420the range request will be passed to the proxied server421and the response will not be cached.422</para>423424</directive>425426427<directive name="proxy_cache_methods">428<syntax>429<literal>GET</literal> |430<literal>HEAD</literal> |431<literal>POST</literal>432...</syntax>433<default>GET HEAD</default>434<context>http</context>435<context>server</context>436<context>location</context>437<appeared-in>0.7.59</appeared-in>438439<para>440If the client request method is listed in this directive then441the response will be cached.442“<literal>GET</literal>” and “<literal>HEAD</literal>” methods are always443added to the list, though it is recommended to specify them explicitly.444See also the <link id="proxy_no_cache"/> directive.445</para>446447</directive>448449450<directive name="proxy_cache_min_uses">451<syntax><value>number</value></syntax>452<default>1</default>453<context>http</context>454<context>server</context>455<context>location</context>456457<para>458Sets the <value>number</value> of requests after which the response459will be cached.460</para>461462</directive>463464465<directive name="proxy_cache_path">466<syntax>467<value>path</value>468[<literal>levels</literal>=<value>levels</value>]469[<literal>use_temp_path</literal>=<literal>on</literal>|<literal>off</literal>]470<literal>keys_zone</literal>=<value>name</value>:<value>size</value>471[<literal>inactive</literal>=<value>time</value>]472[<literal>max_size</literal>=<value>size</value>]473[<literal>min_free</literal>=<value>size</value>]474[<literal>manager_files</literal>=<value>number</value>]475[<literal>manager_sleep</literal>=<value>time</value>]476[<literal>manager_threshold</literal>=<value>time</value>]477[<literal>loader_files</literal>=<value>number</value>]478[<literal>loader_sleep</literal>=<value>time</value>]479[<literal>loader_threshold</literal>=<value>time</value>]480[<literal>purger</literal>=<literal>on</literal>|<literal>off</literal>]481[<literal>purger_files</literal>=<value>number</value>]482[<literal>purger_sleep</literal>=<value>time</value>]483[<literal>purger_threshold</literal>=<value>time</value>]</syntax>484<default/>485<context>http</context>486487<para>488Sets the path and other parameters of a cache.489Cache data are stored in files.490The file name in a cache is a result of491applying the MD5 function to the492<link id="proxy_cache_key">cache key</link>.493The <literal>levels</literal> parameter defines hierarchy levels of a cache:494from 1 to 3, each level accepts values 1 or 2.495For example, in the following configuration496<example>497proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=one:10m;498</example>499file names in a cache will look like this:500<example>501/data/nginx/cache/<emphasis>c</emphasis>/<emphasis>29</emphasis>/b7f54b2df7773722d382f4809d650<emphasis>29c</emphasis>502</example>503</para>504505<para>506A cached response is first written to a temporary file,507and then the file is renamed.508Starting from version 0.8.9, temporary files and the cache can be put on509different file systems.510However, be aware that in this case a file is copied511across two file systems instead of the cheap renaming operation.512It is thus recommended that for any given location both cache and a directory513holding temporary files514are put on the same file system.515The directory for temporary files is set based on516the <literal>use_temp_path</literal> parameter (1.7.10).517If this parameter is omitted or set to the value <literal>on</literal>,518the directory set by the <link id="proxy_temp_path"/> directive519for the given location will be used.520If the value is set to <literal>off</literal>,521temporary files will be put directly in the cache directory.522</para>523524<para>525In addition, all active keys and information about data are stored526in a shared memory zone, whose <value>name</value> and <value>size</value>527are configured by the <literal>keys_zone</literal> parameter.528One megabyte zone can store about 8 thousand keys.529<note>530As part of531<commercial_version>commercial subscription</commercial_version>,532the shared memory zone also stores extended533cache <link doc="ngx_http_api_module.xml" id="http_caches_">information</link>,534thus, it is required to specify a larger zone size for the same number of keys.535For example,536one megabyte zone can store about 4 thousand keys.537</note>538</para>539540<para>541Cached data that are not accessed during the time specified by the542<literal>inactive</literal> parameter get removed from the cache543regardless of their freshness.544By default, <literal>inactive</literal> is set to 10 minutes.545</para>546547<para id="proxy_cache_path_max_size">548The special “cache manager” process monitors the maximum cache size set549by the <literal>max_size</literal> parameter,550and the minimum amount of free space set551by the <literal>min_free</literal> (1.19.1) parameter552on the file system with cache.553When the size is exceeded or there is not enough free space,554it removes the least recently used data.555The data is removed in iterations configured by556<literal>manager_files</literal>,557<literal>manager_threshold</literal>, and558<literal>manager_sleep</literal> parameters (1.11.5).559During one iteration no more than <literal>manager_files</literal> items560are deleted (by default, 100).561The duration of one iteration is limited by the562<literal>manager_threshold</literal> parameter (by default, 200 milliseconds).563Between iterations, a pause configured by the <literal>manager_sleep</literal>564parameter (by default, 50 milliseconds) is made.565</para>566567<para>568A minute after the start the special “cache loader” process is activated.569It loads information about previously cached data stored on file system570into a cache zone.571The loading is also done in iterations.572During one iteration no more than <literal>loader_files</literal> items573are loaded (by default, 100).574Besides, the duration of one iteration is limited by the575<literal>loader_threshold</literal> parameter (by default, 200 milliseconds).576Between iterations, a pause configured by the <literal>loader_sleep</literal>577parameter (by default, 50 milliseconds) is made.578</para>579580<para>581Additionally,582the following parameters are available as part of our583<commercial_version>commercial subscription</commercial_version>:584</para>585586<para>587<list type="tag">588589<tag-name id="purger">590<literal>purger</literal>=<literal>on</literal>|<literal>off</literal>591</tag-name>592<tag-desc>593Instructs whether cache entries that match a594<link id="proxy_cache_purge">wildcard key</link>595will be removed from the disk by the cache purger (1.7.12).596Setting the parameter to <literal>on</literal>597(default is <literal>off</literal>)598will activate the “cache purger” process that599permanently iterates through all cache entries600and deletes the entries that match the wildcard key.601</tag-desc>602603<tag-name id="purger_files">604<literal>purger_files</literal>=<value>number</value>605</tag-name>606<tag-desc>607Sets the number of items that will be scanned during one iteration (1.7.12).608By default, <literal>purger_files</literal> is set to 10.609</tag-desc>610611<tag-name id="purger_threshold">612<literal>purger_threshold</literal>=<value>number</value>613</tag-name>614<tag-desc>615Sets the duration of one iteration (1.7.12).616By default, <literal>purger_threshold</literal> is set to 50 milliseconds.617</tag-desc>618619<tag-name id="purger_sleep">620<literal>purger_sleep</literal>=<value>number</value>621</tag-name>622<tag-desc>623Sets a pause between iterations (1.7.12).624By default, <literal>purger_sleep</literal> is set to 50 milliseconds.625</tag-desc>626627</list>628</para>629630<para>631<note>632In versions 1.7.3, 1.7.7, and 1.11.10 cache header format has been changed.633Previously cached responses will be considered invalid634after upgrading to a newer nginx version.635</note>636</para>637638</directive>639640641<directive name="proxy_cache_purge">642<syntax>string ...</syntax>643<default/>644<context>http</context>645<context>server</context>646<context>location</context>647<appeared-in>1.5.7</appeared-in>648649<para>650Defines conditions under which the request will be considered a cache651purge request.652If at least one value of the string parameters is not empty and is not equal653to “0” then the cache entry with a corresponding654<link id="proxy_cache_key">cache key</link> is removed.655The result of successful operation is indicated by returning656the <http-status code="204" text="No Content"/> response.657</para>658659<para>660If the <link id="proxy_cache_key">cache key</link> of a purge request ends661with an asterisk (“<literal>*</literal>”), all cache entries matching the662wildcard key will be removed from the cache.663However, these entries will remain on the disk until they are deleted664for either <link id="proxy_cache_path">inactivity</link>,665or processed by the <link id="purger">cache purger</link> (1.7.12),666or a client attempts to access them.667</para>668669<para>670Example configuration:671<example>672proxy_cache_path /data/nginx/cache keys_zone=cache_zone:10m;673674map $request_method $purge_method {675PURGE 1;676default 0;677}678679server {680...681location / {682proxy_pass http://backend;683proxy_cache cache_zone;684proxy_cache_key $uri;685proxy_cache_purge $purge_method;686}687}688</example>689<note>690This functionality is available as part of our691<commercial_version>commercial subscription</commercial_version>.692</note>693</para>694695</directive>696697698<directive name="proxy_cache_revalidate">699<syntax><literal>on</literal> | <literal>off</literal></syntax>700<default>off</default>701<context>http</context>702<context>server</context>703<context>location</context>704<appeared-in>1.5.7</appeared-in>705706<para>707Enables revalidation of expired cache items using conditional requests with708the <header>If-Modified-Since</header> and <header>If-None-Match</header>709header fields.710</para>711712</directive>713714715<directive name="proxy_cache_use_stale">716<syntax>717<literal>error</literal> |718<literal>timeout</literal> |719<literal>invalid_header</literal> |720<literal>updating</literal> |721<literal>http_500</literal> |722<literal>http_502</literal> |723<literal>http_503</literal> |724<literal>http_504</literal> |725<literal>http_403</literal> |726<literal>http_404</literal> |727<literal>http_429</literal> |728<literal>off</literal>729...</syntax>730<default>off</default>731<context>http</context>732<context>server</context>733<context>location</context>734735<para>736Determines in which cases a stale cached response can be used737during communication with the proxied server.738The directive’s parameters match the parameters of the739<link id="proxy_next_upstream"/> directive.740</para>741742<para>743The <literal>error</literal> parameter also permits744using a stale cached response if a proxied server to process a request745cannot be selected.746</para>747748<para id="proxy_cache_use_stale_updating">749Additionally, the <literal>updating</literal> parameter permits750using a stale cached response if it is currently being updated.751This allows minimizing the number of accesses to proxied servers752when updating cached data.753</para>754755<para>756Using a stale cached response757can also be enabled directly in the response header758for a specified number of seconds after the response became stale (1.11.10).759This has lower priority than using the directive parameters.760<list type="bullet" compact="no">761762<listitem>763The764“<link url="https://datatracker.ietf.org/doc/html/rfc5861#section-3">stale-while-revalidate</link>”765extension of the <header>Cache-Control</header> header field permits766using a stale cached response if it is currently being updated.767</listitem>768769<listitem>770The771“<link url="https://datatracker.ietf.org/doc/html/rfc5861#section-4">stale-if-error</link>”772extension of the <header>Cache-Control</header> header field permits773using a stale cached response in case of an error.774</listitem>775776</list>777</para>778779<para>780To minimize the number of accesses to proxied servers when781populating a new cache element, the <link id="proxy_cache_lock"/>782directive can be used.783</para>784785</directive>786787788<directive name="proxy_cache_valid">789<syntax>[<value>code</value> ...] <value>time</value></syntax>790<default/>791<context>http</context>792<context>server</context>793<context>location</context>794795<para>796Sets caching time for different response codes.797For example, the following directives798<example>799proxy_cache_valid 200 302 10m;800proxy_cache_valid 404 1m;801</example>802set 10 minutes of caching for responses with codes 200 and 302803and 1 minute for responses with code 404.804</para>805806<para>807If only caching <value>time</value> is specified808<example>809proxy_cache_valid 5m;810</example>811then only 200, 301, and 302 responses are cached.812</para>813814<para>815In addition, the <literal>any</literal> parameter can be specified816to cache any responses:817<example>818proxy_cache_valid 200 302 10m;819proxy_cache_valid 301 1h;820proxy_cache_valid any 1m;821</example>822</para>823824<para>825Parameters of caching can also be set directly826in the response header.827This has higher priority than setting of caching time using the directive.828<list type="bullet" compact="no">829830<listitem>831The <header>X-Accel-Expires</header> header field sets caching time of a832response in seconds.833The zero value disables caching for a response.834If the value starts with the <literal>@</literal> prefix, it sets an absolute835time in seconds since Epoch, up to which the response may be cached.836</listitem>837838<listitem>839If the header does not include the <header>X-Accel-Expires</header> field,840parameters of caching may be set in the header fields841<header>Expires</header> or <header>Cache-Control</header>.842</listitem>843844<listitem>845If the header includes the <header>Set-Cookie</header> field, such a846response will not be cached.847</listitem>848849<listitem>850If the header includes the <header>Vary</header> field851with the special value “<literal>*</literal>”, such a852response will not be cached (1.7.7).853If the header includes the <header>Vary</header> field854with another value, such a response will be cached855taking into account the corresponding request header fields (1.7.7).856</listitem>857858</list>859Processing of one or more of these response header fields can be disabled860using the <link id="proxy_ignore_headers"/> directive.861</para>862863</directive>864865866<directive name="proxy_connect_timeout">867<syntax><value>time</value></syntax>868<default>60s</default>869<context>http</context>870<context>server</context>871<context>location</context>872873<para>874Defines a timeout for establishing a connection with a proxied server.875It should be noted that this timeout cannot usually exceed 75 seconds.876</para>877878</directive>879880881<directive name="proxy_cookie_domain">882<syntax><literal>off</literal></syntax>883<syntax><value>domain</value> <value>replacement</value></syntax>884<default>off</default>885<context>http</context>886<context>server</context>887<context>location</context>888<appeared-in>1.1.15</appeared-in>889890<para>891Sets a text that should be changed in the <literal>domain</literal>892attribute of the <header>Set-Cookie</header> header fields of a893proxied server response.894Suppose a proxied server returned the <header>Set-Cookie</header>895header field with the attribute896“<literal>domain=localhost</literal>”.897The directive898<example>899proxy_cookie_domain localhost example.org;900</example>901will rewrite this attribute to902“<literal>domain=example.org</literal>”.903</para>904905<para>906A dot at the beginning of the <value>domain</value> and907<value>replacement</value> strings and the <literal>domain</literal>908attribute is ignored.909Matching is case-insensitive.910</para>911912<para>913The <value>domain</value> and <value>replacement</value> strings914can contain variables:915<example>916proxy_cookie_domain www.$host $host;917</example>918</para>919920<para>921The directive can also be specified using regular expressions.922In this case, <value>domain</value> should start from923the “<literal>~</literal>” symbol.924A regular expression can contain named and positional captures,925and <value>replacement</value> can reference them:926<example>927proxy_cookie_domain ~\.(?P<sl_domain>[-0-9a-z]+\.[a-z]+)$ $sl_domain;928</example>929</para>930931<para>932Several <literal>proxy_cookie_domain</literal> directives933can be specified on the same level:934<example>935proxy_cookie_domain localhost example.org;936proxy_cookie_domain ~\.([a-z]+\.[a-z]+)$ $1;937</example>938If several directives can be applied to the cookie,939the first matching directive will be chosen.940</para>941942<para>943The <literal>off</literal> parameter cancels the effect944of the <literal>proxy_cookie_domain</literal> directives945inherited from the previous configuration level.946</para>947948</directive>949950951<directive name="proxy_cookie_flags">952<syntax>953<literal>off</literal> |954<value>cookie</value>955[<value>flag</value> ...]</syntax>956<default>off</default>957<context>http</context>958<context>server</context>959<context>location</context>960<appeared-in>1.19.3</appeared-in>961962<para>963Sets one or more flags for the cookie.964The <value>cookie</value> can contain text, variables, and their combinations.965The <value>flag</value>966can contain text, variables, and their combinations (1.19.8).967The968<literal>secure</literal>,969<literal>httponly</literal>,970<literal>samesite=strict</literal>,971<literal>samesite=lax</literal>,972<literal>samesite=none</literal>973parameters add the corresponding flags.974The975<literal>nosecure</literal>,976<literal>nohttponly</literal>,977<literal>nosamesite</literal>978parameters remove the corresponding flags.979</para>980981<para>982The cookie can also be specified using regular expressions.983In this case, <value>cookie</value> should start from984the “<literal>~</literal>” symbol.985</para>986987<para>988Several <literal>proxy_cookie_flags</literal> directives989can be specified on the same configuration level:990<example>991proxy_cookie_flags one httponly;992proxy_cookie_flags ~ nosecure samesite=strict;993</example>994If several directives can be applied to the cookie,995the first matching directive will be chosen.996In the example, the <literal>httponly</literal> flag997is added to the cookie <literal>one</literal>,998for all other cookies999the <literal>samesite=strict</literal> flag is added and1000the <literal>secure</literal> flag is deleted.1001</para>10021003<para>1004The <literal>off</literal> parameter cancels the effect1005of the <literal>proxy_cookie_flags</literal> directives1006inherited from the previous configuration level.1007</para>10081009</directive>101010111012<directive name="proxy_cookie_path">1013<syntax><literal>off</literal></syntax>1014<syntax><value>path</value> <value>replacement</value></syntax>1015<default>off</default>1016<context>http</context>1017<context>server</context>1018<context>location</context>1019<appeared-in>1.1.15</appeared-in>10201021<para>1022Sets a text that should be changed in the <literal>path</literal>1023attribute of the <header>Set-Cookie</header> header fields of a1024proxied server response.1025Suppose a proxied server returned the <header>Set-Cookie</header>1026header field with the attribute1027“<literal>path=/two/some/uri/</literal>”.1028The directive1029<example>1030proxy_cookie_path /two/ /;1031</example>1032will rewrite this attribute to1033“<literal>path=/some/uri/</literal>”.1034</para>10351036<para>1037The <value>path</value> and <value>replacement</value> strings1038can contain variables:1039<example>1040proxy_cookie_path $uri /some$uri;1041</example>1042</para>10431044<para>1045The directive can also be specified using regular expressions.1046In this case, <value>path</value> should either start from1047the “<literal>~</literal>” symbol for a case-sensitive matching,1048or from the “<literal>~*</literal>” symbols for case-insensitive1049matching.1050The regular expression can contain named and positional captures,1051and <value>replacement</value> can reference them:1052<example>1053proxy_cookie_path ~*^/user/([^/]+) /u/$1;1054</example>1055</para>10561057<para>1058Several <literal>proxy_cookie_path</literal> directives1059can be specified on the same level:1060<example>1061proxy_cookie_path /one/ /;1062proxy_cookie_path / /two/;1063</example>1064If several directives can be applied to the cookie,1065the first matching directive will be chosen.1066</para>10671068<para>1069The <literal>off</literal> parameter cancels the effect1070of the <literal>proxy_cookie_path</literal> directives1071inherited from the previous configuration level.1072</para>10731074</directive>107510761077<directive name="proxy_force_ranges">1078<syntax><literal>on</literal> | <literal>off</literal></syntax>1079<default>off</default>1080<context>http</context>1081<context>server</context>1082<context>location</context>1083<appeared-in>1.7.7</appeared-in>10841085<para>1086Enables byte-range support1087for both cached and uncached responses from the proxied server1088regardless of the <header>Accept-Ranges</header> field in these responses.1089</para>10901091</directive>109210931094<directive name="proxy_headers_hash_bucket_size">1095<syntax><value>size</value></syntax>1096<default>64</default>1097<context>http</context>1098<context>server</context>1099<context>location</context>11001101<para>1102Sets the bucket <value>size</value> for hash tables1103used by the <link id="proxy_hide_header"/> and <link id="proxy_set_header"/>1104directives.1105The details of setting up hash tables are provided in a separate1106<link doc="../hash.xml">document</link>.1107</para>11081109</directive>111011111112<directive name="proxy_headers_hash_max_size">1113<syntax><value>size</value></syntax>1114<default>512</default>1115<context>http</context>1116<context>server</context>1117<context>location</context>11181119<para>1120Sets the maximum <value>size</value> of hash tables1121used by the <link id="proxy_hide_header"/> and <link id="proxy_set_header"/>1122directives.1123The details of setting up hash tables are provided in a separate1124<link doc="../hash.xml">document</link>.1125</para>11261127</directive>112811291130<directive name="proxy_hide_header">1131<syntax><value>field</value></syntax>1132<default/>1133<context>http</context>1134<context>server</context>1135<context>location</context>11361137<para>1138By default,1139nginx does not pass the header fields <header>Date</header>,1140<header>Server</header>, <header>X-Pad</header>, and1141<header>X-Accel-...</header> from the response of a proxied1142server to a client.1143The <literal>proxy_hide_header</literal> directive sets additional fields1144that will not be passed.1145If, on the contrary, the passing of fields needs to be permitted,1146the <link id="proxy_pass_header"/> directive can be used.1147</para>11481149</directive>115011511152<directive name="proxy_http_version">1153<syntax>1154<literal>1.0</literal> | <literal>1.1</literal> |1155<literal>2</literal></syntax>1156<default>1.1</default>1157<context>http</context>1158<context>server</context>1159<context>location</context>1160<appeared-in>1.1.4</appeared-in>11611162<para>1163Sets the HTTP protocol version for proxying.1164Since 1.29.7, version 1.1 is used by default.1165Before 1.29.7, version 1.0 was used by default.1166Version 1.1 or 2 (1.29.4) is recommended for use with1167<link doc="ngx_http_upstream_module.xml" id="keepalive"/>1168connections and1169<link doc="ngx_http_upstream_module.xml" id="ntlm">NTLM authentication</link>.1170<note>1171Version 2 requires the1172<link doc="ngx_http_v2_module.xml">ngx_http_v2_module</link> module.1173</note>1174</para>11751176</directive>117711781179<directive name="proxy_ignore_client_abort">1180<syntax><literal>on</literal> | <literal>off</literal></syntax>1181<default>off</default>1182<context>http</context>1183<context>server</context>1184<context>location</context>11851186<para>1187Determines whether the connection with a proxied server should be1188closed when a client closes the connection without waiting1189for a response.1190</para>11911192</directive>119311941195<directive name="proxy_ignore_headers">1196<syntax><value>field</value> ...</syntax>1197<default/>1198<context>http</context>1199<context>server</context>1200<context>location</context>12011202<para>1203Disables processing of certain response header fields from the proxied server.1204The following fields can be ignored: <header>X-Accel-Redirect</header>,1205<header>X-Accel-Expires</header>, <header>X-Accel-Limit-Rate</header> (1.1.6),1206<header>X-Accel-Buffering</header> (1.1.6),1207<header>X-Accel-Charset</header> (1.1.6), <header>Expires</header>,1208<header>Cache-Control</header>, <header>Set-Cookie</header> (0.8.44),1209and <header>Vary</header> (1.7.7).1210</para>12111212<para>1213If not disabled, processing of these header fields has the following1214effect:1215<list type="bullet" compact="no">12161217<listitem>1218<header>X-Accel-Expires</header>, <header>Expires</header>,1219<header>Cache-Control</header>, <header>Set-Cookie</header>,1220and <header>Vary</header>1221set the parameters of response <link id="proxy_cache_valid">caching</link>;1222</listitem>12231224<listitem>1225<header>X-Accel-Redirect</header> performs an1226<link doc="ngx_http_core_module.xml" id="internal">internal1227redirect</link> to the specified URI;1228</listitem>12291230<listitem>1231<header>X-Accel-Limit-Rate</header> sets the1232<link doc="ngx_http_core_module.xml" id="limit_rate">rate1233limit</link> for transmission of a response to a client;1234</listitem>12351236<listitem>1237<header>X-Accel-Buffering</header> enables or disables1238<link id="proxy_buffering">buffering</link> of a response;1239</listitem>12401241<listitem>1242<header>X-Accel-Charset</header> sets the desired1243<link doc="ngx_http_charset_module.xml" id="charset"/>1244of a response.1245</listitem>12461247</list>1248</para>12491250</directive>125112521253<directive name="proxy_intercept_errors">1254<syntax><literal>on</literal> | <literal>off</literal></syntax>1255<default>off</default>1256<context>http</context>1257<context>server</context>1258<context>location</context>12591260<para>1261Determines whether proxied responses with codes greater than or equal1262to 300 should be passed to a client1263or be intercepted and redirected to nginx for processing1264with the <link doc="ngx_http_core_module.xml" id="error_page"/> directive.1265</para>12661267</directive>126812691270<directive name="proxy_limit_rate">1271<syntax><value>rate</value></syntax>1272<default>0</default>1273<context>http</context>1274<context>server</context>1275<context>location</context>1276<appeared-in>1.7.7</appeared-in>12771278<para>1279Limits the speed of reading the response from the proxied server.1280The <value>rate</value> is specified in bytes per second.1281The zero value disables rate limiting.1282The limit is set per a request, and so if nginx simultaneously opens1283two connections to the proxied server,1284the overall rate will be twice as much as the specified limit.1285The limitation works only if1286<link id="proxy_buffering">buffering</link> of responses from the proxied1287server is enabled.1288Parameter value can contain variables (1.27.0).1289</para>12901291</directive>129212931294<directive name="proxy_max_temp_file_size">1295<syntax><value>size</value></syntax>1296<default>1024m</default>1297<context>http</context>1298<context>server</context>1299<context>location</context>13001301<para>1302When <link id="proxy_buffering">buffering</link> of responses from the proxied1303server is enabled, and the whole response does not fit into the buffers1304set by the <link id="proxy_buffer_size"/> and <link id="proxy_buffers"/>1305directives, a part of the response can be saved to a temporary file.1306This directive sets the maximum <value>size</value> of the temporary file.1307The size of data written to the temporary file at a time is set1308by the <link id="proxy_temp_file_write_size"/> directive.1309</para>13101311<para>1312The zero value disables buffering of responses to temporary files.1313</para>13141315<para>1316<note>1317This restriction does not apply to responses1318that will be <link id="proxy_cache">cached</link>1319or <link id="proxy_store">stored</link> on disk.1320</note>1321</para>13221323</directive>132413251326<directive name="proxy_method">1327<syntax><value>method</value></syntax>1328<default/>1329<context>http</context>1330<context>server</context>1331<context>location</context>13321333<para>1334Specifies the HTTP <value>method</value> to use in requests forwarded1335to the proxied server instead of the method from the client request.1336Parameter value can contain variables (1.11.6).1337</para>13381339</directive>134013411342<directive name="proxy_next_upstream">1343<syntax>1344<literal>error</literal> |1345<literal>timeout</literal> |1346<literal>denied</literal> |1347<literal>invalid_header</literal> |1348<literal>http_500</literal> |1349<literal>http_502</literal> |1350<literal>http_503</literal> |1351<literal>http_504</literal> |1352<literal>http_403</literal> |1353<literal>http_404</literal> |1354<literal>http_429</literal> |1355<literal>non_idempotent</literal> |1356<literal>off</literal>1357...</syntax>1358<default>error timeout</default>1359<context>http</context>1360<context>server</context>1361<context>location</context>13621363<para>1364Specifies in which cases a request should be passed to the next server:1365<list type="tag">13661367<tag-name><literal>error</literal></tag-name>1368<tag-desc>an error occurred while establishing a connection with the1369server, passing a request to it, or reading the response header;</tag-desc>13701371<tag-name><literal>timeout</literal></tag-name>1372<tag-desc>a timeout has occurred while establishing a connection with the1373server, passing a request to it, or reading the response header;</tag-desc>13741375<tag-name id="denied"><literal>denied</literal></tag-name>1376<tag-desc>the server <link id="proxy_allow_upstream">denied</link>1377the connection (1.29.3);1378<para>1379<note>1380This parameter is available as part of our1381<commercial_version>commercial subscription</commercial_version>.1382</note>1383</para>1384</tag-desc>13851386<tag-name id="invalid_header"><literal>invalid_header</literal></tag-name>1387<tag-desc>a server returned an empty or invalid response;</tag-desc>13881389<tag-name><literal>http_500</literal></tag-name>1390<tag-desc>a server returned a response with the code 500;</tag-desc>13911392<tag-name><literal>http_502</literal></tag-name>1393<tag-desc>a server returned a response with the code 502;</tag-desc>13941395<tag-name><literal>http_503</literal></tag-name>1396<tag-desc>a server returned a response with the code 503;</tag-desc>13971398<tag-name><literal>http_504</literal></tag-name>1399<tag-desc>a server returned a response with the code 504;</tag-desc>14001401<tag-name><literal>http_403</literal></tag-name>1402<tag-desc>a server returned a response with the code 403;</tag-desc>14031404<tag-name><literal>http_404</literal></tag-name>1405<tag-desc>a server returned a response with the code 404;</tag-desc>14061407<tag-name><literal>http_429</literal></tag-name>1408<tag-desc>a server returned a response with the code 429 (1.11.13);</tag-desc>14091410<tag-name id="non_idempotent"><literal>non_idempotent</literal></tag-name>1411<tag-desc>normally, requests with a1412<link url="https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.2">non-idempotent</link>1413method1414(<literal>POST</literal>, <literal>LOCK</literal>, <literal>PATCH</literal>)1415are not passed to the next server1416if a request has been sent to an upstream server (1.9.13);1417enabling this option explicitly allows retrying such requests;1418</tag-desc>14191420<tag-name><literal>off</literal></tag-name>1421<tag-desc>disables passing a request to the next server.</tag-desc>14221423</list>1424</para>14251426<para>1427One should bear in mind that passing a request to the next server is1428only possible if nothing has been sent to a client yet.1429That is, if an error or timeout occurs in the middle of the1430transferring of a response, fixing this is impossible.1431</para>14321433<para>1434The directive also defines what is considered an1435<link doc="ngx_http_upstream_module.xml" id="max_fails">unsuccessful1436attempt</link> of communication with a server.1437The cases of <literal>error</literal>, <literal>timeout</literal>,1438<literal>denied</literal> and1439<literal>invalid_header</literal> are always considered unsuccessful attempts,1440even if they are not specified in the directive.1441The cases of <literal>http_500</literal>, <literal>http_502</literal>,1442<literal>http_503</literal>, <literal>http_504</literal>,1443and <literal>http_429</literal> are1444considered unsuccessful attempts only if they are specified in the directive.1445The cases of <literal>http_403</literal> and <literal>http_404</literal>1446are never considered unsuccessful attempts.1447</para>14481449<para>1450Passing a request to the next server can be limited by1451<link id="proxy_next_upstream_tries">the number of tries</link>1452and by <link id="proxy_next_upstream_timeout">time</link>.1453</para>14541455</directive>145614571458<directive name="proxy_next_upstream_timeout">1459<syntax><value>time</value></syntax>1460<default>0</default>1461<context>http</context>1462<context>server</context>1463<context>location</context>1464<appeared-in>1.7.5</appeared-in>14651466<para>1467Limits the time during which a request can be passed to the1468<link id="proxy_next_upstream">next server</link>.1469The <literal>0</literal> value turns off this limitation.1470</para>14711472</directive>147314741475<directive name="proxy_next_upstream_tries">1476<syntax><value>number</value></syntax>1477<default>0</default>1478<context>http</context>1479<context>server</context>1480<context>location</context>1481<appeared-in>1.7.5</appeared-in>14821483<para>1484Limits the number of possible tries for passing a request to the1485<link id="proxy_next_upstream">next server</link>.1486The <literal>0</literal> value turns off this limitation.1487</para>14881489</directive>149014911492<directive name="proxy_no_cache">1493<syntax><value>string</value> ...</syntax>1494<default/>1495<context>http</context>1496<context>server</context>1497<context>location</context>14981499<para>1500Defines conditions under which the response will not be saved to a cache.1501If at least one value of the string parameters is not empty and is not1502equal to “0” then the response will not be saved:1503<example>1504proxy_no_cache $cookie_nocache $arg_nocache$arg_comment;1505proxy_no_cache $http_pragma $http_authorization;1506</example>1507Can be used along with the <link id="proxy_cache_bypass"/> directive.1508</para>15091510</directive>151115121513<directive name="proxy_pass">1514<syntax><value>URL</value></syntax>1515<default/>1516<context>location</context>1517<context>if in location</context>1518<context>limit_except</context>15191520<para>1521Sets the protocol and address of a proxied server and an optional URI1522to which a location should be mapped.1523As a protocol, “<literal>http</literal>” or “<literal>https</literal>”1524can be specified.1525The address can be specified as a domain name or IP address,1526and an optional port:1527<example>1528proxy_pass http://localhost:8000/uri/;1529</example>1530or as a UNIX-domain socket path specified after the word1531“<literal>unix</literal>” and enclosed in colons:1532<example>1533proxy_pass http://unix:/tmp/backend.socket:/uri/;1534</example>1535</para>15361537<para>1538If a domain name resolves to several addresses, all of them will be1539used in a round-robin fashion.1540In addition, an address can be specified as a1541<link doc="ngx_http_upstream_module.xml">server group</link>.1542</para>15431544<para>1545Parameter value can contain variables.1546In this case, if an address is specified as a domain name,1547the name is searched among the described server groups,1548and, if not found, is determined using a1549<link doc="ngx_http_core_module.xml" id="resolver"/>.1550</para>15511552<para>1553A request URI is passed to the server as follows:1554<list type="bullet" compact="no">15551556<listitem>1557If the <literal>proxy_pass</literal> directive is specified with a URI,1558then when a request is passed to the server, the part of a1559<link doc="ngx_http_core_module.xml" id="location">normalized</link>1560request URI matching the location is replaced by a URI1561specified in the directive:1562<example>1563location /name/ {1564proxy_pass http://127.0.0.1/remote/;1565}1566</example>1567</listitem>15681569<listitem>1570If <literal>proxy_pass</literal> is specified without a URI,1571the request URI is passed to the server in the same form1572as sent by a client when the original request is processed,1573or the full normalized request URI is passed1574when processing the changed URI:1575<example>1576location /some/path/ {1577proxy_pass http://127.0.0.1;1578}1579</example>1580<note>1581Before version 1.1.12,1582if <literal>proxy_pass</literal> is specified without a URI,1583the original request URI might be passed1584instead of the changed URI in some cases.1585</note>1586</listitem>1587</list>1588</para>15891590<para>1591In some cases, the part of a request URI to be replaced cannot be determined:1592<list type="bullet" compact="no">15931594<listitem>1595When location is specified using a regular expression,1596and also inside named locations.1597<para>1598In these cases,1599<literal>proxy_pass</literal> should be specified without a URI.1600</para>1601</listitem>16021603<listitem>1604When the URI is changed inside a proxied location using the1605<link doc="ngx_http_rewrite_module.xml" id="rewrite"/> directive,1606and this same configuration will be used to process a request1607(<literal>break</literal>):1608<example>1609location /name/ {1610rewrite /name/([^/]+) /users?name=$1 break;1611proxy_pass http://127.0.0.1;1612}1613</example>1614<para>1615In this case, the URI specified in the directive is ignored and1616the full changed request URI is passed to the server.1617</para>1618</listitem>16191620<listitem>1621When variables are used in <literal>proxy_pass</literal>:1622<example>1623location /name/ {1624proxy_pass http://127.0.0.1$request_uri;1625}1626</example>1627In this case, if URI is specified in the directive,1628it is passed to the server as is,1629replacing the original request URI.1630</listitem>1631</list>1632</para>16331634<para>1635<link doc="websocket.xml">WebSocket</link> proxying requires special1636configuration and is supported since version 1.3.13.1637</para>16381639</directive>164016411642<directive name="proxy_pass_header">1643<syntax><value>field</value></syntax>1644<default/>1645<context>http</context>1646<context>server</context>1647<context>location</context>16481649<para>1650Permits passing <link id="proxy_hide_header">otherwise disabled</link> header1651fields from a proxied server to a client.1652</para>16531654</directive>165516561657<directive name="proxy_pass_request_body">1658<syntax><literal>on</literal> | <literal>off</literal></syntax>1659<default>on</default>1660<context>http</context>1661<context>server</context>1662<context>location</context>16631664<para>1665Indicates whether the original request body is passed1666to the proxied server.1667<example>1668location /x-accel-redirect-here/ {1669proxy_method GET;1670proxy_pass_request_body off;1671proxy_set_header Content-Length "";16721673proxy_pass ...1674}1675</example>1676See also the <link id="proxy_set_header"/> and1677<link id="proxy_pass_request_headers"/> directives.1678</para>16791680</directive>168116821683<directive name="proxy_pass_request_headers">1684<syntax><literal>on</literal> | <literal>off</literal></syntax>1685<default>on</default>1686<context>http</context>1687<context>server</context>1688<context>location</context>16891690<para>1691Indicates whether the header fields of the original request are passed1692to the proxied server.1693<example>1694location /x-accel-redirect-here/ {1695proxy_method GET;1696proxy_pass_request_headers off;1697proxy_pass_request_body off;16981699proxy_pass ...1700}1701</example>1702See also the <link id="proxy_set_header"/> and1703<link id="proxy_pass_request_body"/> directives.1704</para>17051706</directive>170717081709<directive name="proxy_pass_trailers">1710<syntax><literal>on</literal> | <literal>off</literal></syntax>1711<default>off</default>1712<context>http</context>1713<context>server</context>1714<context>location</context>1715<appeared-in>1.27.2</appeared-in>17161717<para>1718Permits passing trailer fields from a proxied server to a client.1719</para>17201721<para>1722<note>1723A trailer section should be1724<link url="https://datatracker.ietf.org/doc/html/rfc9110#section-6.5.1">explicitly enabled</link>:1725</note>1726<example>1727location / {1728# proxy_http_version 1.1; #for versions before 1.29.71729proxy_set_header Connection "te";1730proxy_set_header TE "trailers";1731proxy_pass_trailers on;17321733proxy_pass ...1734}1735</example>1736</para>17371738<para>1739<note>1740Trailer fields received from1741an upstream server are passed to a client as is, without interpretation.1742</note>1743</para>17441745</directive>174617471748<directive name="proxy_read_timeout">1749<syntax><value>time</value></syntax>1750<default>60s</default>1751<context>http</context>1752<context>server</context>1753<context>location</context>17541755<para>1756Defines a timeout for reading a response from the proxied server.1757The timeout is set only between two successive read operations,1758not for the transmission of the whole response.1759If the proxied server does not transmit anything within this time,1760the connection is closed.1761</para>17621763</directive>176417651766<directive name="proxy_redirect">1767<syntax><literal>default</literal></syntax>1768<syntax><literal>off</literal></syntax>1769<syntax><value>redirect</value> <value>replacement</value></syntax>1770<default>default</default>1771<context>http</context>1772<context>server</context>1773<context>location</context>17741775<para>1776Sets the text that should be changed in the <header>Location</header>1777and <header>Refresh</header> header fields of a proxied server response.1778Suppose a proxied server returned the header field1779“<literal>Location: http://localhost:8000/two/some/uri/</literal>”.1780The directive1781<example>1782proxy_redirect http://localhost:8000/two/ http://frontend/one/;1783</example>1784will rewrite this string to1785“<literal>Location: http://frontend/one/some/uri/</literal>”.1786</para>17871788<para>1789A server name may be omitted in the <value>replacement</value> string:1790<example>1791proxy_redirect http://localhost:8000/two/ /;1792</example>1793then the primary server’s name and port, if different from 80,1794will be inserted.1795</para>17961797<para>1798The default replacement specified by the <literal>default</literal> parameter1799uses the parameters of the1800<link doc="ngx_http_core_module.xml" id="location"/> and1801<link id="proxy_pass"/> directives.1802Hence, the two configurations below are equivalent:1803<example>1804location /one/ {1805proxy_pass http://upstream:port/two/;1806proxy_redirect default;1807</example>18081809<example>1810location /one/ {1811proxy_pass http://upstream:port/two/;1812proxy_redirect http://upstream:port/two/ /one/;1813</example>1814The <literal>default</literal> parameter is not permitted if1815<link id="proxy_pass"/> is specified using variables.1816</para>18171818<para>1819A <value>replacement</value> string can contain variables:1820<example>1821proxy_redirect http://localhost:8000/ http://$host:$server_port/;1822</example>1823</para>18241825<para>1826A <value>redirect</value> can also contain (1.1.11) variables:1827<example>1828proxy_redirect http://$proxy_host:8000/ /;1829</example>1830</para>18311832<para>1833The directive can be specified (1.1.11) using regular expressions.1834In this case, <value>redirect</value> should either start with1835the “<literal>~</literal>” symbol for a case-sensitive matching,1836or with the “<literal>~*</literal>” symbols for case-insensitive1837matching.1838The regular expression can contain named and positional captures,1839and <value>replacement</value> can reference them:1840<example>1841proxy_redirect ~^(http://[^:]+):\d+(/.+)$ $1$2;1842proxy_redirect ~*/user/([^/]+)/(.+)$ http://$1.example.com/$2;1843</example>1844</para>18451846<para>1847Several <literal>proxy_redirect</literal> directives1848can be specified on the same level:1849<example>1850proxy_redirect default;1851proxy_redirect http://localhost:8000/ /;1852proxy_redirect http://www.example.com/ /;1853</example>1854If several directives can be applied to1855the header fields of a proxied server response,1856the first matching directive will be chosen.1857</para>18581859<para>1860The <literal>off</literal> parameter cancels the effect1861of the <literal>proxy_redirect</literal> directives1862inherited from the previous configuration level.1863</para>18641865<para>1866Using this directive, it is also possible to add host names to relative1867redirects issued by a proxied server:1868<example>1869proxy_redirect / /;1870</example>1871</para>18721873</directive>187418751876<directive name="proxy_request_buffering">1877<syntax><literal>on</literal> | <literal>off</literal></syntax>1878<default>on</default>1879<context>http</context>1880<context>server</context>1881<context>location</context>1882<appeared-in>1.7.11</appeared-in>18831884<para>1885Enables or disables buffering of a client request body.1886</para>18871888<para>1889When buffering is enabled, the entire request body is1890<link doc="ngx_http_core_module.xml" id="client_body_buffer_size">read</link>1891from the client before sending the request to a proxied server.1892</para>18931894<para>1895When buffering is disabled, the request body is sent to the proxied server1896immediately as it is received.1897In this case, the request cannot be passed to the1898<link id="proxy_next_upstream">next server</link>1899if nginx already started sending the request body.1900</para>19011902<para>1903When HTTP/1.1 chunked transfer encoding is used1904to send the original request body,1905the request body will be buffered regardless of the directive value unless1906HTTP/1.1 or HTTP/2 is <link id="proxy_http_version">enabled</link> for proxying.1907</para>19081909</directive>191019111912<directive name="proxy_request_dynamic">1913<syntax><literal>on</literal> | <literal>off</literal></syntax>1914<default>off</default>1915<context>http</context>1916<context>server</context>1917<context>location</context>1918<appeared-in>1.29.3</appeared-in>19191920<para>1921Enables or disables creation of a separate request instance1922for each proxied server.1923By default, a single request is used for all proxied servers.1924If enabled, a separate request instance is created,1925allowing per-server request customization.1926For example, the server-specific <header>Host</header> request header field1927can be set:1928<example>1929proxy_request_dynamic on;1930proxy_set_header Host $upstream_last_server_name;1931</example>1932</para>19331934<para>1935<note>1936This directive is available as part of our1937<commercial_version>commercial subscription</commercial_version>.1938</note>1939</para>19401941</directive>194219431944<directive name="proxy_send_lowat">1945<syntax><value>size</value></syntax>1946<default>0</default>1947<context>http</context>1948<context>server</context>1949<context>location</context>19501951<para>1952If the directive is set to a non-zero value, nginx will try to1953minimize the number1954of send operations on outgoing connections to a proxied server by using either1955<c-def>NOTE_LOWAT</c-def> flag of the1956<link doc="../events.xml" id="kqueue"/> method,1957or the <c-def>SO_SNDLOWAT</c-def> socket option,1958with the specified <value>size</value>.1959</para>19601961<para>1962This directive is ignored on Linux, Solaris, and Windows.1963</para>19641965</directive>196619671968<directive name="proxy_send_timeout">1969<syntax><value>time</value></syntax>1970<default>60s</default>1971<context>http</context>1972<context>server</context>1973<context>location</context>19741975<para>1976Sets a timeout for transmitting a request to the proxied server.1977The timeout is set only between two successive write operations,1978not for the transmission of the whole request.1979If the proxied server does not receive anything within this time,1980the connection is closed.1981</para>19821983</directive>198419851986<directive name="proxy_set_body">1987<syntax><value>value</value></syntax>1988<default/>1989<context>http</context>1990<context>server</context>1991<context>location</context>19921993<para>1994Allows redefining the request body passed to the proxied server.1995The <value>value</value> can contain text, variables, and their combination.1996</para>19971998</directive>199920002001<directive name="proxy_set_header">2002<syntax><value>field</value> <value>value</value></syntax>2003<default>Host $proxy_host</default>2004<default>Connection close</default>2005<context>http</context>2006<context>server</context>2007<context>location</context>20082009<para>2010Allows redefining or appending fields to the request header2011<link id="proxy_pass_request_headers">passed</link> to the proxied server.2012The <value>value</value> can contain text, variables, and their combinations.2013These directives are inherited from the previous configuration level2014if and only if there are no <literal>proxy_set_header</literal> directives2015defined on the current level.2016</para>20172018<para>2019By default, the header fields2020<header>Host</header>2021and2022<header>Connection</header>2023from the original request are not passed to the proxied server.2024If HTTP/1.0 or HTTP/1.1 is2025<link id="proxy_http_version">enabled</link> for proxying,2026these fields are redefined:2027<example>2028proxy_set_header Host $proxy_host;2029proxy_set_header Connection close;2030</example>2031For HTTP/2, the2032<header>:authority</header>2033pseudo-header field with the2034<value>$proxy_host</value>2035value is sent by default,2036unless it is replaced with an explicit <header>Host</header> header field.2037</para>20382039<para>2040If caching is enabled, the header fields2041<header>If-Modified-Since</header>,2042<header>If-Unmodified-Since</header>,2043<header>If-None-Match</header>,2044<header>If-Match</header>,2045<header>Range</header>,2046and2047<header>If-Range</header>2048from the original request are not passed to the proxied server.2049</para>20502051<para>2052An unchanged <header>Host</header> request header field can be passed like this:2053<example>2054proxy_set_header Host $http_host;2055</example>2056</para>20572058<para>2059However, if this field is not present in a client request header then2060nothing will be passed.2061In such a case it is better to use the <var>$host</var> variable—its2062value equals the server name in the <header>Host</header> request header2063field or the primary server name if this field is not present:2064<example>2065proxy_set_header Host $host;2066</example>2067</para>20682069<para>2070In addition, the server name can be passed together with the port of the2071proxied server:2072<example>2073proxy_set_header Host $host:$proxy_port;2074</example>2075</para>20762077<para>2078If the value of a header field is an empty string then this2079field will not be passed to a proxied server:2080<example>2081proxy_set_header Accept-Encoding "";2082</example>2083</para>20842085</directive>208620872088<directive name="proxy_socket_keepalive">2089<syntax><literal>on</literal> | <literal>off</literal></syntax>2090<default>off</default>2091<context>http</context>2092<context>server</context>2093<context>location</context>2094<appeared-in>1.15.6</appeared-in>20952096<para>2097Configures the “TCP keepalive” behavior2098for outgoing connections to a proxied server.2099By default, the operating system’s settings are in effect for the socket.2100If the directive is set to the value “<literal>on</literal>”, the2101<c-def>SO_KEEPALIVE</c-def> socket option is turned on for the socket.2102</para>21032104</directive>210521062107<directive name="proxy_ssl_certificate">2108<syntax><value>file</value></syntax>2109<default/>2110<context>http</context>2111<context>server</context>2112<context>location</context>2113<appeared-in>1.7.8</appeared-in>21142115<para>2116Specifies a <value>file</value> with the certificate in the PEM format2117used for authentication to a proxied HTTPS server.2118</para>21192120<para id="proxy_ssl_certificate_variables">2121Since version 1.21.0, variables can be used in the <value>file</value> name.2122</para>21232124</directive>212521262127<directive name="proxy_ssl_certificate_cache">2128<syntax><literal>off</literal></syntax>2129<syntax>2130<literal>max</literal>=<value>N</value>2131[<literal>inactive</literal>=<value>time</value>]2132[<literal>valid</literal>=<value>time</value>]</syntax>2133<default>off</default>2134<context>http</context>2135<context>server</context>2136<context>location</context>2137<appeared-in>1.27.4</appeared-in>21382139<para>2140Defines a cache that stores2141<link id="proxy_ssl_certificate">SSL certificates</link> and2142<link id="proxy_ssl_certificate_key">secret keys</link>2143specified with <link id="proxy_ssl_certificate_key_variables">variables</link>.2144</para>21452146<para>2147The directive has the following parameters:2148<list type="tag">21492150<tag-name id="proxy_ssl_certificate_cache_max">2151<literal>max</literal>2152</tag-name>2153<tag-desc>2154sets the maximum number of elements in the cache;2155on cache overflow the least recently used (LRU) elements are removed;2156</tag-desc>21572158<tag-name id="proxy_ssl_certificate_cache_inactive">2159<literal>inactive</literal>2160</tag-name>2161<tag-desc>2162defines a time after which an element is removed from the cache2163if it has not been accessed during this time;2164by default, it is 10 seconds;2165</tag-desc>21662167<tag-name id="proxy_ssl_certificate_cache_valid">2168<literal>valid</literal>2169</tag-name>2170<tag-desc>2171defines a time during which2172an element in the cache is considered valid2173and can be reused;2174by default, it is 60 seconds.2175Certificates that exceed this time will be reloaded or revalidated;2176</tag-desc>21772178<tag-name id="proxy_ssl_certificate_cache_off">2179<literal>off</literal>2180</tag-name>2181<tag-desc>2182disables the cache.2183</tag-desc>21842185</list>2186</para>21872188<para>2189Example:2190<example>2191proxy_ssl_certificate $proxy_ssl_server_name.crt;2192proxy_ssl_certificate_key $proxy_ssl_server_name.key;2193proxy_ssl_certificate_cache max=1000 inactive=20s valid=1m;2194</example>2195</para>21962197</directive>219821992200<directive name="proxy_ssl_certificate_key">2201<syntax><value>file</value></syntax>2202<default/>2203<context>http</context>2204<context>server</context>2205<context>location</context>2206<appeared-in>1.7.8</appeared-in>22072208<para>2209Specifies a <value>file</value> with the secret key in the PEM format2210used for authentication to a proxied HTTPS server.2211</para>22122213<para>2214The value2215<literal>engine</literal>:<value>name</value>:<value>id</value>2216can be specified instead of the <value>file</value> (1.7.9),2217which loads a secret key with a specified <value>id</value>2218from the OpenSSL engine <value>name</value>.2219</para>22202221<para>2222The value2223<literal>store</literal>:<value>scheme</value>:<value>id</value>2224can be specified instead of the <value>file</value> (1.29.0),2225which is used to load a secret key with a specified <value>id</value>2226and OpenSSL provider registered URI <value>scheme</value>, such as2227<link url="https://datatracker.ietf.org/doc/html/rfc7512"><literal>pkcs11</literal></link>.2228</para>22292230<para id="proxy_ssl_certificate_key_variables">2231Since version 1.21.0, variables can be used in the <value>file</value> name.2232</para>22332234</directive>223522362237<directive name="proxy_ssl_ciphers">2238<syntax><value>ciphers</value></syntax>2239<default>DEFAULT</default>2240<context>http</context>2241<context>server</context>2242<context>location</context>2243<appeared-in>1.5.6</appeared-in>22442245<para>2246Specifies the enabled ciphers for requests to a proxied HTTPS server.2247The ciphers are specified in the format understood by the OpenSSL library.2248</para>22492250<para>2251The full list can be viewed using the2252“<command>openssl ciphers</command>” command.2253</para>22542255</directive>225622572258<directive name="proxy_ssl_conf_command">2259<syntax><value>name</value> <value>value</value></syntax>2260<default/>2261<context>http</context>2262<context>server</context>2263<context>location</context>2264<appeared-in>1.19.4</appeared-in>22652266<para>2267Sets arbitrary OpenSSL configuration2268<link url="https://www.openssl.org/docs/man1.1.1/man3/SSL_CONF_cmd.html">commands</link>2269when establishing a connection with the proxied HTTPS server.2270<note>2271The directive is supported when using OpenSSL 1.0.2 or higher.2272</note>2273</para>22742275<para>2276Several <literal>proxy_ssl_conf_command</literal> directives2277can be specified on the same level.2278These directives are inherited from the previous configuration level2279if and only if there are2280no <literal>proxy_ssl_conf_command</literal> directives2281defined on the current level.2282</para>22832284<para>2285<note>2286Note that configuring OpenSSL directly2287might result in unexpected behavior.2288</note>2289</para>22902291</directive>229222932294<directive name="proxy_ssl_crl">2295<syntax><value>file</value></syntax>2296<default/>2297<context>http</context>2298<context>server</context>2299<context>location</context>2300<appeared-in>1.7.0</appeared-in>23012302<para>2303Specifies a <value>file</value> with revoked certificates (CRL)2304in the PEM format used to <link id="proxy_ssl_verify">verify</link>2305the certificate of the proxied HTTPS server.2306When using intermediate certificates, their CRLs should be2307specified in the same file.2308</para>23092310</directive>231123122313<directive name="proxy_ssl_key_log">2314<syntax>path</syntax>2315<default/>2316<context>http</context>2317<context>server</context>2318<context>location</context>2319<appeared-in>1.27.2</appeared-in>23202321<para>2322Enables logging of proxied HTTPS server connection SSL keys2323and specifies the path to the key log file.2324Keys are logged in the2325<link url="https://datatracker.ietf.org/doc/html/draft-ietf-tls-keylogfile">SSLKEYLOGFILE</link>2326format compatible with Wireshark.2327</para>23282329<para>2330<note>2331This directive is available as part of our2332<commercial_version>commercial subscription</commercial_version>.2333</note>2334</para>23352336</directive>233723382339<directive name="proxy_ssl_name">2340<syntax><value>name</value></syntax>2341<default>$proxy_host</default>2342<context>http</context>2343<context>server</context>2344<context>location</context>2345<appeared-in>1.7.0</appeared-in>23462347<para>2348Allows overriding the server name used to2349<link id="proxy_ssl_verify">verify</link>2350the certificate of the proxied HTTPS server and to be2351<link id="proxy_ssl_server_name">passed through SNI</link>2352when establishing a connection with the proxied HTTPS server.2353</para>23542355<para>2356By default, the host part of the <link id="proxy_pass"/> URL is used.2357</para>23582359</directive>236023612362<directive name="proxy_ssl_password_file">2363<syntax><value>file</value></syntax>2364<default/>2365<context>http</context>2366<context>server</context>2367<context>location</context>2368<appeared-in>1.7.8</appeared-in>23692370<para>2371Specifies a <value>file</value> with passphrases for2372<link id="proxy_ssl_certificate_key">secret keys</link>2373where each passphrase is specified on a separate line.2374Passphrases are tried in turn when loading the key.2375</para>23762377</directive>237823792380<directive name="proxy_ssl_protocols">2381<syntax>2382[<literal>SSLv2</literal>]2383[<literal>SSLv3</literal>]2384[<literal>TLSv1</literal>]2385[<literal>TLSv1.1</literal>]2386[<literal>TLSv1.2</literal>]2387[<literal>TLSv1.3</literal>]</syntax>2388<default>TLSv1.2 TLSv1.3</default>2389<context>http</context>2390<context>server</context>2391<context>location</context>2392<appeared-in>1.5.6</appeared-in>23932394<para>2395Enables the specified protocols for requests to a proxied HTTPS server.2396</para>23972398<para>2399<note>2400The <literal>TLSv1.3</literal> parameter is used by default2401since 1.23.4.2402</note>2403</para>24042405</directive>240624072408<directive name="proxy_ssl_server_name">2409<syntax><literal>on</literal> | <literal>off</literal></syntax>2410<default>off</default>2411<context>http</context>2412<context>server</context>2413<context>location</context>2414<appeared-in>1.7.0</appeared-in>24152416<para>2417Enables or disables passing of the server name through2418<link url="http://en.wikipedia.org/wiki/Server_Name_Indication">TLS2419Server Name Indication extension</link> (SNI, RFC 6066)2420when establishing a connection with the proxied HTTPS server.2421</para>24222423</directive>242424252426<directive name="proxy_ssl_session_reuse">2427<syntax><literal>on</literal> | <literal>off</literal></syntax>2428<default>on</default>2429<context>http</context>2430<context>server</context>2431<context>location</context>24322433<para>2434Determines whether SSL sessions can be reused when working with2435the proxied server.2436If the errors2437“<literal>digest check failed</literal>”2438appear in the logs, try disabling session reuse.2439</para>24402441</directive>244224432444<directive name="proxy_ssl_trusted_certificate">2445<syntax><value>file</value></syntax>2446<default/>2447<context>http</context>2448<context>server</context>2449<context>location</context>2450<appeared-in>1.7.0</appeared-in>24512452<para>2453Specifies a <value>file</value> with trusted CA certificates in the PEM format2454used to <link id="proxy_ssl_verify">verify</link>2455the certificate of the proxied HTTPS server.2456</para>24572458</directive>245924602461<directive name="proxy_ssl_verify">2462<syntax><literal>on</literal> | <literal>off</literal></syntax>2463<default>off</default>2464<context>http</context>2465<context>server</context>2466<context>location</context>2467<appeared-in>1.7.0</appeared-in>24682469<para>2470Enables or disables verification of the proxied HTTPS server certificate.2471</para>24722473</directive>247424752476<directive name="proxy_ssl_verify_depth">2477<syntax><value>number</value></syntax>2478<default>1</default>2479<context>http</context>2480<context>server</context>2481<context>location</context>2482<appeared-in>1.7.0</appeared-in>24832484<para>2485Sets the verification depth in the proxied HTTPS server certificates chain.2486</para>24872488</directive>248924902491<directive name="proxy_store">2492<syntax>2493<literal>on</literal> |2494<literal>off</literal> |2495<value>string</value></syntax>2496<default>off</default>2497<context>http</context>2498<context>server</context>2499<context>location</context>25002501<para>2502Enables saving of files to a disk.2503The <literal>on</literal> parameter saves files with paths2504corresponding to the directives2505<link doc="ngx_http_core_module.xml" id="alias"/> or2506<link doc="ngx_http_core_module.xml" id="root"/>.2507The <literal>off</literal> parameter disables saving of files.2508In addition, the file name can be set explicitly using the2509<value>string</value> with variables:2510<example>2511proxy_store /data/www$original_uri;2512</example>2513</para>25142515<para>2516The modification time of files is set according to the received2517<header>Last-Modified</header> response header field.2518The response is first written to a temporary file,2519and then the file is renamed.2520Starting from version 0.8.9, temporary files and the persistent store2521can be put on different file systems.2522However, be aware that in this case a file is copied2523across two file systems instead of the cheap renaming operation.2524It is thus recommended that for any given location both saved files and a2525directory holding temporary files, set by the <link id="proxy_temp_path"/>2526directive, are put on the same file system.2527</para>25282529<para>2530This directive can be used to create local copies of static unchangeable2531files, e.g.:2532<example>2533location /images/ {2534root /data/www;2535error_page 404 = /fetch$uri;2536}25372538location /fetch/ {2539internal;25402541proxy_pass http://backend/;2542proxy_store on;2543proxy_store_access user:rw group:rw all:r;2544proxy_temp_path /data/temp;25452546alias /data/www/;2547}2548</example>2549</para>25502551<para>2552or like this:2553<example>2554location /images/ {2555root /data/www;2556error_page 404 = @fetch;2557}25582559location @fetch {2560internal;25612562proxy_pass http://backend;2563proxy_store on;2564proxy_store_access user:rw group:rw all:r;2565proxy_temp_path /data/temp;25662567root /data/www;2568}2569</example>2570</para>25712572</directive>257325742575<directive name="proxy_store_access">2576<syntax><value>users</value>:<value>permissions</value> ...</syntax>2577<default>user:rw</default>2578<context>http</context>2579<context>server</context>2580<context>location</context>25812582<para>2583Sets access permissions for newly created files and directories, e.g.:2584<example>2585proxy_store_access user:rw group:rw all:r;2586</example>2587</para>25882589<para>2590If any <literal>group</literal> or <literal>all</literal> access permissions2591are specified then <literal>user</literal> permissions may be omitted:2592<example>2593proxy_store_access group:rw all:r;2594</example>2595</para>25962597</directive>259825992600<directive name="proxy_temp_file_write_size">2601<syntax><value>size</value></syntax>2602<default>8k|16k</default>2603<context>http</context>2604<context>server</context>2605<context>location</context>26062607<para>2608Limits the <value>size</value> of data written to a temporary file2609at a time, when buffering of responses from the proxied server2610to temporary files is enabled.2611By default, <value>size</value> is limited by two buffers set by the2612<link id="proxy_buffer_size"/> and <link id="proxy_buffers"/> directives.2613The maximum size of a temporary file is set by the2614<link id="proxy_max_temp_file_size"/> directive.2615</para>26162617</directive>261826192620<directive name="proxy_temp_path">2621<syntax>2622<value>path</value>2623[<value>level1</value>2624[<value>level2</value>2625[<value>level3</value>]]]</syntax>2626<default>proxy_temp</default>2627<context>http</context>2628<context>server</context>2629<context>location</context>26302631<para>2632Defines a directory for storing temporary files2633with data received from proxied servers.2634Up to three-level subdirectory hierarchy can be used underneath the specified2635directory.2636For example, in the following configuration2637<example>2638proxy_temp_path /spool/nginx/proxy_temp 1 2;2639</example>2640a temporary file might look like this:2641<example>2642/spool/nginx/proxy_temp/<emphasis>7</emphasis>/<emphasis>45</emphasis>/00000123<emphasis>457</emphasis>2643</example>2644</para>26452646<para>2647See also the <literal>use_temp_path</literal> parameter of the2648<link id="proxy_cache_path"/> directive.2649</para>26502651</directive>26522653</section>265426552656<section id="variables" name="Embedded Variables">26572658<para>2659The <literal>ngx_http_proxy_module</literal> module supports embedded variables2660that can be used to compose headers using the2661<link id="proxy_set_header"/> directive:2662<list type="tag">26632664<tag-name id="var_proxy_host"><var>$proxy_host</var></tag-name>2665<tag-desc>name and port of a proxied server as specified in the2666<link id="proxy_pass"/> directive;</tag-desc>26672668<tag-name id="var_proxy_port"><var>$proxy_port</var></tag-name>2669<tag-desc>port of a proxied server as specified in the2670<link id="proxy_pass"/> directive, or the protocol’s default port;</tag-desc>26712672<tag-name id="var_proxy_add_x_forwarded_for">2673<var>$proxy_add_x_forwarded_for</var></tag-name>2674<tag-desc>the <header>X-Forwarded-For</header> client request header field2675with the <var>$remote_addr</var> variable appended to it, separated by a comma.2676If the <header>X-Forwarded-For</header> field is not present in the client2677request header, the <var>$proxy_add_x_forwarded_for</var> variable is equal2678to the <var>$remote_addr</var> variable.</tag-desc>2679</list>2680</para>26812682</section>26832684</module>268526862687