<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GeneralThreat.com &#187; nginx</title>
	<atom:link href="http://www.generalthreat.com/tag/nginx/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.generalthreat.com</link>
	<description>Dangerously different projects and code</description>
	<lastBuildDate>Sun, 19 Jan 2014 20:00:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>Creating a (relatively) secure dynamic PHP test environment with nginx</title>
		<link>http://www.generalthreat.com/2012/11/creating-a-secure-dynamic-env/</link>
		<comments>http://www.generalthreat.com/2012/11/creating-a-secure-dynamic-env/#comments</comments>
		<pubDate>Fri, 30 Nov 2012 02:51:54 +0000</pubDate>
		<dc:creator><![CDATA[David]]></dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.generalthreat.com/?p=95</guid>
		<description><![CDATA[I&#8217;ve been working on a deployment tool for WordPress development environments; one that can quickly provision and maintain the dizzying array of sites needed to test plugins against different versions of WordPress (with and&#46;&#46;&#46;]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been working on a deployment tool for WordPress development environments; one that can quickly provision and maintain the dizzying array of sites needed to test plugins against different versions of WordPress (with and w/o Multisite), BuddyPress, bbPress, etc.</p>
<p>Some cocktail napkin math suggested at least 20 combinations were needed to cover all the currently-supported configurations. Besides the chore of setting up environments for each, the need to add or remove environments as components are updated makes a manual deployment effort seem ridiculous.</p>
<p>While I&#8217;m finishing up work on that tool, I thought I&#8217;d start by posting the web server and PHP configs I&#8217;m using to make this happen.</p>
<h3>nginx Configuration</h3>
<p>I went with nginx because of its low memory usage and its handy regular-expression hostname matching, which I find more flexible and less kludgey for this application than mod_vhost_alias or mod_rewrite. This nginx config will provide the flexibility of dynamically-creating sites while still providing some isolation between them.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="nginx" style="font-family:monospace;">server {
        server_name ~^(.*)\.dev.your.domain$ ;
&nbsp;
        set $instance $1;
        set $session_root /var/www/dev/$instance/sessions;
&nbsp;
        root /var/www/dev/$instance/html;
        index index.php;
&nbsp;
        location ~ \.php$ {
&nbsp;
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
&nbsp;
                fastcgi_pass unix:/var/run/fpm-devsites.sock;
#               fastcgi_pass 127.0.0.1:9000
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param PHP_ADMIN_VALUE  &quot;open_basedir=$document_root\nsession.save_path=$session_root&quot;;
                include /etc/nginx/fastcgi_params;
&nbsp;
        }
&nbsp;
        location / {
                try_files $uri $uri/ /index.php;
        }
}</pre></td></tr></table></div>

<p>Thanks to mike at <a href="http://michaelshadle.com/2011/02/11/setting-php-ini-parameters-from-nginx">http://michaelshadle.com/2011/02/11/setting-php-ini-parameters-from-nginx</a> for the great guide to the PHP_ADMIN_VALUE param.</p>
<h3>PHP-FPM Configuration</h3>
<p>Ideally each site would have its own FPM pool, but that would mean root privileges were needed to provision new sites. So a single but separate pool for the dev environments was a necessary compromise. The goal of dynamically creating sites through an unprivileged web interface also meant that the <code>devsites</code> pool needed to run as the web user.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">; Start a new pool named 'www'.</span>
<span style="color: #666666; font-style: italic;">; the variable $pool can we used in any directive and will be replaced by the</span>
<span style="color: #666666; font-style: italic;">; pool name ('www' here)</span>
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>devsites<span style="">&#93;</span></span>
&nbsp;
<span style="color: #666666; font-style: italic;">; Unix user/group of processes</span>
<span style="color: #666666; font-style: italic;">; Note: The user is mandatory. If the group is not set, the default user's group</span>
<span style="color: #666666; font-style: italic;">;       will be used.</span>
<span style="color: #000099;">user</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> www-data</span>
<span style="color: #000099;">group</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> www-data</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; The address on which to accept FastCGI requests.</span>
<span style="color: #666666; font-style: italic;">; Valid syntaxes are:</span>
<span style="color: #666666; font-style: italic;">;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on</span>
<span style="color: #666666; font-style: italic;">;                            a specific port;</span>
<span style="color: #666666; font-style: italic;">;   'port'                 - to listen on a TCP socket to all addresses on a</span>
<span style="color: #666666; font-style: italic;">;                            specific port;</span>
<span style="color: #666666; font-style: italic;">;   '/path/to/unix/socket' - to listen on a unix socket.</span>
<span style="color: #666666; font-style: italic;">; Note: This value is mandatory.</span>
<span style="color: #000099;">listen</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /var/run/fpm-$pool.sock</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; Set permissions for unix socket, if one is used. In Linux, read/write</span>
<span style="color: #666666; font-style: italic;">; permissions must be set in order to allow connections from a web server. Many</span>
<span style="color: #666666; font-style: italic;">; BSD-derived systems allow connections regardless of permissions.</span>
<span style="color: #666666; font-style: italic;">; Default Values: user and group are set as the running user</span>
<span style="color: #666666; font-style: italic;">;                 mode is set to 0666</span>
listen.owner <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> www-data</span>
listen.group <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> www-data</span>
listen.mode <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 0666</span></pre></td></tr></table></div>

<p>If you&#8217;ve found this helpful (or troublesome), feel free to drop me a line in the comments below!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.generalthreat.com/2012/11/creating-a-secure-dynamic-env/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

 Served from: www.generalthreat.com @ 2026-06-09 04:02:34 by W3 Total Cache -->