<?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>dan.thoughts &#187; Nginx</title>
	<atom:link href="http://blog.sosedoff.com/category/nginx/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sosedoff.com</link>
	<description>Web-development, PHP, Ruby, Sinatra, Merb, Rails, MySQL, SQLite, Web Services.</description>
	<lastBuildDate>Wed, 25 Jan 2012 18:54:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Maintenance page for Rails applications with nginx</title>
		<link>http://blog.sosedoff.com/2010/09/22/maintenance-page-for-rails-applications-with-nginx/</link>
		<comments>http://blog.sosedoff.com/2010/09/22/maintenance-page-for-rails-applications-with-nginx/#comments</comments>
		<pubDate>Wed, 22 Sep 2010 16:34:14 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[web servers]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=281</guid>
		<description><![CDATA[Here is a small tooltip how to setup maintenance page for Rails applications under nginx.  I usually put offline.txt into public directory while making any changes or testing.
Solution works with any type of backend server (passenger/php-fpm/upstream)
Sample vhost config:

server {
  listen 80;
  server_name HOSTNAME;

  location / {
    root /path/to/your/public/dir;
 [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a small tooltip how to setup maintenance page for Rails applications under nginx.  I usually put offline.txt into public directory while making any changes or testing.<br />
Solution works with any type of backend server (passenger/php-fpm/upstream)</p>
<p>Sample vhost config:</p>
<pre>
server {
  listen 80;
  server_name HOSTNAME;

  location / {
    root /path/to/your/public/dir;
    passenger_enabled on;
    rails_env production;

    if (-f $document_root/offline.txt) {
      return 503;
    }
  }

  location /maintenance.html {
    root /path/to/your/public/dir;
  }

  error_page 503 /maintenance.html;
}
</pre>
<p>Pastie: <a href="http://pastie.org/private/pgnhvnkj4uxe4mkgnhvqw">http://pastie.org/private/pgnhvnkj4uxe4mkgnhvqw</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2010/09/22/maintenance-page-for-rails-applications-with-nginx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to deploy Sinatra / Merb applications with nginx</title>
		<link>http://blog.sosedoff.com/2009/07/04/how-to-deploy-sinatra-merb-applications-with-nginx/</link>
		<comments>http://blog.sosedoff.com/2009/07/04/how-to-deploy-sinatra-merb-applications-with-nginx/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 15:59:47 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[sinatra]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=158</guid>
		<description><![CDATA[Developing with Merb or Sinatra ? Like web server nginx ? Ok, lets go.
Basically, Merb/Sinatra uses thin (based on eventmachine) server module, so it is working as stand-alone application. So, there is a way to connect nginx with these applications. Very simple &#8211; all you need to proxy requests to backend server. And all static [...]]]></description>
			<content:encoded><![CDATA[<p>Developing with <a href="http://merbivore.com/">Merb</a> or <a href="http://sinatrarb.com/">Sinatra</a> ? Like web server <a href="http://sysoev.ru/nginx">nginx</a> ? Ok, lets go.</p>
<p>Basically, Merb/Sinatra uses <a href="http://code.macournoyer.com/thin/">thin</a> (based on <a href="http://rubyeventmachine.com/">eventmachine</a>) server module, so it is working as stand-alone application. So, there is a way to connect nginx with these applications. Very simple &#8211; all you need to proxy requests to backend server. And all static files will be served by nginx.</p>
<pre>
upstream your_app {
  server 127.0.0.1:YOUR_PORT_NUMBER;
}

server {
  server_name YOUR_SERVERNAME;
  listen 80;
  charset utf-8;
  client_max_body_size 64M; # maximum of proxied filesize (for uploads)

  location / {
    root /path/to/app/root;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect false;
    if (-f $request_filename) {
      break;
    }

    if (!-f $request_filename) {
      proxy_pass http://your_app;
      break;
    }
  }

  # static content (images, flash, styles, etc.)
  location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|js|swf)$ {
    root /path/to/your/public/dir;
    access_log off;
  }
}
</pre>
<p>Then, all you need &#8211; start your application in daemon mode. Dont forget to bind application server to listen only on local address (127.0.0.1). </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/07/04/how-to-deploy-sinatra-merb-applications-with-nginx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up nginx with SSL support</title>
		<link>http://blog.sosedoff.com/2009/04/16/setting-up-nginx-with-ssl-support/</link>
		<comments>http://blog.sosedoff.com/2009/04/16/setting-up-nginx-with-ssl-support/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 22:58:23 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[certificates]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[self-signed]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=127</guid>
		<description><![CDATA[Here is a simple manual how to setup nginx to use self-signed SSL certificates with nginx web server.
Build nginx
First, we need to get nginx sources and additional modules (pcre, zlib, openssl).

cd /source
$ wget http://sysoev.ru/nginx/nginx-0.6.36.tar.gz
$ wget http://www.zlib.net/zlib-1.2.3.tar.gz
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz
$ wget http://www.openssl.org/source/openssl-0.9.8k.tar.gz

After, unpack all archives

$ tar -zxf nginx-0.6.36.tar.gz
$ tar -zxf zlib-1.2.3.tar.gz
$ tar -zxf pcre-7.8.tar.gz
$ tar -zxf openssl-0.9.8k.tar.gz

Configure, [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple manual how to setup nginx to use self-signed SSL certificates with nginx web server.</p>
<h3>Build nginx</h3>
<p>First, we need to get nginx sources and additional modules (pcre, zlib, openssl).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">source</span>
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>sysoev.ru<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>nginx-0.6.36.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.zlib.net<span style="color: #000000; font-weight: bold;">/</span>zlib-1.2.3.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>:<span style="color: #000000; font-weight: bold;">//</span>ftp.csx.cam.ac.uk<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>software<span style="color: #000000; font-weight: bold;">/</span>programming<span style="color: #000000; font-weight: bold;">/</span>pcre<span style="color: #000000; font-weight: bold;">/</span>pcre-7.8.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.openssl.org<span style="color: #000000; font-weight: bold;">/</span>source<span style="color: #000000; font-weight: bold;">/</span>openssl-0.9.8k.tar.gz</pre></div></div>

<p>After, unpack all archives</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxf</span> nginx-0.6.36.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxf</span> zlib-1.2.3.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxf</span> pcre-7.8.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxf</span> openssl-0.9.8k.tar.gz</pre></div></div>

<p>Configure, make and install nginx with SSL, PCRE Regular expressions, Zlib support:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> nginx-0.6.36
$ .<span style="color: #000000; font-weight: bold;">/</span>configure --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module <span style="color: #660033;">--with-zlib</span>=..<span style="color: #000000; font-weight: bold;">/</span>zlib-1.2.3 <span style="color: #660033;">--with-pcre</span>=..<span style="color: #000000; font-weight: bold;">/</span>pcre-<span style="color: #000000;">7.8</span> <span style="color: #660033;">--with-openssl</span>=..<span style="color: #000000; font-weight: bold;">/</span>openssl-0.9.8k
$ <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<h3>Create SSL certificate</h3>
<p>The following is an extremely simplified view of how SSL is implemented and what part the certificate plays in the entire process.</p>
<h4>Generate a Private Key</h4>
<p>The openssl toolkit is used to generate an RSA Private Key and CSR (Certificate Signing Request). It can also be used to generate self-signed certificates which can be used for testing purposes or internal usage.</p>
<p>The first step is to create your RSA Private Key. This key is a 1024 bit RSA key which is encrypted using Triple-DES and stored in a PEM format so that it is readable as ASCII text.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ openssl genrsa <span style="color: #660033;">-des3</span> <span style="color: #660033;">-out</span> server.key <span style="color: #000000;">1024</span>
&nbsp;
Generating RSA private key, <span style="color: #000000;">1024</span> bit long modulus
.........................................................++++++
........++++++
e is <span style="color: #000000;">65537</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>0x10001<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Enter PEM pass phrase:
Verifying password - Enter PEM pass phrase:</pre></div></div>

<h4>Generate a CSR (Certificate Signing Request)</h4>
<p>Once the private key is generated a Certificate Signing Request can be generated. The CSR is then used in one of two ways. Ideally, the CSR will be sent to a Certificate Authority, such as Thawte or Verisign who will verify the identity of the requestor and issue a signed certificate. The second option is to self-sign the CSR, which will be demonstrated in the next section.</p>
<p>During the generation of the CSR, you will be prompted for several pieces of information. These are the X.509 attributes of the certificate. One of the prompts will be for &#8220;Common Name (e.g., YOUR name)&#8221;. It is important that this field be filled in with the fully qualified domain name of the server to be protected by SSL. If the website to be protected will be https://domain.com, then enter domain.com at this prompt. The command to generate the CSR is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ openssl req <span style="color: #660033;">-new</span> <span style="color: #660033;">-key</span> server.key <span style="color: #660033;">-out</span> server.csr
&nbsp;
    Country Name <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2</span> letter code<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>GB<span style="color: #7a0874; font-weight: bold;">&#93;</span>:US
    State or Province Name <span style="color: #7a0874; font-weight: bold;">&#40;</span>full name<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>Berkshire<span style="color: #7a0874; font-weight: bold;">&#93;</span>:Illinois
    Locality Name <span style="color: #7a0874; font-weight: bold;">&#40;</span>eg, city<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>Newbury<span style="color: #7a0874; font-weight: bold;">&#93;</span>:Chicago
    Organization Name <span style="color: #7a0874; font-weight: bold;">&#40;</span>eg, company<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>My Company Ltd<span style="color: #7a0874; font-weight: bold;">&#93;</span>:Sosedoff
    Organizational Unit Name <span style="color: #7a0874; font-weight: bold;">&#40;</span>eg, section<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>:Information Technology
    Common Name <span style="color: #7a0874; font-weight: bold;">&#40;</span>eg, your name or your server<span style="color: #ff0000;">'s hostname) []:domain.com
    Email Address []:YOUR.MAIL@HERE.com
    Please enter the following '</span>extra<span style="color: #ff0000;">' attributes
    to be sent with your certificate request
    A challenge password []:
    An optional company name []:</span></pre></div></div>

<h4>Remove Passphrase from Key </h4>
<p>One unfortunate side-effect of the pass-phrased private key is that nginx will ask for the pass-phrase each time the web server is started. Obviously this is not necessarily convenient as someone will not always be around to type in the pass-phrase, such as after a reboot or crash. It is possible to remove the Triple-DES encryption from the key, thereby no longer needing to type in a pass-phrase. If the private key is no longer encrypted, it is critical that this file only be readable by the root user! If your system is ever compromised and a third party obtains your unencrypted private key, the corresponding certificate will need to be revoked. With that being said, use the following command to remove the pass-phrase from the key:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cp</span> server.key server.key.org
$ openssl rsa <span style="color: #660033;">-in</span> server.key.org <span style="color: #660033;">-out</span> server.key
&nbsp;
    The newly created server.key <span style="color: #c20cb9; font-weight: bold;">file</span> has no <span style="color: #c20cb9; font-weight: bold;">more</span> passphrase <span style="color: #000000; font-weight: bold;">in</span> it.</pre></div></div>

<h4>Generating a Self-Signed Certificate</h4>
<p>At this point you will need to generate a self-signed certificate because you either don&#8217;t plan on having your certificate signed by a CA, or you wish to test your new SSL implementation while the CA is signing your certificate. This temporary certificate will generate an error in the client browser to the effect that the signing certificate authority is unknown and not trusted.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ openssl x509 <span style="color: #660033;">-req</span> <span style="color: #660033;">-days</span> <span style="color: #000000;">365</span> <span style="color: #660033;">-in</span> server.csr <span style="color: #660033;">-signkey</span> server.key <span style="color: #660033;">-out</span> server.crt
    Signature ok</pre></div></div>

<h3>Configure nginx to use SSL</h3>
<p>Ok, now we have all necessary files to setup web server. Copy files server.key and server.crt to some folder where your configuration files located (by default, &#8216;/usr/local/nginx/conf&#8217;). And edit nginx.conf (or any other file that represents your site):</p>
<pre>
server {
    server_name YOURNAME_HERE;
    listen 443;

    ssl on;
    ssl_certificate path/to/certificate.crt;
    ssl_certificate_key path/to/certificate.key;
}
</pre>
<p>And update server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># /etc/init.d/nginx reload</span></pre></div></div>

<h3>Test the site</h3>
<pre>https://yourdomain.com/</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/04/16/setting-up-nginx-with-ssl-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Init.d nginx script for Debian and RHEL systems</title>
		<link>http://blog.sosedoff.com/2009/03/15/initd-nginx-script-for-debian-and-rhel-systems/</link>
		<comments>http://blog.sosedoff.com/2009/03/15/initd-nginx-script-for-debian-and-rhel-systems/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 14:14:19 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[init script]]></category>
		<category><![CDATA[init.d]]></category>
		<category><![CDATA[rhel]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=108</guid>
		<description><![CDATA[Here is general init.d nginx script that working on Debian and RHEL/CentOS systems. It`s set to default configuration with main path to nginx = /usr/local/nginx

#!/bin/sh
#
# Init file for nginx
#
# chkconfig: 2345 55 25
# description: Nginx web server
#
# processname: nginx
# config: /usr/local/nginx/nginx.conf
# pidfile: /usr/local/nginx/nginx.pid
&#160;
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# [...]]]></description>
			<content:encoded><![CDATA[<p>Here is general init.d nginx script that working on Debian and RHEL/CentOS systems. It`s set to default configuration with main path to nginx = /usr/local/nginx</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Init file for nginx</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># chkconfig: 2345 55 25</span>
<span style="color: #666666; font-style: italic;"># description: Nginx web server</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># processname: nginx</span>
<span style="color: #666666; font-style: italic;"># config: /usr/local/nginx/nginx.conf</span>
<span style="color: #666666; font-style: italic;"># pidfile: /usr/local/nginx/nginx.pid</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and</span>
<span style="color: #666666; font-style: italic;"># run 'sudo update-rc.d nginx defaults', or use the appropriate command on your</span>
<span style="color: #666666; font-style: italic;"># distro. For CentOS/Redhat run: '/sbin/chkconfig --add nginx'</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Author: Ryan Norbauer &lt;ryan.norbauer@gmail.com&gt;</span>
<span style="color: #666666; font-style: italic;"># Modified: Geoffrey Grosenbach http://topfunky.com</span>
<span style="color: #666666; font-style: italic;"># Modified: David Krmpotic http://davidhq.com</span>
<span style="color: #666666; font-style: italic;"># Modified: Vishnu Gopal http://vish.in</span>
<span style="color: #666666; font-style: italic;"># Modified: Dan Sosedov &lt;dan.sosedoff@gmail.com&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-e</span>
&nbsp;
<span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin
<span style="color: #007800;">DESC</span>=<span style="color: #ff0000;">&quot;nginx daemon&quot;</span>
<span style="color: #007800;">NAME</span>=nginx
<span style="color: #007800;">DAEMON</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>
<span style="color: #007800;">CONFIGFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>nginx.conf
<span style="color: #007800;">PIDFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid
<span style="color: #007800;">SCRIPTNAME</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Gracefully exit if the package has been removed.</span>
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-x</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
&nbsp;
d_start<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #007800;">$DAEMON</span> <span style="color: #660033;">-c</span> <span style="color: #007800;">$CONFIGFILE</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-en</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> already running&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
d_stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-QUIT</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$PIDFILE</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-en</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> not running&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
d_reload<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-HUP</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$PIDFILE</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-en</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> can't reload&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
  start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting <span style="color: #007800;">$DESC</span>: <span style="color: #007800;">$NAME</span>&quot;</span>
    d_start
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.&quot;</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
  stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Stopping <span style="color: #007800;">$DESC</span>: <span style="color: #007800;">$NAME</span>&quot;</span>
    d_stop
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.&quot;</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
  reload<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Reloading <span style="color: #007800;">$DESC</span> configuration...&quot;</span>
    d_reload
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.&quot;</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
  restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Restarting <span style="color: #007800;">$DESC</span>: <span style="color: #007800;">$NAME</span>&quot;</span>
    d_stop
    <span style="color: #666666; font-style: italic;"># One second might not be time enough for a daemon to stop,</span>
    <span style="color: #666666; font-style: italic;"># if this happens, d_start will fail (and dpkg will break if</span>
    <span style="color: #666666; font-style: italic;"># the package is being upgraded). Change the timeout if needed</span>
    <span style="color: #666666; font-style: italic;"># be, or change d_stop to have start-stop-daemon use --retry.</span>
    <span style="color: #666666; font-style: italic;"># Notice that using --retry slows down the shutdown process somewhat.</span>
    <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
    d_start
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.&quot;</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: <span style="color: #007800;">$SCRIPTNAME</span> {start|stop|restart|reload}&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">3</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx <span style="color: #7a0874; font-weight: bold;">&#40;</span>start<span style="color: #000000; font-weight: bold;">|</span>stop<span style="color: #000000; font-weight: bold;">|</span>restart<span style="color: #000000; font-weight: bold;">|</span>reload<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>You also can download it &#8211; <a href="http://files.sosedoff.com/e570e29f/">http://files.sosedoff.com/e570e29f/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/03/15/initd-nginx-script-for-debian-and-rhel-systems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making URL controller easy</title>
		<link>http://blog.sosedoff.com/2009/01/15/making-url-controller-easy/</link>
		<comments>http://blog.sosedoff.com/2009/01/15/making-url-controller-easy/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 10:27:08 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[rewrite rules]]></category>
		<category><![CDATA[url controller]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=10</guid>
		<description><![CDATA[For example, instead of using &#8220;dirty&#8221; url`s in your web application (like test.php?param=1&#38;val=342&#38;fuck=bla) you can use very nice links (/this/is/nice/link/). And also, redirect all the requests to single file.
nginx configuration:

location / {
    root /var/site/public_html;
    index index.php index.html index.htm;
    if (!-e $request_filename) {
     [...]]]></description>
			<content:encoded><![CDATA[<p>For example, instead of using &#8220;dirty&#8221; url`s in your web application (like test.php?param=1&amp;val=342&amp;fuck=bla) you can use very nice links (/this/is/nice/link/). And also, redirect all the requests to single file.</p>
<p><strong>nginx configuration:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">location / {
    root /var/site/public_html;
    index index.php index.html index.htm;
    if (!-e $request_filename) {
        rewrite ^/(.*)/$ /index.php?path=$request_uri last;
    }
}</pre></div></div>

<p><strong>The same for Apache 2:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">RewriteBase</span> /
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} !-d
<span style="color: #00007f;">RewriteRule</span> ^(.*)/$ index.php?path=%{REQUEST_URI} [NCL]</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/01/15/making-url-controller-easy/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rewrite subdomains with nginx 0.6.x</title>
		<link>http://blog.sosedoff.com/2009/01/15/rewrite-subdomains-with-nginx-06x/</link>
		<comments>http://blog.sosedoff.com/2009/01/15/rewrite-subdomains-with-nginx-06x/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 10:25:56 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[domains]]></category>
		<category><![CDATA[rewrite rules]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=8</guid>
		<description><![CDATA[Problem: You have a domain name &#8216;www.domain.com&#8217; that needs to be redirected to &#8216;domain.com&#8217;.
Solution:

In your nginx config file (i`m keeping all configs for all sites separate in different files), befor &#8217;server&#8217; block configuration you should put this piese of code:

server {
    server_name www.domain.com;
    rewrite ^(.*) http://domain.com$1 permanent;
}
server {
... actual [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong> You have a domain name &#8216;www.domain.com&#8217; that needs to be redirected to &#8216;domain.com&#8217;.</p>
<p><strong>Solution:<br />
</strong><br />
In your nginx config file (i`m keeping all configs for all sites separate in different files), befor &#8217;server&#8217; block configuration you should put this piese of code:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">server {
    server_name www.domain.com;
    rewrite ^(.*) http://domain.com$1 permanent;
}
server {
... actual server configuration ...
}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/01/15/rewrite-subdomains-with-nginx-06x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring WebDAV Server</title>
		<link>http://blog.sosedoff.com/2009/01/15/configuring-webdav-server/</link>
		<comments>http://blog.sosedoff.com/2009/01/15/configuring-webdav-server/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 10:24:32 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[webdav]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=6</guid>
		<description><![CDATA[Some time ago i had reason to make couple servers being accessible by WebDAV protocol.
But all our special storage servers were running nginx 0.6.x, that also supports this protocol.
By the way, it doesn`t support meta commands such as PROPFIND, OPTIONS, so if you try to connect to server with some command-line or GUI client it [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago i had reason to make couple servers being accessible by WebDAV protocol.<br />
But all our special storage servers were running nginx 0.6.x, that also supports this protocol.<br />
By the way, it doesn`t support meta commands such as PROPFIND, OPTIONS, so if you try to connect to server with some command-line or GUI client it will close connection due to accepting &#8220;unknown&#8221; commands, but will work only with PUT, DELETE, COPY, MOVE, MKCOL requests.<br />
It was a huge problem, because for a long time i couldn`t figure out what the reason of reject. Server allways respond with &#8216;405 Not allowed&#8217;. But when i tried put file &#8211; it worked.<br />
Also, alternate fast server <a href="http://lighttpd.net" target="_blank">Lighttpd</a> supports all meta commands.</p>
<p><strong>Simple nginx configuration:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">server {
    listen 80;
    server_name localhost;
    access_log log/access.log;
    error_log log/error.log;
    charset utf-8;
    client_body_temp_path client_body_temp;
    autoindex on;
&nbsp;
     location / {
          root /home/dav/public;
          dav_methods PUT DELETE MKCOL COPY MOVE;
          dav_access user:rw group:rw all:r;
          create_full_put_path on;
&nbsp;
          # auth access
          auth_basic &quot;Restricted&quot;;
          auth_basic_user_file ;
     }
}</pre></div></div>

<p>After configuring server, you`ll need to create htpassword file, that will keep user credentials.<br />
Simple example:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">htpasswd <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">/</span>where<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>save<span style="color: #000000; font-weight: bold;">/</span>the<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">file</span> username</pre></div></div>

<p>More information about how to configure nginx can be found at <a title="Nginx Modules information" href="http://wiki.codemongers.com/NginxModules" target="_blank">http://wiki.codemongers.com/NginxModules</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/01/15/configuring-webdav-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Streaming FLV videos problem in nginx 0.6.32</title>
		<link>http://blog.sosedoff.com/2009/01/15/streaming-flv-videos-problem-in-nginx/</link>
		<comments>http://blog.sosedoff.com/2009/01/15/streaming-flv-videos-problem-in-nginx/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 10:16:22 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[flv streaming]]></category>
		<category><![CDATA[jwplayer]]></category>
		<category><![CDATA[problem]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=4</guid>
		<description><![CDATA[nginx, fast small webserver, supports flash flv files streaming.
I am currently using JW Player 4.0 on projects, its free, lightweight and have a lot useful features.
But, i got some problems with its latest versions. It always adding some special information, like player container resolution like this:
myvideo.flv?start=2659763&#038;width=280&#038;version=4.0&#038;...
Result: cannot seek on the video.
Found a solution on ruby [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sysoev.ru/nginx">nginx</a>, fast small webserver, supports flash flv files streaming.<br />
I am currently using JW Player 4.0 on projects, its free, lightweight and have a lot useful features.<br />
But, i got some problems with its latest versions. It always adding some special information, like player container resolution like this:</p>
<pre>myvideo.flv?start=2659763&#038;width=280&#038;version=4.0&#038;...</pre>
<p>Result: cannot seek on the video.<br />
Found a solution on ruby forum. <a href="http://www.ruby-forum.com/attachment/2307/patch.flv">http://www.ruby-forum.com/attachment/2307/patch.flv</a><br />
You need only apply this patch to sources and rebuild nginx. That`s it.</p>
<p>P.S. Don`t know about older versions of nginx, but 0.6.32 from sources doesnt work with JW Player 4.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/01/15/streaming-flv-videos-problem-in-nginx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

