--- 
author: 
  email: ash@firemirror.com
  keyid: bfc7465ebdca5337
  name: Ash Berlin
categories: []

date: 2007-09-29T21:58:51Z
guid: E6ABD362-6EB3-11DC-8EA1-D6A1BB7FECD7
modified: 2007-11-16T20:22:04Z
raw: "I spent most of last week preparing a new server to deploy a project onto a \nnice shiny new [1&1 Dedicated Server](http://www.1and1.co.uk/?k_id=10200518) \n(oh and if you buy something from that link I get a referral bonus - yay!) \nAll the boring stuff like bootstrapping a fresh Debian install onto the \ndisks from a rescue image; fighting the bootloader to make it work with no\nindication of errors when I make a mistake since I have no physical access to\nthe machine - you know: the ususal.\n\nSo once I'd finished those mundane tasks I had to setup the webserver. \nPreviously I'd have gone straight for Apache 2. However I'm deploying a\nCatalyst application to the machine, and although Catalyst will run under\nmod_perl, the recommended method is to use FastCGI since it turns out to be a\nlot less hassle in the long run.\n\n## Aims with FastCGI \n\nWhat I want from my FastCGI deployment:\n\n* to have two seperate FastCGI managers running, so that whenever I need to upgrade the code, I can shut one down, bring it back up with the new code, then do the same for the other - thus giving me the ability to upgrade the code with no downtime (assuming of course that there are no DB changes that might require downtime etc. etc.)\n* to have the static content served via the webserver, since this is what they do well\n* to not have fastcgi show up anywhere in the URL.\n\n## Apache...? \n\n\nDoing this with Apache+mod_fastcgi seems impossible though, since Apache's \nhandling of FastCGI isn't briliant. To do this in Apache you basically have to\ncreate two vhosts (and optionally give them ServerName's that dont resolve\nexternally) and then `Alias / /path/to/fastCGI/N.socket`. \n\nStill with me? 'cos we're not done yet. In the main vhost for the server (i.e. www.myapp.com) you\nthen have to create a [balanced proxy](http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#ProxyPass)\nlike the following:\n\n    ProxyPass / balancer://myapp-cluster\n    &lt;Proxy balancer://myapp-cluster>\n      BalanceMember http://myapp-1.internal\n      BalanceMember http://myapp-2.internal\n      Allow from all\n      Order Allow,Deny\n    &lt;/Proxy>\n\nComplex, no? And whats worse, is that it doesn't even cope with one of the \nbackend FastCGI servers being down - you just get a 500 page served to the \nuser. Bad Apache! Try the other (FastCGI) server please! \n\n## The Solution - Lighttpd\n\nAfter a bit of Googling, it seems like Apache just wont cope with this \nsituation. I've been hearing good things about Lighttpd, particularly that its\n[FastCGI](http://www.lighttpd.net/documentation/fastcgi.html) support is \nnative and much better.\n\nThe interesting bits of lighttpd config I've used:\n\n    lang:perl\n    server.moudles += (\n        \"mod_alias\",\n        \"mod_rewrite\",\n        \"mod_redirect\",\n        \"mod_setenv\",\n    )\n\nPretty self explanatory - load some of the modules we need. The rest of the\nconfig goes inside the `$HTTP[\"host\"] =~ \"www.mysite.com\"` directive.\n\n    lang:perl\n        # Let lighttpd take care of serving that static content\n        alias.url = (\n          \"/favicon.ico\" => \"/var/www/mysite.com/MySite/root/favicon.ico\",\n          \"/js/\"   => \"/var/www/mysite.com/MySite/root/js/\",\n          \"/css/\"  => \"/var/www/mysite.com/MySite/root/css/\",\n          \"/tour/\" => \"/var/www/mysite.com/MySite/root/tour/\",\n        )\n\n        # rewrite-once will stop processing after the first match\n        url.rewrite-once = (\n          \"^/((?:js|css|tour)/.*)\" => \"/$1\",\n          \"^/favicon.ico\" => \"/favicon.ico\",\n          \"^/(.*)\" => \"/fcgi/$1\"            \n        )\n    }\n\nThese two bits tell lighttpd to handle all the static content itself, and \nthen forward everything else off to the /fcgi path, which is defined as \nfollows:\n\n    lang:perl\n      fastcgi.server = (\n        \"/fcgi\" => (\n          ( \"host\" => \"127.0.0.1\", \"port\" => 3010, \"check-local\" => \"disable\"),\n          ( \"host\" => \"127.0.0.1\", \"port\" => 3011, \"check-local\" => \"disable\")\n        )\n      )\n    \nFairly obvious - everything under `/fcgi` is handled by the FastCGI servers.\nNote however that this will make Catalyst think it is based at \n`http://mysite.com/fcgi/` which it isn't, so we need to fix it:\n\n    lang:perl\n        $HTTP[\"url\"] =~ \"^/\" {\n          setenv.add-environment = ( \"SCRIPT_NAME\" => \"/\" )\n        }\n\nThat does the job - Catalyst now thinks its rooted at `/`, and lighttpd is now\nhandling all the static content itself.\n\nFor the completeness-sake, I've included the full config as a single block \nbelow.\n\n    lang:perl\n    $HTTP[\"host\"] =~ \"^mysite.com\" {\n        url.redirect = ( \"^/(.*)\" => \"http://www.mysite.com/$1\" )\n    }\n\n    $HTTP[\"host\"] =~ \"www.mysite.com\" {\n\n        # dir listings are bad\n        server.dir-listing = \"disable\"\n\n        server.errorlog    = \"/var/log/lighttpd/mysite.com.error.log\"\n        accesslog.filename = \"/var/log/lighttpd/mysite.com.access.log\"\n\n        # Let lighttpd take care of serving that static content\n        alias.url = (\n          \"/favicon.ico\" => \"/var/www/mysite.com/MySite/root/favicon.ico\",\n          \"/js/\"   => \"/var/www/mysite.com/MySite/root/js/\",\n          \"/css/\"  => \"/var/www/mysite.com/MySite/root/css/\",\n          \"/tour/\" => \"/var/www/mysite.com/MySite/root/tour/\",\n        )\n\n        # rewrite-once will stop processing after the first match\n        url.rewrite-once = (\n          \"^/((?:js|css|tour)/.*)\" => \"/$1\",\n          \"^/favicon.ico\" => \"/favicon.ico\",\n          \"^/(.*)\" => \"/fcgi/$1\"            \n        )\n\n        fastcgi.server = (\n          \"/fcgi\" => (\n            ( \"host\" => \"127.0.0.1\", \"port\" => 3010, \"check-local\" => \"disable\"),\n            ( \"host\" => \"127.0.0.1\", \"port\" => 3011, \"check-local\" => \"disable\")\n          )\n        )\n\n        $HTTP[\"url\"] =~ \"^/\" {\n          setenv.add-environment = ( \"SCRIPT_NAME\" => \"/\" )\n        }\n\n    }\n\n"
signed: 1
summary: " I spent most of last week preparing a new …"
tags: 
  - 
    lighttpd: 0
  - 
    catalyst: 0
  - 
    fastcgi: 0
