{"id":401577,"date":"2024-06-29T15:57:05","date_gmt":"2024-06-29T15:57:05","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=401577"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T15:57:05","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=401577","title":{"rendered":"<span>Nginx. \u041e \u0447\u0435\u043c \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043f\u0438\u0441\u0430\u0442\u044c<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042f \u043d\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443. \u0420\u0430\u0437\u0433\u043e\u0432\u043e\u0440 \u043d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u043e \u0441\u043a\u0430\u0442\u0438\u0442\u0441\u044f \u043a \u043d\u0430\u0431\u0438\u0432\u0448\u0435\u043c\u0443 \u043e\u0441\u043a\u043e\u043c\u0438\u043d\u0443 <em>IfisEvil<\/em>. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e \u0438\u0437\u043c\u0443\u0441\u043e\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u0438 \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0438 \u0448\u0443\u043c\u0438\u0445\u0430 \u0432\u043e\u043a\u0440\u0443\u0433 \u043d\u0435\u0433\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043d\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u043a\u043e\u0440\u0435\u043d\u044c \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u0440\u043e&#8230; \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<p>\u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u0432 <em>nginx<\/em> &#8212; \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430. \u0418\u043c\u0435\u043d\u043d\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0438. \u041f\u0440\u0438 \u0441\u043b\u0438\u044f\u043d\u0438\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u0438 \u0435\u0451 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0442\u0435\u043a\u0443\u0449\u0438\u0439. \u041b\u043e\u0433\u0438\u0447\u043d\u043e, \u0447\u0442\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u0442 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u0442 \u0441\u043e\u0441\u0435\u0434\u043d\u0435\u0433\u043e <em>location<\/em> \u0438\u043b\u0438 <em>if<\/em>.<\/p>\n<p>\u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e. \u041f\u043e\u043a\u0430 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p><em>N.B.: \u0417\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 nginx \u0432\u0435\u0440\u0441\u0438\u0438 1.21.1 (\u0435\u0441\u043b\u0438 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0438\u043d\u043e\u0435). \u0412\u0441\u0451 \u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043d\u0430 \u043e\u043f\u044b\u0442\u0435 \u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0430\u0432\u0442\u043e\u0440\u0430. \u0412\u043c\u0435\u0441\u0442\u0435 \u0441 \u0442\u0435\u043c \u0430\u0432\u0442\u043e\u0440 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c nginx \u0438 \u0434\u0430\u0436\u0435 \u0435\u0433\u043e \u043c\u0430\u0441\u0442\u0438\u0442\u044b\u043c \u0441\u0432\u0430\u0440\u0449\u0438\u043a\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430 \u0430\u0432\u0442\u043e\u0440\u0430 \u043a\u0430\u043a \u0434\u043e\u0433\u043c\u0443, \u0430, \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u043f\u043e\u0434\u0432\u0435\u0440\u0433\u0430\u0442\u044c \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u044e \u0438 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e.<\/em> <\/p>\n<p>\u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043d\u0435 \u0432\u0441\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f. \u0422\u0430\u043a \u0432 <em>location<\/em> \u043d\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442\u0441\u044f:<\/p>\n<ol>\n<li>\n<p>\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u043c\u043e\u0434\u0443\u043b\u044f\u00a0<em>rewrite:<\/em><\/p>\n<ul>\n<li>\n<p><em>break<\/em><\/p>\n<\/li>\n<li>\n<p><em>if<\/em><\/p>\n<\/li>\n<li>\n<p><em>return<\/em><\/p>\n<\/li>\n<li>\n<p><em>rewrite<\/em><\/p>\n<\/li>\n<li>\n<p><em>set<\/em><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><em>try_files<\/em><\/p>\n<\/li>\n<li>\n<p>\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0444\u0430\u0437\u044b\u00a0<em>CONTENT<\/em>\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0445 \u043d\u0435\u043a\u0443\u044e \u044f\u0432\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 (\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0442\u0434\u0430\u0447\u0438 \u0441\u0442\u0430\u0442\u0438\u043a\u0438):<\/p>\n<ul>\n<li>\n<p><em>grpc_pass<\/em><\/p>\n<\/li>\n<li>\n<p><em>fastcgi_pass<\/em><\/p>\n<\/li>\n<li>\n<p><em>memcached_pass<\/em><\/p>\n<\/li>\n<li>\n<p><em>proxy_pass<\/em><\/p>\n<\/li>\n<li>\n<p><em>scgi_pass<\/em><\/p>\n<\/li>\n<li>\n<p><em>uwsgi_pass<\/em><\/p>\n<\/li>\n<li>\n<p><em>empty_gif<\/em><\/p>\n<\/li>\n<li>\n<p><em>flv<\/em><\/p>\n<\/li>\n<li>\n<p><em>mp4<\/em><\/p>\n<\/li>\n<li>\n<p><em>stub_status<\/em><\/p>\n<\/li>\n<li>\n<p><em>perl<\/em><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u0447\u0430\u0441\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043d\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0441\u0432\u043e\u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b (\u044d\u0442\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0435\u0441\u0442\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e):<\/p>\n<ul>\n<li>\n<p><em>limit_req<\/em><\/p>\n<\/li>\n<li>\n<p><em>sub_filter<\/em><\/p>\n<\/li>\n<li>\n<p><em>ssl_conf_command<\/em><\/p>\n<\/li>\n<li>\n<p><em>scgi_param<\/em><\/p>\n<\/li>\n<li>\n<p><em>add_header<\/em><\/p>\n<\/li>\n<li>\n<p><em>add_trailer<\/em><\/p>\n<\/li>\n<li>\n<p><em>uwsgi_param<\/em><\/p>\n<\/li>\n<li>\n<p><em>uwsgi_ssl_conf_command<\/em><\/p>\n<\/li>\n<li>\n<p><em>fastcgi_param<\/em><\/p>\n<\/li>\n<li>\n<p><em>xslt_param \u0438 xslt_string_param<\/em><\/p>\n<\/li>\n<li>\n<p><em>proxy_set_header <\/em><\/p>\n<\/li>\n<li>\n<p><em>proxy_ssl_conf_command<\/em><\/p>\n<\/li>\n<li>\n<p><em>grpc_set_header<\/em><\/p>\n<\/li>\n<li>\n<p><em>grpc_ssl_conf_command<\/em><\/p>\n<\/li>\n<li>\n<p><em>error_page<\/em><\/p>\n<\/li>\n<li>\n<p><em>limit_conn<\/em><\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u043e\u0433\u0434\u0430 \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0438\u0441\u0430\u0442\u044c\u00a0<em>proxy_pass<\/em>\u00a0\u0432 \u043a\u0430\u0436\u0434\u044b\u0439\u00a0<em>location<\/em>\u00a0\u0438 \u0442.\u043f., \u043d\u043e \u043a \u043d\u0438\u043c \u043f\u0440\u0438\u0432\u044b\u043a\u0430\u0435\u0448\u044c \u0438 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0448\u044c \u044d\u0442\u043e \u043a\u0430\u043a \u0444\u0438\u0447\u0443, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442\u00a0<em>if.<\/em> <em>\u00a0If<\/em>\u00a0\u043d\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u043e\u043d \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u0441\u0451, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f, \u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 <em>nginx<\/em> \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u043d\u0435\u0435 (\u0433\u0434\u0435-\u0442\u043e \u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 <em>1.8.0<\/em>) \u0437\u0430\u043f\u0440\u043e\u0441 \u043a <em>example.com\/if-and-alias\/1.html<\/em><\/p>\n<pre><code class=\"nginx\">location ~* ^\/if-and-alias\/(?&lt;file>.*) {   alias \/tmp\/$file;    set $true 1;    if ($true) {     # nothing   } }<\/code><\/pre>\n<p>\u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b \u043a \u043e\u0448\u0438\u0431\u043a\u0435 <em>404 Not Found<\/em> \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0432 <em>\/tmp<\/em>. \u0414\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0431\u0435\u0437\u043e\u0433\u043b\u044f\u0434\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <em>if<\/em> \u0432 <em>location<\/em>. \u041c\u043d\u043e\u0433\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c, \u0442\u043e\u0447\u043d\u0435\u0435, \u0442\u0430\u043a \u0438 \u0437\u0430\u0434\u0443\u043c\u0430\u043d\u043e. <\/p>\n<blockquote>\n<p><em>Not really bug, just how it works.<\/em><\/p>\n<\/blockquote>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438 \u0446\u0438\u0442\u0430\u0442\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u0432\u0437\u044f\u0442\u044b \u0438\u0437 <a href=\"https:\/\/www.nginx.com\/resources\/wiki\/start\/topics\/depth\/ifisevil\/\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430<\/a>. \u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0438\u0437 \u043d\u0435\u0433\u043e \u043f\u0435\u0440\u0432\u0443\u044e \u0436\u0435 \u0437\u0430\u0434\u0430\u0447\u043a\u0443, \u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443 <em>add_header<\/em> \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 <em>server<\/em>:<\/p>\n<pre><code class=\"nginx\">add_header X-Zero 0; location \/only-one-if {     set $true 1;      if ($true) {         add_header X-First 1;     }      if ($true) {         add_header X-Second 2;     }      return 204; }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <em>X-Second<\/em>, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b <em>add_header<\/em> \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b:<\/p>\n<pre><code class=\"nginx\">$ HEAD -S \"example.com\/only-one-if\" | grep -F 'X-' X-Second: 2<\/code><\/pre>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u0432\u0441\u0451 \u043b\u043e\u0433\u0438\u0447\u043d\u043e. \u041a\u0430\u0436\u0434\u044b\u0439 <em>if<\/em> \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 <em>location<\/em>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442\u0441\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, \u043d\u043e (\u043a\u0430\u043a \u043f\u0438\u0441\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u0448\u0435) \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432a <em>add_header<\/em> \u043d\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0441\u0432\u043e\u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b. \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u043e\u0442 \u0441\u043e\u0441\u0435\u0434\u043d\u0435\u0433\u043e <em>if<\/em>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c <em>if<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 (\u043f\u0440\u0438 \u0435\u0433\u043e \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0441\u0442\u0438) \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c. \u041d\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 <em>add_header<\/em> \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0438 \u0444\u0430\u0437\u044b <em>REWRITE<\/em>, \u0442\u043e \u0435\u0441\u0442\u044c, \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u043c\u043e\u0434\u0443\u043b\u044f <em>ngx_http_rewrite_module<\/em>, \u043e\u043d\u0438 <strong>\u0432\u0441\u0435<\/strong> \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u0434\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 <em>add_header<\/em>:<\/p>\n<pre><code class=\"nginx\">location \/only-one-if {     set $true 1;     set $a 0;      if ($true) {         set $a $a:1;         add_header X-First $a;     }      if ($true) {         set $a $a:2;         add_header X-Second $a;     }     set $a $a:3;     return 204; }<\/code><\/pre>\n<pre><code class=\"bash\">$ HEAD -S \"example.com\/only-one-if\" | grep -F 'X-' X-Second: 0:1:2:3<\/code><\/pre>\n<p>\u0414\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b <em>ngx_http_rewrite_module<\/em> \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443:<\/p>\n<ol>\n<li>\n<p>\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f <em>a = 0<\/em>;<\/p>\n<\/li>\n<li>\n<p>\u0434\u0430\u043b\u0435\u0435 <em>a = 0:1<\/em>, \u0442\u0430\u043a \u043a\u0430\u043a \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e <em>if<\/em> \u0438\u0441\u0442\u0438\u043d\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>\u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e <em>if<\/em> \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u0442\u0438\u043d\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 <em>a = 0:1:2<\/em>;<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0432 \u0441 <em>if<\/em>&#8216;\u0430\u043c\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0432 location \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 <em>a = 0:1:2:3<\/em><\/p>\n<\/li>\n<li>\n<p>\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043f\u0435\u0440\u044c, \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0432 <em>return&#8217;\u043e\u043c<\/em> \u0444\u0430\u0437\u0443 <em>REWRITE<\/em>, \u0432 \u0444\u0438\u043b\u044c\u0442\u0440\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <em>X-Second<\/em> <em>= 0:1:2:3<\/em><\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432 \u043e\u0442\u043b\u0430\u0434\u0447\u0438\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"bash\">$ cat \/tmp\/error.log | grep -iE \"(if|var|set|header|value)\" | cut -d ' ' -f 6- ... using configuration \"\/only-one-if\" http script value: \"1\" http script set $true http script value: \"0\" http script set $a http script var http script var: \"1\" http script if http script complex value http script var: \"0\" http script set $a http script var http script var: \"1\" http script if http script complex value http script var: \"0:1\" http script set $a http script complex value http script var: \"0:1:2\" http script set $a http set discard body http script var: \"0:1:2:3\" ADD HEADER: 'X-Second' => '0:1:2:3' http finalize request: 0, \"\/only-one-if?\"<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0437\u0430\u0434\u0430\u0447\u0435 \u0432\u0437\u044f\u0442\u043e\u0439 <a href=\"https:\/\/agentzh.blogspot.com\/2011\/03\/how-nginx-location-if-works.html\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a>:<\/p>\n<pre><code class=\"nginx\">location \/proxy {   proxy_pass http:\/\/127.0.0.1:8080\/$a;      set $a 32;      if ($a = 32) {     set $a 56;   }      set $a 76; }  location ~ \/(\\d+) {   echo $1; }<\/code><\/pre>\n<p>\u0421\u043d\u043e\u0432\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b <em>set: a = 32, a = 56, a = 76<\/em>, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0444\u0430\u0437\u0430\u043c \u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u0435\u0431\u044f \u0436\u0435, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432 \u043e\u0442\u0432\u0435\u0442:<\/p>\n<pre><code class=\"bash\">$ GET -S \"example.com\/proxy\" GET http:\/\/example.com\/proxy 200 OK 76<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0440\u0430\u0437\u0431\u043e\u0440\u0430 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0443\u0436\u0435 \u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c, \u043d\u043e \u0437\u0434\u0435\u0441\u044c \u0437\u0430\u043e\u0434\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c <em>location<\/em> \u0438 <em>if<\/em>:<\/p>\n<pre><code class=\"nginx\">location \/proxy {   proxy_pass http:\/\/127.0.0.1:8080\/$a;      set $a 32;      if ($a = 32) {     set $a 56;   }      set $a 76;      location \/proxy\/location {   }    }<\/code><\/pre>\n<p>\u0418 \u044d\u0442\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0434\u0430\u0435\u0442 \u043d\u0430\u043c<\/p>\n<pre><code class=\"bash\">$ GET -Sd \"example.com\/proxy\/location\" GET http:\/\/example.com\/proxy\/location 404 Not Found<\/code><\/pre>\n<p>\u0442\u0430\u043a \u043a\u0430\u043a \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 <em>proxy_pass<\/em> \u043d\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u0432 <em>location<\/em>.<\/p>\n<p>\u0410 \u0432\u043e\u0442 \u044d\u0442\u043e\u0442 \u0436\u0443\u0442\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440<\/p>\n<pre><code class=\"nginx\">location \/proxy {   proxy_pass http:\/\/127.0.0.1:8080\/$a;      set $a 32;      if ($a = 32) {     set $a 56;   }      set $a 76;      if ($uri ~ '\/proxy\/location') {   }    }<\/code><\/pre>\n<p>\u0432\u0432\u0438\u0434\u0443 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e <em>if<\/em> \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0451, \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e:<\/p>\n<pre><code class=\"bash\">$ GET -S \"example.com\/proxy\/location\" GET http:\/\/example.com\/proxy\/location 200 OK 76<\/code><\/pre>\n<p>\u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a \u043d\u0435 \u043d\u0430\u0434\u043e!<\/p>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438, \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e &#171;\u043d\u0435\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u043e\u0433\u043e&#187; \u0441\u043f\u0438\u0441\u043a\u0430, \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e <em>try_files:<\/em><\/p>\n<pre><code class=\"nginx\">location \/itf {      try_files  \/file  @fallback;       set $true 1;       if ($true) {          # nothing      } }  location @fallback {     echo \"fallback\"; }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043d\u0435 \u043f\u043e\u043f\u0430\u0434\u0435\u043c \u0432 <em>&#171;@fallback&#187;<\/em>, <em>if<\/em> \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 <em>try_files, <\/em>\u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0432\u043d\u0443\u0442\u0440\u0438 <em>if<\/em> \u043d\u0435 \u0443\u0434\u0430\u0441\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e <em>location<\/em>:<\/p>\n<pre><code class=\"nginx\">location \/itf {     try_files  \/file  @fallback;      set $true 1;      location \/itf\/itf2 {     } }<\/code><\/pre>\n<p>\u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u0434\u0430\u0441\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430:<\/p>\n<pre><code class=\"bash\">$ GET -Sd \"example.com\/itf\/itf2\" GET http:\/\/example.com\/itf\/itf2 404 Not Found<\/code><\/pre>\n<p>\u0442\u0430\u043a \u043a\u0430\u043a \u0438 \u0432 <em>location <\/em>\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 <em>try_files <\/em>\u043d\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f<em>. <\/em>\u041d\u043e \u0437\u0434\u0435\u0441\u044c \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0451 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>\u0412\u043e\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438 \u0432\u0441\u0451 &#8212; \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0431\u0430\u0433\u043e\u0432 \u0432 <em>if<\/em> \u043d\u0435\u0442. \u0415\u0441\u0442\u044c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0433\u0434\u0435-\u0442\u043e \u043e\u0431\u0449\u0438\u0435, \u0433\u0434\u0435-\u0442\u043e \u0441\u0432\u043e\u0438 \u0434\u043b\u044f <em>if<\/em> \u0438 \u0441\u0432\u043e\u0438 \u0434\u043b\u044f <em>location,<\/em> \u0438 \u043a\u0430\u043a\u0430\u044f-\u043d\u0438\u0431\u0443\u0434\u044c \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0430 \u0438\u043b\u0438 \u0441\u043a\u0440\u043e\u043c\u043d\u0430\u044f \u0441\u0432\u043e\u0434\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0430 \u0441 (\u043d\u0435)\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u044b\u043c\u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430\u043c\u0438 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0441\u043d\u044f\u0442\u044c \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0435 \u0432\u043e\u043a\u0440\u0443\u0433 \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u044b.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/572324\/\"> https:\/\/habr.com\/ru\/articles\/572324\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042f \u043d\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443. \u0420\u0430\u0437\u0433\u043e\u0432\u043e\u0440 \u043d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u043e \u0441\u043a\u0430\u0442\u0438\u0442\u0441\u044f \u043a \u043d\u0430\u0431\u0438\u0432\u0448\u0435\u043c\u0443 \u043e\u0441\u043a\u043e\u043c\u0438\u043d\u0443 <em>IfisEvil<\/em>. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e \u0438\u0437\u043c\u0443\u0441\u043e\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u0438 \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0438 \u0448\u0443\u043c\u0438\u0445\u0430 \u0432\u043e\u043a\u0440\u0443\u0433 \u043d\u0435\u0433\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043d\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u043a\u043e\u0440\u0435\u043d\u044c \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u0440\u043e&#8230; \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<p>\u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u0432 <em>nginx<\/em> &#8212; \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430. \u0418\u043c\u0435\u043d\u043d\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0438. \u041f\u0440\u0438 \u0441\u043b\u0438\u044f\u043d\u0438\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u0438 \u0435\u0451 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0442\u0435\u043a\u0443\u0449\u0438\u0439. \u041b\u043e\u0433\u0438\u0447\u043d\u043e, \u0447\u0442\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u0442 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043e\u0442 \u0441\u043e\u0441\u0435\u0434\u043d\u0435\u0433\u043e <em>location<\/em> \u0438\u043b\u0438 <em>if<\/em>.<\/p>\n<p>\u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e. \u041f\u043e\u043a\u0430 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p><em>N.B.: \u0417\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 nginx \u0432\u0435\u0440\u0441\u0438\u0438 1.21.1 (\u0435\u0441\u043b\u0438 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0438\u043d\u043e\u0435). \u0412\u0441\u0451 \u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043d\u0430 \u043e\u043f\u044b\u0442\u0435 \u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0430\u0432\u0442\u043e\u0440\u0430. \u0412\u043c\u0435\u0441\u0442\u0435 \u0441 \u0442\u0435\u043c \u0430\u0432\u0442\u043e\u0440 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c nginx \u0438 \u0434\u0430\u0436\u0435 \u0435\u0433\u043e \u043c\u0430\u0441\u0442\u0438\u0442\u044b\u043c \u0441\u0432\u0430\u0440\u0449\u0438\u043a\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430 \u0430\u0432\u0442\u043e\u0440\u0430 \u043a\u0430\u043a \u0434\u043e\u0433\u043c\u0443, \u0430, \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u043f\u043e\u0434\u0432\u0435\u0440\u0433\u0430\u0442\u044c \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u044e \u0438 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e.<\/em> <\/p>\n<p>\u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043d\u0435 \u0432\u0441\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f. \u0422\u0430\u043a \u0432 <em>location<\/em> \u043d\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442\u0441\u044f:<\/p>\n<ol>\n<li>\n<p>\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u043c\u043e\u0434\u0443\u043b\u044f\u00a0<em>rewrite:<\/em><\/p>\n<ul>\n<li>\n<p><em>break<\/em><\/p>\n<\/li>\n<li>\n<p><em>if<\/em><\/p>\n<\/li>\n<li>\n<p><em>return<\/em><\/p>\n<\/li>\n<li>\n<p><em>rewrite<\/em><\/p>\n<\/li>\n<li>\n<p><em>set<\/em><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><em>try_files<\/em><\/p>\n<\/li>\n<li>\n<p>\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0444\u0430\u0437\u044b\u00a0<em>CONTENT<\/em>\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0445 \u043d\u0435\u043a\u0443\u044e \u044f\u0432\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 (\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0442\u0434\u0430\u0447\u0438 \u0441\u0442\u0430\u0442\u0438\u043a\u0438):<\/p>\n<ul>\n<li>\n<p><em>grpc_pass<\/em><\/p>\n<\/li>\n<li>\n<p><em>fastcgi_pass<\/em><\/p>\n<\/li>\n<li>\n<p><em>memcached_pass<\/em><\/p>\n<\/li>\n<li>\n<p><em>proxy_pass<\/em><\/p>\n<\/li>\n<li>\n<p><em>scgi_pass<\/em><\/p>\n<\/li>\n<li>\n<p><em>uwsgi_pass<\/em><\/p>\n<\/li>\n<li>\n<p><em>empty_gif<\/em><\/p>\n<\/li>\n<li>\n<p><em>flv<\/em><\/p>\n<\/li>\n<li>\n<p><em>mp4<\/em><\/p>\n<\/li>\n<li>\n<p><em>stub_status<\/em><\/p>\n<\/li>\n<li>\n<p><em>perl<\/em><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u0447\u0430\u0441\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043d\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0441\u0432\u043e\u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b (\u044d\u0442\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0435\u0441\u0442\u044c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e):<\/p>\n<ul>\n<li>\n<p><em>limit_req<\/em><\/p>\n<\/li>\n<li>\n<p><em>sub_filter<\/em><\/p>\n<\/li>\n<li>\n<p><em>ssl_conf_command<\/em><\/p>\n<\/li>\n<li>\n<p><em>scgi_param<\/em><\/p>\n<\/li>\n<li>\n<p><em>add_header<\/em><\/p>\n<\/li>\n<li>\n<p><em>add_trailer<\/em><\/p>\n<\/li>\n<li>\n<p><em>uwsgi_param<\/em><\/p>\n<\/li>\n<li>\n<p><em>uwsgi_ssl_conf_command<\/em><\/p>\n<\/li>\n<li>\n<p><em>fastcgi_param<\/em><\/p>\n<\/li>\n<li>\n<p><em>xslt_param \u0438 xslt_string_param<\/em><\/p>\n<\/li>\n<li>\n<p><em>proxy_set_header <\/em><\/p>\n<\/li>\n<li>\n<p><em>proxy_ssl_conf_command<\/em><\/p>\n<\/li>\n<li>\n<p><em>grpc_set_header<\/em><\/p>\n<\/li>\n<li>\n<p><em>grpc_ssl_conf_command<\/em><\/p>\n<\/li>\n<li>\n<p><em>error_page<\/em><\/p>\n<\/li>\n<li>\n<p><em>limit_conn<\/em><\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u043e\u0433\u0434\u0430 \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0438\u0441\u0430\u0442\u044c\u00a0<em>proxy_pass<\/em>\u00a0\u0432 \u043a\u0430\u0436\u0434\u044b\u0439\u00a0<em>location<\/em>\u00a0\u0438 \u0442.\u043f., \u043d\u043e \u043a \u043d\u0438\u043c \u043f\u0440\u0438\u0432\u044b\u043a\u0430\u0435\u0448\u044c \u0438 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0448\u044c \u044d\u0442\u043e \u043a\u0430\u043a \u0444\u0438\u0447\u0443, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442\u00a0<em>if.<\/em> <em>\u00a0If<\/em>\u00a0\u043d\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u043e\u043d \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u0441\u0451, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f, \u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 <em>nginx<\/em> \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u043d\u0435\u0435 (\u0433\u0434\u0435-\u0442\u043e \u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 <em>1.8.0<\/em>) \u0437\u0430\u043f\u0440\u043e\u0441 \u043a <em>example.com\/if-and-alias\/1.html<\/em><\/p>\n<pre><code class=\"nginx\">location ~* ^\/if-and-alias\/(?&lt;file>.*) {   alias \/tmp\/$file;    set $true 1;    if ($true) {     # nothing   } }<\/code><\/pre>\n<p>\u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b \u043a \u043e\u0448\u0438\u0431\u043a\u0435 <em>404 Not Found<\/em> \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0432 <em>\/tmp<\/em>. \u0414\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0431\u0435\u0437\u043e\u0433\u043b\u044f\u0434\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <em>if<\/em> \u0432 <em>location<\/em>. \u041c\u043d\u043e\u0433\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c, \u0442\u043e\u0447\u043d\u0435\u0435, \u0442\u0430\u043a \u0438 \u0437\u0430\u0434\u0443\u043c\u0430\u043d\u043e. <\/p>\n<blockquote>\n<p><em>Not really bug, just how it works.<\/em><\/p>\n<\/blockquote>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438 \u0446\u0438\u0442\u0430\u0442\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u0432\u0437\u044f\u0442\u044b \u0438\u0437 <a href=\"https:\/\/www.nginx.com\/resources\/wiki\/start\/topics\/depth\/ifisevil\/\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430<\/a>. \u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0438\u0437 \u043d\u0435\u0433\u043e \u043f\u0435\u0440\u0432\u0443\u044e \u0436\u0435 \u0437\u0430\u0434\u0430\u0447\u043a\u0443, \u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443 <em>add_header<\/em> \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 <em>server<\/em>:<\/p>\n<pre><code class=\"nginx\">add_header X-Zero 0; location \/only-one-if {     set $true 1;      if ($true) {         add_header X-First 1;     }      if ($true) {         add_header X-Second 2;     }      return 204; }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <em>X-Second<\/em>, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b <em>add_header<\/em> \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b:<\/p>\n<pre><code class=\"nginx\">$ HEAD -S \"example.com\/only-one-if\" | grep -F 'X-' X-Second: 2<\/code><\/pre>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u0432\u0441\u0451 \u043b\u043e\u0433\u0438\u0447\u043d\u043e. \u041a\u0430\u0436\u0434\u044b\u0439 <em>if<\/em> \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 <em>location<\/em>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442\u0441\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, \u043d\u043e (\u043a\u0430\u043a \u043f\u0438\u0441\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u0448\u0435) \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432a <em>add_header<\/em> \u043d\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0441\u0432\u043e\u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b. \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u043e\u0442 \u0441\u043e\u0441\u0435\u0434\u043d\u0435\u0433\u043e <em>if<\/em>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c <em>if<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 (\u043f\u0440\u0438 \u0435\u0433\u043e \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0441\u0442\u0438) \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c. \u041d\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 <em>add_header<\/em> \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0438 \u0444\u0430\u0437\u044b <em>REWRITE<\/em>, \u0442\u043e \u0435\u0441\u0442\u044c, \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u043c\u043e\u0434\u0443\u043b\u044f <em>ngx_http_rewrite_module<\/em>, \u043e\u043d\u0438 <strong>\u0432\u0441\u0435<\/strong> \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u0434\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 <em>add_header<\/em>:<\/p>\n<pre><code class=\"nginx\">location \/only-one-if {     set $true 1;     set $a 0;      if ($true) {         set $a $a:1;         add_header X-First $a;     }      if ($true) {         set $a $a:2;         add_header X-Second $a;     }     set $a $a:3;     return 204; }<\/code><\/pre>\n<pre><code class=\"bash\">$ HEAD -S \"example.com\/only-one-if\" | grep -F 'X-' X-Second: 0:1:2:3<\/code><\/pre>\n<p>\u0414\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b <em>ngx_http_rewrite_module<\/em> \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443:<\/p>\n<ol>\n<li>\n<p>\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f <em>a = 0<\/em>;<\/p>\n<\/li>\n<li>\n<p>\u0434\u0430\u043b\u0435\u0435 <em>a = 0:1<\/em>, \u0442\u0430\u043a \u043a\u0430\u043a \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e <em>if<\/em> \u0438\u0441\u0442\u0438\u043d\u043d\u043e;<\/p>\n<\/li>\n<li>\n<p>\u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e <em>if<\/em> \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u0442\u0438\u043d\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 <em>a = 0:1:2<\/em>;<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0432 \u0441 <em>if<\/em>&#8216;\u0430\u043c\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0432 location \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 <em>a = 0:1:2:3<\/em><\/p>\n<\/li>\n<li>\n<p>\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043f\u0435\u0440\u044c, \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0432 <em>return&#8217;\u043e\u043c<\/em> \u0444\u0430\u0437\u0443 <em>REWRITE<\/em>, \u0432 \u0444\u0438\u043b\u044c\u0442\u0440\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <em>X-Second<\/em> <em>= 0:1:2:3<\/em><\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>\u041a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432 \u043e\u0442\u043b\u0430\u0434\u0447\u0438\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"bash\">$ cat \/tmp\/error.log | grep -iE \"(if|var|set|header|value)\" | cut -d ' ' -f 6- ... using configuration \"\/only-one-if\" http script value: \"1\" http script set $true http script value: \"0\" http script set $a http script var http script var: \"1\" http script if http script complex value http script var: \"0\" http script set $a http script var http script var: \"1\" http script if http script complex value http script var: \"0:1\" http script set $a http script complex value http script var: \"0:1:2\" http script set $a http set discard body http script var: \"0:1:2:3\" ADD HEADER: 'X-Second' => '0:1:2:3' http finalize request: 0, \"\/only-one-if?\"<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0437\u0430\u0434\u0430\u0447\u0435 \u0432\u0437\u044f\u0442\u043e\u0439 <a href=\"https:\/\/agentzh.blogspot.com\/2011\/03\/how-nginx-location-if-works.html\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a>:<\/p>\n<pre><code class=\"nginx\">location \/proxy {   proxy_pass http:\/\/127.0.0.1:8080\/$a;      set $a 32;      if ($a = 32) {     set $a 56;   }      set $a 76; }  location ~ \/(\\d+) {   echo $1; }<\/code><\/pre>\n<p>\u0421\u043d\u043e\u0432\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b <em>set: a = 32, a = 56, a = 76<\/em>, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0444\u0430\u0437\u0430\u043c \u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u0435\u0431\u044f \u0436\u0435, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432 \u043e\u0442\u0432\u0435\u0442:<\/p>\n<pre><code class=\"bash\">$ GET -S \"example.com\/proxy\" GET http:\/\/example.com\/proxy 200 OK 76<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0440\u0430\u0437\u0431\u043e\u0440\u0430 \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0443\u0436\u0435 \u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c, \u043d\u043e \u0437\u0434\u0435\u0441\u044c \u0437\u0430\u043e\u0434\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c <em>location<\/em> \u0438 <em>if<\/em>:<\/p>\n<pre><code class=\"nginx\">location \/proxy {   proxy_pass http:\/\/127.0.0.1:8080\/$a;      set $a 32;      if ($a = 32) {     set $a 56;   }      set $a 76;      location \/proxy\/location {   }    }<\/code><\/pre>\n<p>\u0418 \u044d\u0442\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0434\u0430\u0435\u0442 \u043d\u0430\u043c<\/p>\n<pre><code class=\"bash\">$ GET -Sd \"example.com\/proxy\/location\" GET http:\/\/example.com\/proxy\/location 404 Not Found<\/code><\/pre>\n<p>\u0442\u0430\u043a \u043a\u0430\u043a \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 <em>proxy_pass<\/em> \u043d\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u0432 <em>location<\/em>.<\/p>\n<p>\u0410 \u0432\u043e\u0442 \u044d\u0442\u043e\u0442 \u0436\u0443\u0442\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440<\/p>\n<pre><code class=\"nginx\">location \/proxy {   proxy_pass http:\/\/127.0.0.1:8080\/$a;      set $a 32;      if ($a = 32) {     set $a 56;   }      set $a 76;      if ($uri ~ '\/proxy\/location') {   }    }<\/code><\/pre>\n<p>\u0432\u0432\u0438\u0434\u0443 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e <em>if<\/em> \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0451, \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e:<\/p>\n<pre><code class=\"bash\">$ GET -S \"example.com\/proxy\/location\" GET http:\/\/example.com\/proxy\/location 200 OK 76<\/code><\/pre>\n<p>\u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a \u043d\u0435 \u043d\u0430\u0434\u043e!<\/p>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438, \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e &#171;\u043d\u0435\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u043e\u0433\u043e&#187; \u0441\u043f\u0438\u0441\u043a\u0430, \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e <em>try_files:<\/em><\/p>\n<pre><code class=\"nginx\">location \/itf {      try_files  \/file  @fallback;       set $true 1;       if ($true) {          # nothing      } }  location @fallback {     echo \"fallback\"; }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043d\u0435 \u043f\u043e\u043f\u0430\u0434\u0435\u043c \u0432 <em>&#171;@fallback&#187;<\/em>, <em>if<\/em> \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 <em>try_files, <\/em>\u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0432\u043d\u0443\u0442\u0440\u0438 <em>if<\/em> \u043d\u0435 \u0443\u0434\u0430\u0441\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0443. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e <em>location<\/em>:<\/p>\n<pre><code class=\"nginx\">location \/itf {     try_files  \/file  @fallback;      set $true 1;      location \/itf\/itf2 {     } }<\/code><\/pre>\n<p>\u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u0434\u0430\u0441\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430:<\/p>\n<pre><code class=\"bash\">$ GET -Sd \"example.com\/itf\/itf2\" GET http:\/\/example.com\/itf\/itf2 404 Not Found<\/code><\/pre>\n<p>\u0442\u0430\u043a \u043a\u0430\u043a \u0438 \u0432 <em>location <\/em>\u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 <em>try_files <\/em>\u043d\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f<em>. <\/em>\u041d\u043e \u0437\u0434\u0435\u0441\u044c \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0451 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>\u0412\u043e\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438 \u0432\u0441\u0451 &#8212; \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0431\u0430\u0433\u043e\u0432 \u0432 <em>if<\/em> \u043d\u0435\u0442. \u0415\u0441\u0442\u044c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0433\u0434\u0435-\u0442\u043e \u043e\u0431\u0449\u0438\u0435, \u0433\u0434\u0435-\u0442\u043e \u0441\u0432\u043e\u0438 \u0434\u043b\u044f <em>if<\/em> \u0438 \u0441\u0432\u043e\u0438 \u0434\u043b\u044f <em>location,<\/em> \u0438 \u043a\u0430\u043a\u0430\u044f-\u043d\u0438\u0431\u0443\u0434\u044c \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0430 \u0438\u043b\u0438 \u0441\u043a\u0440\u043e\u043c\u043d\u0430\u044f \u0441\u0432\u043e\u0434\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0430 \u0441 (\u043d\u0435)\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u044b\u043c\u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430\u043c\u0438 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0441\u043d\u044f\u0442\u044c \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0435 \u0432\u043e\u043a\u0440\u0443\u0433 \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u044b.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/572324\/\"> https:\/\/habr.com\/ru\/articles\/572324\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-401577","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/401577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=401577"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/401577\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=401577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=401577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=401577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}