CINXE.COM

IfIsEvil

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head><script type="text/javascript" src="https://web-static.archive.org/_static/js/bundle-playback.js?v=7YQSqjSh" charset="utf-8"></script> <script type="text/javascript" src="https://web-static.archive.org/_static/js/wombat.js?v=txqj7nKC" charset="utf-8"></script> <script>window.RufflePlayer=window.RufflePlayer||{};window.RufflePlayer.config={"autoplay":"on","unmuteOverlay":"hidden"};</script> <script type="text/javascript" src="https://web-static.archive.org/_static/js/ruffle/ruffle.js"></script> <script type="text/javascript"> __wm.init("https://web.archive.org/web"); __wm.wombat("http://wiki.nginx.org:80/IfIsEvil","20121216232625","https://web.archive.org/","web","https://web-static.archive.org/_static/", "1355700385"); </script> <link rel="stylesheet" type="text/css" href="https://web-static.archive.org/_static/css/banner-styles.css?v=p7PEIJWi" /> <link rel="stylesheet" type="text/css" href="https://web-static.archive.org/_static/css/iconochive.css?v=3PDvdIFv" /> <!-- End Wayback Rewrite JS Include --> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta name="generator" content="MediaWiki 1.19.0"/> <link rel="alternate" type="application/x-wiki" title="Edit" href="/web/20121216232625/http://wiki.nginx.org/index.php?title=IfIsEvil&amp;action=edit"/> <link rel="edit" title="Edit" href="/index.php?title=IfIsEvil&amp;action=edit"/> <link rel="shortcut icon" href="/web/20121216232625im_/http://wiki.nginx.org/favicon.ico"/> <link rel="search" type="application/opensearchdescription+xml" href="/web/20121216232625/http://wiki.nginx.org/opensearch_desc.php" title="Nginx Community (en)"/> <link rel="EditURI" type="application/rsd+xml" href="http://wiki.nginx.org/api.php?action=rsd"/> <link rel="copyright" href="https://web.archive.org/web/20121216232625/http://creativecommons.org/licenses/by/3.0/"/> <link rel="alternate" type="application/atom+xml" title="Nginx Community Atom feed" href="/web/20121216232625/http://wiki.nginx.org/index.php?title=Special:RecentChanges&amp;feed=atom"/> <title>IfIsEvil</title> <link rel="stylesheet" type="text/css" href="/web/20121216232625cs_/http://wiki.nginx.org/skins/bluwiki_skin/main.css" media="screen"/> <link rel="stylesheet" type="text/css" href="/web/20121216232625cs_/http://wiki.nginx.org/skins/bluwiki_skin/clean.css" media="print"/> <script type="text/javascript" src="/web/20121216232625js_/http://wiki.nginx.org/skins/common/wikibits.js"></script> <!-- Head Scripts --> <script src="https://web.archive.org/web/20121216232625js_/http://wiki.nginx.org/load.php?debug=false&amp;lang=en&amp;modules=startup&amp;only=scripts&amp;skin=bluwiki_skin&amp;*"></script> <script>if(window.mw){ mw.config.set({"wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"IfIsEvil","wgTitle":"IfIsEvil","wgCurRevisionId":466,"wgArticleId":435,"wgIsArticle":true,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":[],"wgBreakFrames":false,"wgPageContentLanguage":"en","wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgRelevantPageName":"IfIsEvil","wgRestrictionEdit":[],"wgRestrictionMove":[]}); }</script><script>if(window.mw){ mw.loader.implement("user.options",function($){mw.user.options.set({"ccmeonemails":0,"cols":80,"date":"default","diffonly":0,"disablemail":0,"disablesuggest":0,"editfont":"default","editondblclick":0,"editsection":1,"editsectiononrightclick":0,"enotifminoredits":0,"enotifrevealaddr":0,"enotifusertalkpages":1,"enotifwatchlistpages":0,"extendwatchlist":0,"externaldiff":0,"externaleditor":0,"fancysig":0,"forceeditsummary":0,"gender":"unknown","hideminor":0,"hidepatrolled":0,"highlightbroken":1,"imagesize":2,"justify":0,"math":1,"minordefault":0,"newpageshidepatrolled":0,"nocache":0,"noconvertlink":0,"norollbackdiff":0,"numberheadings":0,"previewonfirst":0,"previewontop":1,"quickbar":5,"rcdays":7,"rclimit":50,"rememberpassword":0,"rows":25,"searchlimit":20,"showhiddencats":0,"showjumplinks":1,"shownumberswatching":1,"showtoc":1,"showtoolbar":1,"skin":"bluwiki_skin","stubthreshold":0,"thumbsize":2,"underline":2,"uselivepreview":0,"usenewrc":0,"watchcreations":0,"watchdefault":0, "watchdeletion":0,"watchlistdays":3,"watchlisthideanons":0,"watchlisthidebots":0,"watchlisthideliu":0,"watchlisthideminor":0,"watchlisthideown":0,"watchlisthidepatrolled":0,"watchmoves":0,"wllimit":250,"variant":"en","language":"en","searchNs0":true,"searchNs1":false,"searchNs2":false,"searchNs3":false,"searchNs4":false,"searchNs5":false,"searchNs6":false,"searchNs7":false,"searchNs8":false,"searchNs9":false,"searchNs10":false,"searchNs11":false,"searchNs12":false,"searchNs13":false,"searchNs14":false,"searchNs15":false});;},{},{});mw.loader.implement("user.tokens",function($){mw.user.tokens.set({"editToken":"+\\","watchToken":false});;},{},{}); /* cache key: wikidb:resourceloader:filter:minify-js:7:f7aad1866ca6dd9429d876811ee74c3f */ }</script> <script>if(window.mw){ mw.loader.load(["mediawiki.page.startup","mediawiki.legacy.wikibits"]); }</script><style type="text/css">/*<![CDATA[*/ .source-nginx {line-height: normal;} .source-nginx li, .source-nginx pre { line-height: normal; border: 0px none white; } /** * GeSHi Dynamically Generated Stylesheet * -------------------------------------- * Dynamically generated stylesheet for nginx * CSS class: source-nginx, CSS id: * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) * -------------------------------------- */ .nginx.source-nginx .de1, .nginx.source-nginx .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;} .nginx.source-nginx {font-family:monospace;} .nginx.source-nginx .imp {font-weight: bold; color: red;} .nginx.source-nginx li, .nginx.source-nginx .li1 {font-weight: normal; vertical-align:top;} .nginx.source-nginx .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;} .nginx.source-nginx .li2 {font-weight: bold; vertical-align:top;} .nginx.source-nginx .kw1 {color: #b1b100;} .nginx.source-nginx .kw2 {color: #000000; font-weight: bold;} .nginx.source-nginx .kw3 {color: #000066;} .nginx.source-nginx .kw4 {color: #993333;} .nginx.source-nginx .co1 {color: #808080; font-style: italic;} .nginx.source-nginx .co2 {color: #339933;} .nginx.source-nginx .coMULTI {color: #808080; font-style: italic;} .nginx.source-nginx .es0 {color: #000099; font-weight: bold;} .nginx.source-nginx .br0 {color: #66cc66;} .nginx.source-nginx .sy0 {color: #66cc66;} .nginx.source-nginx .st0 {color: #ff0000;} .nginx.source-nginx .me1 {color: #202020;} .nginx.source-nginx .me2 {color: #202020;} .nginx.source-nginx .ln-xtra, .nginx.source-nginx li.ln-xtra, .nginx.source-nginx div.ln-xtra {background-color: #ffc;} .nginx.source-nginx span.xtra { display:block; } /*]]>*/ </style> <style type="text/css">/*<![CDATA[*/ @import "/web/20121216232625cs_/http://wiki.nginx.org/index.php?title=MediaWiki:Geshi.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000"; /*]]>*/ </style> <style> .editsection, #toolbar, #user-tools { display: none; } </style> </head> <body> <div id="titleBar"> <table id="fuck-ie"> <tr> <td width="30%"> <div id="userlogin"> <a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=Special:UserLogin&amp;returnto=IfIsEvil" title="Log in / create account">Log in / create account</a> </div> </td> <td width="60%" align="right"> <form name="searchform" action="/web/20121216232625/http://wiki.nginx.org/Special:Search" id="searchform" method="get"> <input id="searchInput" name="search" type="text" accesskey="f" value=""/> <!-- <input type='submit' name="go" class="searchButton" id="searchGoButton" value="Go" /> --> <input type="submit" name="fulltext" class="searchButton" value="Search"/> </form> </td> <td width="4em" align="left" style="padding: 0 0 0 1em;"><a href="Faq" id="faqlink">FAQ</a></td> </tr> </table> </div> <!--<a class="portlet" id="p-logo" href="/Main" title="Main"> <img src="/local/nginx-logo.png" /> </a>--> <a class="portlet" id="p-logo" href="/web/20121216232625/http://wiki.nginx.org/Main" title="Main"> <img src="/web/20121216232625im_/http://wiki.nginx.org/local/nginx-logo.png"/> </a> <div style="float: right;"> <ul id="icon-nav"> <li><a href="/web/20121216232625/http://wiki.nginx.org/Install"><img src="/web/20121216232625im_/http://wiki.nginx.org/local/install.png" alt="Install"/><br/>Install</a></li> <li><a href="/web/20121216232625/http://wiki.nginx.org/Modules"><img src="/web/20121216232625im_/http://wiki.nginx.org/local/modules.png" alt="Modules"/><br/>Modules</a></li> <li><a href="/web/20121216232625/http://wiki.nginx.org/3rdPartyModules"><img src="/web/20121216232625im_/http://wiki.nginx.org/local/addons.png" alt="Addons"/><br/>Addons</a></li> <li><a href="/web/20121216232625/http://wiki.nginx.org/Configuration"><img src="/web/20121216232625im_/http://wiki.nginx.org/local/configure.png" alt="Configure"/><br/>Configure</a></li> <li><a href="/web/20121216232625/http://wiki.nginx.org/Community"><img src="/web/20121216232625im_/http://wiki.nginx.org/local/community.png" alt="Community"/><br/>Community</a></li> <li><a href="/web/20121216232625/http://wiki.nginx.org/Resources"><img src="/web/20121216232625im_/http://wiki.nginx.org/local/resources.png" alt="Other Resources"/><br/>Resources</a></li> <li><a href="https://web.archive.org/web/20121216232625/http://trac.nginx.org/nginx"><img src="/web/20121216232625im_/http://wiki.nginx.org/local/trac.png" alt="Bug reports, feature requests"/><br/>Trac</a></li> </ul> </div> </div> <br style="clear: both;"/> <div class="visualClear"></div> <div id="globalWrapper"> <div id="content"> <a name="top" id="contentTop"></a> <div id="toolbar"> <a href="/web/20121216232625/http://wiki.nginx.org/IfIsEvil" title="Page"><img src="/web/20121216232625im_/http://wiki.nginx.org/skins/bluwiki_skin/Article-small.png" class="selected" alt="Page"/></a> <a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=Talk:IfIsEvil&amp;action=edit&amp;redlink=1" title="Discussion"><img src="/web/20121216232625im_/http://wiki.nginx.org/skins/bluwiki_skin/Discussion-small.png" class="new" alt="Discussion"/></a> <a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=IfIsEvil&amp;action=edit" title="Edit"><img src="/web/20121216232625im_/http://wiki.nginx.org/skins/bluwiki_skin/Edit-small.png" class="" alt="Edit"/></a> <a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=IfIsEvil&amp;action=history" title="History"><img src="/web/20121216232625im_/http://wiki.nginx.org/skins/bluwiki_skin/History-small.png" class="" alt="History"/></a> </div> <h1 class="firstHeading">IfIsEvil</h1> <div id="bodyContent"> <div id="contentSub"></div> <!-- start content --> <div id="mw-content-text" lang="en" dir="ltr" class="mw-content-ltr"><table id="toc" class="toc"><tr><td><div id="toctitle"><h2>Contents</h2></div> <ul> <li class="toclevel-1 tocsection-1"><a href="#Introduction"><span class="tocnumber">1</span> <span class="toctext">Introduction</span></a></li> <li class="toclevel-1 tocsection-2"><a href="#What_to_do_instead"><span class="tocnumber">2</span> <span class="toctext">What to do instead</span></a></li> <li class="toclevel-1 tocsection-3"><a href="#Examples"><span class="tocnumber">3</span> <span class="toctext">Examples</span></a></li> <li class="toclevel-1 tocsection-4"><a href="#Why_this_happens_and_still_not_fixed"><span class="tocnumber">4</span> <span class="toctext">Why this happens and still not fixed</span></a></li> <li class="toclevel-1 tocsection-5"><a href="#If_you_still_want_to_use_if"><span class="tocnumber">5</span> <span class="toctext">If you still want to use if</span></a></li> </ul> </td></tr></table> <h1><span class="editsection">[<a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=IfIsEvil&amp;action=edit&amp;section=1" title="Edit section: Introduction">edit</a>]</span> <span class="mw-headline" id="Introduction"> Introduction </span></h1> <p>Directive <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#if" title="NginxHttpRewriteModule" class="mw-redirect">if</a> has problems when used in location context, in some cases it doesn't do what you expect but something completely different instead. In some cases it even segfaults. It's generally a good idea to avoid it if possible. </p><p>The only 100% safe things which may be done inside if in location context are: </p> <ul><li> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#return" title="NginxHttpRewriteModule" class="mw-redirect">return</a> ...; </li><li> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#rewrite" title="NginxHttpRewriteModule" class="mw-redirect">rewrite</a> ... last; </li></ul> <p>Anything else may possibly cause unpredictable behaviour, including potential SIGSEGV. </p><p>It is important to note that the behaviour of if is not inconsistent, given two identical requests it will not randomly fail on one and work on the other, with proper testing and understanding ifs <b>can</b> be used. The advice to use other directives where available still very much apply, though. </p><p>There are cases where you simply cannot avoid using an if, for example if you need to test a variable which has no equivalent directive. </p> <div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="nginx source-nginx"><pre class="de1"><a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#if"><span class="kw22">if</span></a> <span class="br0">&#40;</span><span class="re0">$request_method</span> <span class="sy0">=</span> POST <span class="br0">&#41;</span> <span class="br0">&#123;</span> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#return"><span class="kw22">return</span></a> <span class="nu0">405</span><span class="sy0">;</span> <span class="br0">&#125;</span> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#if"><span class="kw22">if</span></a> <span class="br0">&#40;</span><span class="re0">$args</span> <span class="sy0">~</span> post<span class="sy0">=</span><span class="nu0">140</span><span class="br0">&#41;</span><span class="br0">&#123;</span> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#rewrite"><span class="kw22">rewrite</span></a> ^ <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#http"><span class="kw3">http</span></a>://example.com/ permanent<span class="sy0">;</span> <span class="br0">&#125;</span></pre></div></div> <h1><span class="editsection">[<a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=IfIsEvil&amp;action=edit&amp;section=2" title="Edit section: What to do instead">edit</a>]</span> <span class="mw-headline" id="What_to_do_instead"> What to do instead </span></h1> <p>Use <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#try_files" title="NginxHttpCoreModule" class="mw-redirect">try_files</a> if it suits your needs. Use the "return ..." or "rewrite ... last" in other cases. In some cases it's also possible to move ifs to server level (where it's safe as only other rewrite module directives are allowed within it). </p><p>E.g. the following may be used to safely change location which will be used to process request: </p> <div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="nginx source-nginx"><pre class="de1"> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#location"><span class="kw3">location</span></a> / <span class="br0">&#123;</span> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#error_page"><span class="kw3">error_page</span></a> <span class="nu0">418</span> <span class="sy0">=</span> <span class="re0">@other</span><span class="sy0">;</span> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#recursive_error_pages"><span class="kw3">recursive_error_pages</span></a> on<span class="sy0">;</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#if"><span class="kw22">if</span></a> <span class="br0">&#40;</span><span class="re0">$something</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#return"><span class="kw22">return</span></a> <span class="nu0">418</span><span class="sy0">;</span> <span class="br0">&#125;</span> &#160; <span class="co1"># some configuration</span> ... <span class="br0">&#125;</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#location"><span class="kw3">location</span></a> <span class="re0">@other</span> <span class="br0">&#123;</span> <span class="co1"># some other configuration</span> ... <span class="br0">&#125;</span></pre></div></div> <p>In some cases it may be good idea to use embedded scripting modules (<a href="/web/20121216232625/http://wiki.nginx.org/EmbeddedPerlModule" title="EmbeddedPerlModule" class="mw-redirect">embedded perl</a>, or various <a href="/web/20121216232625/http://wiki.nginx.org/3rdPartyModules" title="3rdPartyModules">3rd party modules</a>) to do the scripting. </p> <h1><span class="editsection">[<a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=IfIsEvil&amp;action=edit&amp;section=3" title="Edit section: Examples">edit</a>]</span> <span class="mw-headline" id="Examples"> Examples </span></h1> <p>Here are some examples which explain why if is evil. Don't try this at home. You were warned. </p> <div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="nginx source-nginx"><pre class="de1"> <span class="co1"># Here is collection of unexpectedly buggy configurations to show that</span> <span class="co1"># if inside location is evil.</span> &#160; <span class="co1"># only second header will be present in response</span> <span class="co1"># not really bug, just how it works</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#location"><span class="kw3">location</span></a> /only-one-<a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#if"><span class="kw22">if</span></a> <span class="br0">&#123;</span> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#set"><span class="kw22">set</span></a> <span class="re0">$true</span> <span class="nu0">1</span><span class="sy0">;</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#if"><span class="kw22">if</span></a> <span class="br0">&#40;</span><span class="re0">$true</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpHeadersModule#add_header"><span class="kw14">add_header</span></a> X-First <span class="nu0">1</span><span class="sy0">;</span> <span class="br0">&#125;</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#if"><span class="kw22">if</span></a> <span class="br0">&#40;</span><span class="re0">$true</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpHeadersModule#add_header"><span class="kw14">add_header</span></a> X-Second <span class="nu0">2</span><span class="sy0">;</span> <span class="br0">&#125;</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#return"><span class="kw22">return</span></a> <span class="nu0">204</span><span class="sy0">;</span> <span class="br0">&#125;</span> &#160; <span class="co1"># request will be sent to backend without uri changed</span> <span class="co1"># to '/' due to if</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#location"><span class="kw3">location</span></a> /proxy-pass-uri <span class="br0">&#123;</span> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpProxyModule#proxy_pass"><span class="kw21">proxy_pass</span></a> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#http"><span class="kw3">http</span></a>://127.0.0.1:<span class="nu0">8080</span>/<span class="sy0">;</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#set"><span class="kw22">set</span></a> <span class="re0">$true</span> <span class="nu0">1</span><span class="sy0">;</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#if"><span class="kw22">if</span></a> <span class="br0">&#40;</span><span class="re0">$true</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="co1"># nothing</span> <span class="br0">&#125;</span> <span class="br0">&#125;</span> &#160; <span class="co1"># try_files wont work due to if</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#location"><span class="kw3">location</span></a> /if-try-files <span class="br0">&#123;</span> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#try_files"><span class="kw3">try_files</span></a> /file <span class="re0">@fallback</span><span class="sy0">;</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#set"><span class="kw22">set</span></a> <span class="re0">$true</span> <span class="nu0">1</span><span class="sy0">;</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#if"><span class="kw22">if</span></a> <span class="br0">&#40;</span><span class="re0">$true</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="co1"># nothing</span> <span class="br0">&#125;</span> <span class="br0">&#125;</span> &#160; <span class="co1"># nginx will SIGSEGV</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#location"><span class="kw3">location</span></a> /crash <span class="br0">&#123;</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#set"><span class="kw22">set</span></a> <span class="re0">$true</span> <span class="nu0">1</span><span class="sy0">;</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#if"><span class="kw22">if</span></a> <span class="br0">&#40;</span><span class="re0">$true</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="co1"># fastcgi_pass here</span> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpFcgiModule#fastcgi_pass"><span class="kw11">fastcgi_pass</span></a> 127.0.0.1:<span class="nu0">9000</span><span class="sy0">;</span> <span class="br0">&#125;</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#if"><span class="kw22">if</span></a> <span class="br0">&#40;</span><span class="re0">$true</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="co1"># no handler here</span> <span class="br0">&#125;</span> <span class="br0">&#125;</span> &#160; <span class="co1"># alias with captures isn't correcly inherited into implicit nested</span> <span class="co1"># location created by if</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#location"><span class="kw3">location</span></a> <span class="sy0">~</span>* ^/if-and-<a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#alias"><span class="kw3">alias</span></a>/<span class="br0">&#40;</span>?<span class="re4">&lt;file&gt;</span>.*<span class="br0">&#41;</span> <span class="br0">&#123;</span> <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpCoreModule#alias"><span class="kw3">alias</span></a> /tmp/<span class="re0">$file</span><span class="sy0">;</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#set"><span class="kw22">set</span></a> <span class="re0">$true</span> <span class="nu0">1</span><span class="sy0">;</span> &#160; <a href="/web/20121216232625/http://wiki.nginx.org/NginxHttpRewriteModule#if"><span class="kw22">if</span></a> <span class="br0">&#40;</span><span class="re0">$true</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="co1"># nothing</span> <span class="br0">&#125;</span> <span class="br0">&#125;</span></pre></div></div> <p>In case you think you found an example which isn't listed here - it's a good idea to report it to <a href="/web/20121216232625/http://wiki.nginx.org/User:MaximDounin" title="User:MaximDounin">MaximDounin</a>. </p> <h1><span class="editsection">[<a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=IfIsEvil&amp;action=edit&amp;section=4" title="Edit section: Why this happens and still not fixed">edit</a>]</span> <span class="mw-headline" id="Why_this_happens_and_still_not_fixed"> Why this happens and still not fixed </span></h1> <p>Directive "if" is part of rewrite module which evaluates instructions imperatively. On the other hand, nginx configuration in general is declarative. At some point due to users demand an attempt was made to enable some non-rewrite directives inside "if", and this lead to situation we have now. It mostly works, but... see above. </p><p>Looks like the only correct fix would be to disable non-rewrite directives inside if completely. It would break many configuration out there though, so wasn't done yet. </p> <h1><span class="editsection">[<a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=IfIsEvil&amp;action=edit&amp;section=5" title="Edit section: If you still want to use if">edit</a>]</span> <span class="mw-headline" id="If_you_still_want_to_use_if"> If you still want to use if </span></h1> <p>If you read all of the above and still want to use if: </p> <ul><li> Please make sure you actually do understand how it works. Some basic idea may be found e.g. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20121216232625/http://agentzh.blogspot.com/2011/03/how-nginx-location-if-works.html">here</a>. </li><li> Do proper testing. </li></ul> <p>You were warned. </p> <!-- NewPP limit report Preprocessor node count: 45/1000000 Post-expand include size: 0/2097152 bytes Template argument size: 0/2097152 bytes Expensive parser function count: 0/100 --> <!-- Saved in parser cache with key wikidb:pcache:idhash:435-0!*!0!!en!*!* and timestamp 20121026025241 --> </div><div class="printfooter"> Retrieved from "<a href="https://web.archive.org/web/20121216232625/http://wiki.nginx.org/index.php?title=IfIsEvil&amp;oldid=466">http://wiki.nginx.org/index.php?title=IfIsEvil&amp;oldid=466</a>"</div> <!--<div id="catlinks"><div id='catlinks' class='catlinks catlinks-allhidden'></div></div>--> <!-- end content --> <div class="visualClear"></div> </div> </div> </div> <!-- Close global wrapper --> <div id="dropdownpanel"> <div class="contentdiv"> <div id="toolbox"> <!-- begin toolbox --> <div id="user-tools"> <div id="p-cactions" class="portlet"> <h5>Views</h5> <ul> <li id="ca-nstab-main" class="selected"> <a href="/web/20121216232625/http://wiki.nginx.org/IfIsEvil"> Page</a></li> <li id="ca-talk" class="new"> <a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=Talk:IfIsEvil&amp;action=edit&amp;redlink=1"> Discussion</a></li> <li id="ca-edit"> <a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=IfIsEvil&amp;action=edit"> Edit</a></li> <li id="ca-history"> <a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=IfIsEvil&amp;action=history"> History</a></li> </ul> </div> <div class="portlet" id="p-tb"> <h5>Toolbox</h5> <div class="pBody"> <ul> <li id="t-whatlinkshere"><a href="/web/20121216232625/http://wiki.nginx.org/Special:WhatLinksHere/IfIsEvil">What links here</a></li> <li id="t-recentchangeslinked"><a href="/web/20121216232625/http://wiki.nginx.org/Special:RecentChangesLinked/IfIsEvil">Related changes</a></li> <li id="t-specialpages"><a href="/web/20121216232625/http://wiki.nginx.org/Special:SpecialPages">Special pages</a></li> <li id="t-print"><a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=IfIsEvil&amp;printable=yes">Printable version</a></li> <li id="t-permalink"><a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=IfIsEvil&amp;oldid=466">Permanent link</a></li> </ul> </div> </div> <div class="portlet" id="p-personal"> <h5>Personal tools</h5> <div class="pBody"> <ul> <li id="pt-login"><a href="/web/20121216232625/http://wiki.nginx.org/index.php?title=Special:UserLogin&amp;returnto=IfIsEvil">Log in / create account</a></li> </ul> </div> </div> <!-- <div class='portlet' id='p-navigation'> <h5>Navigation</h5> <div class='pBody'> <ul> <li id="n-mainpage-description"><a href="/Main">Main page</a></li> <li id="n-portal"><a href="/Nginx_Community:Community_portal">Community portal</a></li> <li id="n-currentevents"><a href="/Nginx_Community:Current_events">Current events</a></li> <li id="n-recentchanges"><a href="/Special:RecentChanges">Recent changes</a></li> <li id="n-randompage"><a href="/Special:Random">Random page</a></li> <li id="n-help"><a href="/Help:Contents">Help</a></li> </ul> </div> </div> <div class='portlet' id='p-SEARCH'> <h5>SEARCH</h5> <div class='pBody'> <ul> </ul> </div> </div> <div class='portlet' id='p-TOOLBOX'> <h5>TOOLBOX</h5> <div class='pBody'> <ul> </ul> </div> </div> <div class='portlet' id='p-LANGUAGES'> <h5>LANGUAGES</h5> <div class='pBody'> <ul> </ul> </div> </div> --> <!-- <script language="JavaScript" src="http://landmark-project.com/feed2js/feed2js.php?src=http%3A%2F%2Fn2.nabble.com%2Fnginx-ft2469901.xml&desc=1&date=y&targ=popup&html=p" type="text/javascript"> </script> <noscript> <a href="http://landmark-project.com/feed2js/feed2js.php?src=http%3A%2F%2Fn2.nabble.com%2Fnginx-ft2469901.xml&desc=1&date=y&targ=popup&html=y"> View RSS feed </a> </noscript> <script type="text/javascript"> function popupfeed ( url ) { var myfeatures = "toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,status=yes,resizable=no,width=800,height=400"; thefeed = window.open ( url, 'feed2jspop', myfeatures ); if (window.focus) { thefeed.focus ( ); } } </script> --> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-22238880-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://web.archive.org/web/20121216232625/https://ssl' : 'https://web.archive.org/web/20121216232625/http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> <div class="visualClear"></div> </div><!-- usertools --> <div id="footer"> <div id="donate"> <form action="https://web.archive.org/web/20121216232625/https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_donations"> <input type="hidden" name="business" value="paypal@nginx.net"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest"> <input type="image" src="/web/20121216232625im_/http://wiki.nginx.org/skins/bluwiki_skin/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="/web/20121216232625im_/http://wiki.nginx.org/_.gif" width="1" height="1"> </form> </div> <div id="footer-info"> This page was last modified on 4 August 2011, at 13:29. - <!-- --> <a href="/web/20121216232625/http://wiki.nginx.org/Nginx_Community:General_disclaimer" title="Nginx Community:General disclaimer">Disclaimers</a> - <a href="/web/20121216232625/http://wiki.nginx.org/Nginx_Community:About" title="Nginx Community:About">About Nginx Community</a> </div> <br style="clear: both;"/> <div id="propaganda"> <div id="f-copyrightico"> <a href="https://web.archive.org/web/20121216232625/http://creativecommons.org/licenses/by/3.0/"> <img src="/web/20121216232625im_/http://wiki.nginx.org/local/cc-88x31.png"/> </a> </div> <!--<a href="/"><img src="/local/propaganda/nginx-inside.png" alt="Powered by Nginx" /></a>--> <!--<a href="http://www.mediawiki.org"><img src="/local/propaganda/mediawiki.gif" alt="Powered by Mediawiki" /></a>--> <!--<a href="http://www.postgresql.org"><img src="/local/propaganda/postgresql.gif" alt="Powered by PostgreSQL" /></a>--> <span id="props"> Powered by nginx/1.3.2 | <a href="/web/20121216232625/http://wiki.nginx.org/CliffWells">Design by Cliff Wells</a> | <a href="https://web.archive.org/web/20121216232625/http://dryicons.com/">Icons by DryIcons</a> </span> </div> </div> </div> <!-- end #toolbox --> </div> <br style="clear: both;"/> </div> </body> <!-- Cached/compressed 20121026025241 --> </html> <!-- FILE ARCHIVED ON 23:26:25 Dec 16, 2012 AND RETRIEVED FROM THE INTERNET ARCHIVE ON 18:27:36 Feb 26, 2025. JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE. ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C. SECTION 108(a)(3)). --> <!-- playback timings (ms): captures_list: 1.005 exclusion.robots: 0.052 exclusion.robots.policy: 0.033 esindex: 0.02 cdx.remote: 26.1 LoadShardBlock: 340.822 (3) PetaboxLoader3.datanode: 322.392 (4) PetaboxLoader3.resolve: 144.283 (2) load_resource: 205.065 -->

Pages: 1 2 3 4 5 6 7 8 9 10