<?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>Arnisoft &#187; Howto</title>
	<atom:link href="http://arnisoft.com/category/networking/howto/feed/" rel="self" type="application/rss+xml" />
	<link>http://arnisoft.com</link>
	<description>Software Development  &#38; Networkadministration</description>
	<lastBuildDate>Wed, 13 Apr 2011 16:23:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>NGinx: Custom error handling</title>
		<link>http://arnisoft.com/285/nginx-custom-error-handling/</link>
		<comments>http://arnisoft.com/285/nginx-custom-error-handling/#comments</comments>
		<pubDate>Tue, 18 May 2010 16:23:52 +0000</pubDate>
		<dc:creator>devarni</dc:creator>
				<category><![CDATA[Howto]]></category>

		<guid isPermaLink="false">http://arnisoft.com/?p=285</guid>
		<description><![CDATA[I will give you a idea about the easy implementation of error page handling with Nginx. 1. Setting error handler Error handler can be set with the error_page directive. More about this directive you can find here. Do this in your server block but better use a generic file and include this in every virtual [...]]]></description>
			<content:encoded><![CDATA[<p>I will give you a idea about the easy implementation of error page handling with Nginx.</p>
<p><b>1. Setting error handler</b></p>
<p>Error handler can be set with the <code>error_page</code> directive. More about this directive you can find <a href="http://wiki.nginx.org/NginxHttpCoreModule#error_page" mce_href="http://wiki.nginx.org/NginxHttpCoreModule#error_page" target="_blank">here</a>.</p>
<p>Do this in your server block but better use a generic file and include this in every virtual host server block.&nbsp;I use for this a file &#8220;vhost&#8221; with all such settings.</p>
<p>The handler or html files are placed in a separate folder outside the webs. You can use a folder inside your Nginx settings (I use here for example a &#8220;html&#8221; folder).</p>
<p>The location block is needed to pass the correct root and file to php fastcgi. In this example I use a file &#8220;fastcgi&#8221; &nbsp;with this mostly used lines:</p>
<pre name="code" class="php">
fastcgi_pass   unix:/tmp/fastcgi.socket;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
include fastcgi_params;
</pre>
<p>Here the part in the server block (or in your generic vhost file for including):</p>
<pre name="code" class="php">

# error handler, codes can also be combined
error_page 401 /error.php?c=401;
error_page 403 /error.php?c=403;
error_page 404 /error.php?c=404;
error_page 500 /error.php?c=500;
error_page 502 503 504 /error.php?c=50x;

# serve error.php from /etc/nginx/html folder
location =/error.php {
   root /etc/nginx/html;
   include conf/fastcgi;
}
</pre>
<p><b>2. PHP file</b></p>
<p>The error.php file will be called with the URL encoded error-code, so its easy to grab this code in the PHP file from the superglobal <code>$_GET</code> array.</p>
<p>To map this error code to a message string, use a associative array and a function to return the string.</p>
<p>This is the part in the error.php file:</p>
<pre name="code" class="php">

<?php

//mapping array for error code to message string
$_err = Array("401" => "Autorisierung erforderlich! - Authorization Required",
    "403" => "Zugriff ist nicht erlaubt! - Access forbidden",
    "404" => "Seite wurde nicht gefunden - Page not found",
    "500" => "Interner Serverfehler - Internal Server Error",
    "50x" => "Seite ist momentan nicht verf&uuml;gbar. Bitte Anfrage sp&auml;ter wiederholen.<br/>-<br/>The page is temporarily unavailable. Try again later.");

// get the error string
function errorString($error) {
    global $_err;

    foreach ($_err as $key => $val) {
        if ($key == $error)
            return $val;
    }

    return "Unknown Error";
}

isset($_GET['c']) or die("Unknown Error");
$error = $_GET['c'];
$str = errorString($error);

?>

Error &lt;?=$error?&gt;: <strong>&lt;?=$str?&gt;</strong>
</pre>
<p>You can format the error page as you like. But remember: the web root url will be the  actual virtual host! Easiest way: use inline CSS. If this is not your preferred way, place the css file in a virtual host (eg. your default virtual host)</p>
]]></content:encoded>
			<wfw:commentRss>http://arnisoft.com/285/nginx-custom-error-handling/feed/lang/en/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx: phpmyadmin configuration</title>
		<link>http://arnisoft.com/253/nginx-phpmyadmin-configuration/</link>
		<comments>http://arnisoft.com/253/nginx-phpmyadmin-configuration/#comments</comments>
		<pubDate>Thu, 13 May 2010 15:11:53 +0000</pubDate>
		<dc:creator>devarni</dc:creator>
				<category><![CDATA[Howto]]></category>

		<guid isPermaLink="false">http://arnisoft.com/?p=253</guid>
		<description><![CDATA[This configuration is used to access phpmyadmin as a &#8220;subfolder&#8221; of the domain like: http://mysite.com/phpmyadmin The location will be append to the root! For a similar behaviour like the Apache configuration, you could use the &#8220;alias&#8221; directive My phpmyadmin installation is under /usr/share/phpmyadmin, thats why I use /usr/share as the root. server{ ... location /phpmyadmin{ [...]]]></description>
			<content:encoded><![CDATA[<p>This configuration is used to access phpmyadmin as a &#8220;subfolder&#8221; of the domain like:</p>
<p>http://mysite.com/phpmyadmin</p>
<p>
The location will be append to the root! For a similar behaviour like the Apache configuration, you could use the &#8220;alias&#8221; directive<br/><br />
My phpmyadmin installation is under /usr/share/phpmyadmin, thats why I use /usr/share as the root.
</p>
<pre name="code" class="js">
server{
...
    location /phpmyadmin{
        root    /usr/share;
        index   index.php;
    }

    location ~ \.php$ {
        set $php_root   $document_root;
            if ($request_uri ~* /phpmyadmin) {
                set $php_root /usr/share;
           }

        fastcgi_pass   unix:/tmp/fastcgi.socket;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://arnisoft.com/253/nginx-phpmyadmin-configuration/feed/lang/en/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