text: "\nI spent most of last week preparing a new server to deploy a project on-\nto a nice shiny new 1&1 Dedicated Server [1] (oh and if you buy some-\nthing from that link I get a referral bonus - yay!) All the boring stuff\nlike bootstrapping a fresh Debian install onto the disks from a rescue\nimage; fighting the bootloader to make it work with no indication of er-\nrors when I make a mistake since I have no physical access to the ma-\nchine - you know: the ususal.\n\nSo once I'd finished those mundane tasks I had to setup the webserver.\nPreviously I'd have gone straight for Apache 2. However I'm deploying a\nCatalyst application to the machine, and although Catalyst will run un-\nder mod_perl, the recommended method is to use FastCGI since it turns\nout to be a lot less hassle in the long run.\n\nAIMS WITH FASTCGI\n\nWhat I want from my FastCGI deployment: to have two seperate FastCGI\nmanagers running, so that whenever I need to upgrade the code, I can\nshut one down, bring it back up with the new code, then do the same for\nthe other - thus giving me the ability to upgrade the code with no down-\ntime (assuming of course that there are no DB changes that might require\ndowntime etc. etc.)to have the static content served via the webserver,\nsince this is what they do wellto not have fastcgi show up anywhere in\nthe URL. APACHE...?\n\nDoing this with Apache+mod_fastcgi seems impossible though, since A-\npache's handling of FastCGI isn't briliant. To do this in Apache you\nbasically have to create two vhosts (and optionally give them\nServerName's that dont resolve externally) and then Alias / /path/to/-\nfastCGI/N.socket.\n\nStill with me? 'cos we're not done yet. In the main vhost for the server\n(i.e. www.myapp.com) you then have to create a balanced proxy [2] like\nthe following:\n\nComplex, no? And whats worse, is that it doesn't even cope with one of\nthe backend FastCGI servers being down - you just get a 500 page served\nto the user. Bad Apache! Try the other (FastCGI) server please!\n\nTHE SOLUTION - LIGHTTPD\n\nAfter a bit of Googling, it seems like Apache just wont cope with this\nsituation. I've been hearing good things about Lighttpd, particularly\nthat its FastCGI [3] support is native and much better.\n\nThe interesting bits of lighttpd config I've used:\n\nPretty self explanatory - load some of the modules we need. The rest of\nthe config goes inside the $HTTP[\"host\"] =~ \"www.mysite.com\" directive.\n\nThese two bits tell lighttpd to handle all the static content itself,\nand then forward everything else off to the /fcgi path, which is defined\nas follows:\n\nFairly obvious - everything under /fcgi is handled by the FastCGI\nservers. Note however that this will make Catalyst think it is based at\nhttp://mysite.com/fcgi/ which it isn't, so we need to fix it:\n\nThat does the job - Catalyst now thinks its rooted at /, and lighttpd is\nnow handling all the static content itself.\n\nFor the completeness-sake, I've included the full config as a single\nblock below.\n\n-- \n [1] http://www.1and1.co.uk/?k_id=10200518\n [2] http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#ProxyPass\n [3] http://www.lighttpd.net/documentation/fastcgi.html\n"
title: Catalyst with Lighttpd
type: markdown
uri: http://perlitist.com/articles/catalyst-with-lighttpd
xhtml: "<p>I spent most of last week preparing a new server to deploy a project onto a nice shiny new <a href=\"http://www.1and1.co.uk/?k_id=10200518\">1&amp;1 Dedicated Server</a> (oh and if you buy something from that link I get a referral bonus - yay!) All the boring stuff like bootstrapping a fresh Debian install onto the disks from a rescue image; fighting the bootloader to make it work with no indication of errors when I make a mistake since I have no physical access to the machine - you know: the ususal.</p><p>So once I&apos;d finished those mundane tasks I had to setup the webserver. Previously I&apos;d have gone straight for Apache 2. However I&apos;m deploying a Catalyst application to the machine, and although Catalyst will run under mod_perl, the recommended method is to use FastCGI since it turns out to be a lot less hassle in the long run.</p><h4>Aims with FastCGI</h4><p>What I want from my FastCGI deployment:</p><ul><li>to have two seperate FastCGI managers running, so that whenever I need to upgrade the code, I can shut one down, bring it back up with the new code, then do the same for the other - thus giving me the ability to upgrade the code with no downtime (assuming of course that there are no DB changes that might require downtime etc. etc.)</li><li>to have the static content served via the webserver, since this is what they do well</li><li>to not have fastcgi show up anywhere in the URL.</li></ul><h4>Apache...?</h4><p>Doing this with Apache+mod_fastcgi seems impossible though, since Apache&apos;s handling of FastCGI isn&apos;t briliant. To do this in Apache you basically have to create two vhosts (and optionally give them ServerName&apos;s that dont resolve externally) and then <code>Alias / /path/to/fastCGI/N.socket</code>. </p><p>Still with me? &apos;cos we&apos;re not done yet. In the main vhost for the server (i.e. www.myapp.com) you then have to create a balanced proxy like the following:</p><pre><code>ProxyPass / balancer://myapp-cluster\n&lt;Proxy balancer://myapp-cluster>\n  BalanceMember http://myapp-1.internal\n  BalanceMember http://myapp-2.internal\n  Allow from all\n  Order Allow,Deny\n&lt;/Proxy>\n</code></pre><p>Complex, no? And whats worse, is that it doesn&apos;t even cope with one of the backend FastCGI servers being down - you just get a 500 page served to the user. Bad Apache! Try the other (FastCGI) server please! </p><h4>The Solution - Lighttpd</h4><p>After a bit of Googling, it seems like Apache just wont cope with this situation. I&apos;ve been hearing good things about Lighttpd, particularly that its <a href=\"http://www.lighttpd.net/documentation/fastcgi.html\">FastCGI</a> support is native and much better.</p><p>The interesting bits of lighttpd config I&apos;ve used:</p><pre><code><span class=\"Normal\">server.moudles += (</span><span class=\"Normal\">\n</span><span class=\"Normal\">    </span><span class=\"Operator\">&quot;</span><span class=\"String\">mod_alias</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">    </span><span class=\"Operator\">&quot;</span><span class=\"String\">mod_rewrite</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">    </span><span class=\"Operator\">&quot;</span><span class=\"String\">mod_redirect</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">    </span><span class=\"Operator\">&quot;</span><span class=\"String\">mod_setenv</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">)</span><span class=\"Normal\">\n</span></code></pre><p>Pretty self explanatory - load some of the modules we need. The rest of the config goes inside the <code>$HTTP[&quot;host&quot;] =~ &quot;www.mysite.com&quot;</code> directive.</p><pre><code><span class=\"Normal\">    </span><span class=\"Comment\"># Let lighttpd take care of serving that static content</span><span class=\"Comment\">\n</span><span class=\"Normal\">    alias.url = (</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">/favicon.ico</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/var/www/mysite.com/MySite/root/favicon.ico</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">/js/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">   =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/var/www/mysite.com/MySite/root/js/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">/css/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">  =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/var/www/mysite.com/MySite/root/css/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">/tour/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/var/www/mysite.com/MySite/root/tour/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">    )</span><span class=\"Normal\">\n</span><span class=\"Normal\">\n</span><span class=\"Normal\">    </span><span class=\"Comment\"># rewrite-once will stop processing after the first match</span><span class=\"Comment\">\n</span><span class=\"Normal\">    url.rewrite</span><span class=\"Operator\">-o</span><span class=\"Normal\">nce = (</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">^/((?:js|css|tour)/.*)</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/</span><span class=\"Variable\">$1</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">^/favicon.ico</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/favicon.ico</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">^/(.*)</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/fcgi/</span><span class=\"Variable\">$1</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">            </span><span class=\"Normal\">\n</span><span class=\"Normal\">    )</span><span class=\"Normal\">\n</span><span class=\"Normal\">}</span><span class=\"Normal\">\n</span></code></pre><p>These two bits tell lighttpd to handle all the static content itself, and then forward everything else off to the /fcgi path, which is defined as follows:</p><pre><code><span class=\"Normal\">  fastcgi.server = (</span><span class=\"Normal\">\n</span><span class=\"Normal\">    </span><span class=\"Operator\">&quot;</span><span class=\"String\">/fcgi</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; (</span><span class=\"Normal\">\n</span><span class=\"Normal\">      ( </span><span class=\"Operator\">&quot;</span><span class=\"String\">host</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">127.0.0.1</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">, </span><span class=\"Operator\">&quot;</span><span class=\"String\">port</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Float\">3010</span><span class=\"Normal\">, </span><span class=\"Operator\">&quot;</span><span class=\"String\">check-local</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">disable</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">),</span><span class=\"Normal\">\n</span><span class=\"Normal\">      ( </span><span class=\"Operator\">&quot;</span><span class=\"String\">host</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">127.0.0.1</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">, </span><span class=\"Operator\">&quot;</span><span class=\"String\">port</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Float\">3011</span><span class=\"Normal\">, </span><span class=\"Operator\">&quot;</span><span class=\"String\">check-local</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">disable</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">)</span><span class=\"Normal\">\n</span><span class=\"Normal\">    )</span><span class=\"Normal\">\n</span><span class=\"Normal\">  )</span><span class=\"Normal\">\n</span></code></pre><p>Fairly obvious - everything under <code>/fcgi</code> is handled by the FastCGI servers. Note however that this will make Catalyst think it is based at <code>http://mysite.com/fcgi/</code> which it isn&apos;t, so we need to fix it:</p><pre><code><span class=\"Normal\">    </span><span class=\"DataType\">$HTTP</span><span class=\"Normal\">[</span><span class=\"Operator\">&quot;</span><span class=\"String\">url</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">] =~ </span><span class=\"Operator\">&quot;</span><span class=\"String\">^/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> {</span><span class=\"Normal\">\n</span><span class=\"Normal\">      setenv.add</span><span class=\"Operator\">-e</span><span class=\"Normal\">nvironment = ( </span><span class=\"Operator\">&quot;</span><span class=\"String\">SCRIPT_NAME</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> )</span><span class=\"Normal\">\n</span><span class=\"Normal\">    }</span><span class=\"Normal\">\n</span></code></pre><p>That does the job - Catalyst now thinks its rooted at <code>/</code>, and lighttpd is now handling all the static content itself.</p><p>For the completeness-sake, I&apos;ve included the full config as a single block below.</p><pre><code><span class=\"DataType\">$HTTP</span><span class=\"Normal\">[</span><span class=\"Operator\">&quot;</span><span class=\"String\">host</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">] =~ </span><span class=\"Operator\">&quot;</span><span class=\"String\">^mysite.com</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> {</span><span class=\"Normal\">\n</span><span class=\"Normal\">    url.redirect = ( </span><span class=\"Operator\">&quot;</span><span class=\"String\">^/(.*)</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">http://www.mysite.com/</span><span class=\"Variable\">$1</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> )</span><span class=\"Normal\">\n</span><span class=\"Normal\">}</span><span class=\"Normal\">\n</span><span class=\"Normal\">\n</span><span class=\"DataType\">$HTTP</span><span class=\"Normal\">[</span><span class=\"Operator\">&quot;</span><span class=\"String\">host</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">] =~ </span><span class=\"Operator\">&quot;</span><span class=\"String\">www.mysite.com</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> {</span><span class=\"Normal\">\n</span><span class=\"Normal\">\n</span><span class=\"Normal\">    </span><span class=\"Comment\"># dir listings are bad</span><span class=\"Comment\">\n</span><span class=\"Normal\">    server.dir</span><span class=\"Operator\">-l</span><span class=\"Normal\">isting = </span><span class=\"Operator\">&quot;</span><span class=\"String\">disable</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">\n</span><span class=\"Normal\">\n</span><span class=\"Normal\">    server.errorlog    = </span><span class=\"Operator\">&quot;</span><span class=\"String\">/var/log/lighttpd/mysite.com.error.log</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">\n</span><span class=\"Normal\">    accesslog.filename = </span><span class=\"Operator\">&quot;</span><span class=\"String\">/var/log/lighttpd/mysite.com.access.log</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">\n</span><span class=\"Normal\">\n</span><span class=\"Normal\">    </span><span class=\"Comment\"># Let lighttpd take care of serving that static content</span><span class=\"Comment\">\n</span><span class=\"Normal\">    alias.url = (</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">/favicon.ico</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/var/www/mysite.com/MySite/root/favicon.ico</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">/js/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">   =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/var/www/mysite.com/MySite/root/js/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">/css/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">  =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/var/www/mysite.com/MySite/root/css/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">/tour/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/var/www/mysite.com/MySite/root/tour/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">    )</span><span class=\"Normal\">\n</span><span class=\"Normal\">\n</span><span class=\"Normal\">    </span><span class=\"Comment\"># rewrite-once will stop processing after the first match</span><span class=\"Comment\">\n</span><span class=\"Normal\">    url.rewrite</span><span class=\"Operator\">-o</span><span class=\"Normal\">nce = (</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">^/((?:js|css|tour)/.*)</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/</span><span class=\"Variable\">$1</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">^/favicon.ico</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/favicon.ico</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">,</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">^/(.*)</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/fcgi/</span><span class=\"Variable\">$1</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">            </span><span class=\"Normal\">\n</span><span class=\"Normal\">    )</span><span class=\"Normal\">\n</span><span class=\"Normal\">\n</span><span class=\"Normal\">    fastcgi.server = (</span><span class=\"Normal\">\n</span><span class=\"Normal\">      </span><span class=\"Operator\">&quot;</span><span class=\"String\">/fcgi</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; (</span><span class=\"Normal\">\n</span><span class=\"Normal\">        ( </span><span class=\"Operator\">&quot;</span><span class=\"String\">host</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">127.0.0.1</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">, </span><span class=\"Operator\">&quot;</span><span class=\"String\">port</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Float\">3010</span><span class=\"Normal\">, </span><span class=\"Operator\">&quot;</span><span class=\"String\">check-local</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">disable</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">),</span><span class=\"Normal\">\n</span><span class=\"Normal\">        ( </span><span class=\"Operator\">&quot;</span><span class=\"String\">host</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">127.0.0.1</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">, </span><span class=\"Operator\">&quot;</span><span class=\"String\">port</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Float\">3011</span><span class=\"Normal\">, </span><span class=\"Operator\">&quot;</span><span class=\"String\">check-local</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">disable</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">)</span><span class=\"Normal\">\n</span><span class=\"Normal\">      )</span><span class=\"Normal\">\n</span><span class=\"Normal\">    )</span><span class=\"Normal\">\n</span><span class=\"Normal\">\n</span><span class=\"Normal\">    </span><span class=\"DataType\">$HTTP</span><span class=\"Normal\">[</span><span class=\"Operator\">&quot;</span><span class=\"String\">url</span><span class=\"Operator\">&quot;</span><span class=\"Normal\">] =~ </span><span class=\"Operator\">&quot;</span><span class=\"String\">^/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> {</span><span class=\"Normal\">\n</span><span class=\"Normal\">      setenv.add</span><span class=\"Operator\">-e</span><span class=\"Normal\">nvironment = ( </span><span class=\"Operator\">&quot;</span><span class=\"String\">SCRIPT_NAME</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> =&gt; </span><span class=\"Operator\">&quot;</span><span class=\"String\">/</span><span class=\"Operator\">&quot;</span><span class=\"Normal\"> )</span><span class=\"Normal\">\n</span><span class=\"Normal\">    }</span><span class=\"Normal\">\n</span><span class=\"Normal\">\n</span><span class=\"Normal\">}</span><span class=\"Normal\">\n</span></code></pre>"
