<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>nginx &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/nginx/</link>
	<description>Feed of posts on WordPress.com tagged "nginx"</description>
	<pubDate>Sun, 29 Nov 2009 02:44:15 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Image upload issue in wordpressmu with nginx]]></title>
<link>http://purab.wordpress.com/2009/11/26/image-upload-issue-in-wordpressmu-with-nginx/</link>
<pubDate>Thu, 26 Nov 2009 08:40:11 +0000</pubDate>
<dc:creator>purab</dc:creator>
<guid>http://purab.wordpress.com/2009/11/26/image-upload-issue-in-wordpressmu-with-nginx/</guid>
<description><![CDATA[I sovled the issue with WordprssMU and Images. you can use following code. Please Use the following ]]></description>
<content:encoded><![CDATA[I sovled the issue with WordprssMU and Images. you can use following code. Please Use the following ]]></content:encoded>
</item>
<item>
<title><![CDATA[Nginx rule with image fix for multiple wordpress instance]]></title>
<link>http://purab.wordpress.com/2009/11/26/nginx-rule-with-image-fix-for-multiple-wordpress-instance/</link>
<pubDate>Thu, 26 Nov 2009 08:37:07 +0000</pubDate>
<dc:creator>purab</dc:creator>
<guid>http://purab.wordpress.com/2009/11/26/nginx-rule-with-image-fix-for-multiple-wordpress-instance/</guid>
<description><![CDATA[I sovled the issue with Wordprss and Images. If you want to host or install two instances on one dom]]></description>
<content:encoded><![CDATA[I sovled the issue with Wordprss and Images. If you want to host or install two instances on one dom]]></content:encoded>
</item>
<item>
<title><![CDATA[How to host multiple rails site on Nginx]]></title>
<link>http://purab.wordpress.com/2009/11/18/how-to-host-multiple-rails-site-on-nginx/</link>
<pubDate>Wed, 18 Nov 2009 07:28:18 +0000</pubDate>
<dc:creator>purab</dc:creator>
<guid>http://purab.wordpress.com/2009/11/18/how-to-host-multiple-rails-site-on-nginx/</guid>
<description><![CDATA[User following code in Nginx.conf file.. and paste into that file #vim /etc/nginx/nginx.conf http { ]]></description>
<content:encoded><![CDATA[User following code in Nginx.conf file.. and paste into that file #vim /etc/nginx/nginx.conf http { ]]></content:encoded>
</item>
<item>
<title><![CDATA[Desplegando aplicaciones RoR: Capistrano + Mongrel (I)]]></title>
<link>http://yodesarrollo.wordpress.com/2009/11/16/desplegando-aplicaciones-ror-con-capistrano-mongrel-nginx-12/</link>
<pubDate>Mon, 16 Nov 2009 13:11:46 +0000</pubDate>
<dc:creator>Pablo</dc:creator>
<guid>http://yodesarrollo.wordpress.com/2009/11/16/desplegando-aplicaciones-ror-con-capistrano-mongrel-nginx-12/</guid>
<description><![CDATA[Estos días en el trabajo he estado desplegando una aplicación web hecha en Ruby On Rails, y hoy por ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Estos días en el trabajo he estado desplegando una aplicación web hecha en Ruby On Rails, y hoy por fin acabamos con ello. La verdad que el despliegue ha sido bastante sencillo, quitando aquellos típicos errores por no saber <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Hay varios tutoriales para desplegar usando <a href="http://www.capify.org/index.php/Capistrano">Capistrano</a>, <a href="http://mongrel.rubyforge.org/">Mongrel</a> y <a href="http://nginx.net/">Nginx</a>, pero yo voy a postear mi propia solución.</p>
<p>Para empezar,supongo que tienes un servidor funcionando con Ruby, las gemas de Rails, acceso ssh y Subversion.</p>
<p>Vayamos por partes, como diría Jack El Destripador: instalar Mongrel y Nginx en el servidor (en mi caso un flamante Debian Lenny):</p>
<pre class="brush: plain;">
# apt-get install nginx
# ### Mongrel lo instalo como una gema de Ruby
# gem install mongrel mongrel-cluster
</pre>
<p>Ahora podemos instalar Capistrano en el equipo de trabajo local</p>
<pre class="brush: plain;"># gem install capistrano</pre>
<p>¿Está? Ahora comenzamos el trabajo de verdad. La documentación de Capistrano (<a href="http://www.capify.org/index.php/Getting_Started">Getting Started</a> y <a href="http://www.capify.org/index.php/From_The_Beginning">From The Beiginning</a>) son más que suficentes para hacer funcionar Capistrano como Dios manda. Vayamos a la carpeta de la aplicación y ejecuta lo siguiente (si no está en el path, no queda otra que buscarlo):</p>
<pre class="brush: plain;"># capify .</pre>
<p>Esto genera dos ficheros, Capfile y deploy.rb. El contenido de deploy.rb tendrá la siguiente forma:</p>
<pre class="brush: ruby;">

set :application, &#34;Nombre de la aplicación&#34;
set :repository,  &#34;Ruta del repositorio al código. Como no especifico nada más, Capistrano asume que es Subversion&#34;
# Desplegar desde la rama trunk puede estar bien, pero a veces puede ser mejor crear una rama estable y desplegar de ahí, para curarse en salud

role :web, &#34;192.168.1.192&#34;                          # Mi servidor HTTP, Apache/etc
role :app, &#34;192.168.1.192&#34;                          # Mi servidor de aplicaciones
role :db,  &#34;192.168.1.192&#34;,:primary =&#62; true         # Servidor de base de datos. Le indico también que es la base de datos primaria

set :deploy_to, &#34;/home/deploy/apps/nombre-aplicacion/&#34; # El sitio donde se va a desplegar
set :user, 'deploy' # El usuario que desplegará todo

# namespace :deploy do
#   task :start {}
#   task :stop {}
#   task :restart, :roles =&#62; :app, :except =&#62; { :no_release =&#62; true } do
#     run &#34;#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}&#34;
#   end
# end
</pre>
<p>En el fichero Capfile no suele haber que tocar nada, pero puede que necesites especificar que usuario va a arrancar el servidor de aplicaciones. Para ello añade la siguiente línea al fichero Capfile:</p>
<pre class="brush: ruby;">set :runner, 'deploy'</pre>
<p>Con esto, un desplegado debería funcionar, como norma general. Para mas opciones, mira en los enlaces que mencioné antes.</p>
<p>Ahora, con Capistrano preparado para la marcha, y el servidor con las aplicaciones necesarias, desplegar es tan sencillo como hacer desde el equipo de trabajo:</p>
<pre class="brush: plain;">

cap deploy: setup
# =&#62; Con esto se prepara el servidor con la jerarquía de carpetas
# Después de esto es mejor mirar si las carpetas tienen el propietario y los permisos que deben.
cap deploy:check
# =&#62; Un chequeo de dependencias automático
cap deploy:update
# =&#62; Hace un checkout de la última versión del repositorio y lo organiza, estableciendo la ultima versión como &#34;current&#34;.</pre>
<p>Ahora damos respiro a este equipo, ya que tenemos que crear la base de datos. para ello nos conectamos a la base de datos de turno para la producción, creamos usuarios y todo lo necesario y desde el servidor mandamos hacer las migraciones:</p>
<pre class="brush: plain;">rake RAILS_ENV=production db:schema:load
# = &#62; Cualquier error aquí vendrá por que falta algo por hacer, o database.yml tiene algún dato incorrecto</pre>
<p>Con todo esto, ya debería funcionar la aplicación web. Podemos probarlo con &#8220;script/console production&#8221; o con WEBrick</p>
<p>Para que Capistrano pueda arrancar el servidor de aplicaciones, hay que crear un script en la carpeta script del proyecto. Lo llamamos spin, y para funcionar con Mongrel, ha de tener lo siguiente (cambiando por tus datos, claro ^_^):</p>
<pre class="brush: plain;">#!/bin/sh

/home/deploy/apps/mvweb4/current/script/process/spawner \
 mongrel \
 --environment=production \
 --instances=1 \
 --address=127.0.0.1 \
 --port=8000</pre>
<p>Si quisiera ejecutar más mongrels, en distintos puertos, solo tengo que repetir ese comando en el fichero.</p>
<p>Ahora, solo queda que en el equipo se mande a capistrano que arranque los Mongrel con:</p>
<pre class="brush: plain;"># cap deploy:start</pre>
<p>Gracias a todo esto tenemos el servidor de aplicaciones escuchando, desde local todo funciona, pero nos queda el servidor web. Como este post esta quedando muy largo, dejo para el siguiente finiquitar esto y dejarlo 100% funcional. Si llegaste leyendo hasta aquí ¡enhorabuena!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[instalacja nowoczesnego serwera WWW z obsługą PHP i skryptu DokuWiki]]></title>
<link>http://trycode.wordpress.com/2009/11/16/nginx-php-php-fpm-dokuwiki/</link>
<pubDate>Mon, 16 Nov 2009 12:51:33 +0000</pubDate>
<dc:creator>trym</dc:creator>
<guid>http://trycode.wordpress.com/2009/11/16/nginx-php-php-fpm-dokuwiki/</guid>
<description><![CDATA[Czego będziemy potrzebowali aby uruchomić nasze Wiki: PHP, PHP-FPM, XCache, Nginx, skrypt DokuWiki, ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Czego będziemy potrzebowali aby uruchomić nasze Wiki:</p>
<ul>
<li>PHP,</li>
<li>PHP-FPM,</li>
<li>XCache,</li>
<li>Nginx,</li>
<li>skrypt DokuWiki,</li>
<li>oraz kilku podstawowych pakietów z repozytorium.</li>
</ul>
<p><em>PHP </em>myślę, że nie ma specjalnej potrzeby w tym miejscu opisywać. Dodam tylko, że **PHP-FPM** ma za zadanie nieco podnieść wydajność i zachęcam do skorzystania.</p>
<p><em>Nginx (wym. engine x)</em> jest ultraszybkim oraz zajmującym mało pamięci serwerem WWW. Tworzony jest przez rosyjskiego programistę Igora Sysojewa. Więcej na temat serwera na [[http://sysoev.ru/en/&#124;stronie domowej projektu]].<br />
<!--more--><br />
W zasadzie DokuWiki może działać zgodnie z różnymi serwerami WWW, ale ja wybrałem do tej pory nieznanego mi Nginx.</p>
<h5>Przygotowanie systemu</h5>
<p>Nie jest to zbyt wymagająca procedura, ale należy mieć podstawowe paczki dostępne w repozytorium. Chociażby z tego powodu, że będą potrzebne do późniejszej kompilacji. Moglibyśmy wszystko pobrać z repozytorium Debiana, jednak ma to swoje wady. Po pierwsze PHP ma zbyt dużo zależności, a po drugie instalując ze źródeł skorzystamy z nowszych wersji pakietów (przykładowo na dzień dzisiejszy w repo (testing) mamy wersję Nginx&#8217;a 0.6.34-2, a my ze źródeł zainstalujemy 0.7.60).</p>
<p>W celu instalacji wspomnianych pakietów należy wykonać komendę:</p>
<p><code>aptitude install build-essential libtool libltdl3-dev libgd-dev libmcrypt-dev libxml2-dev libmysqlclient15-dev flex m4 awk automake autoconf bison make<br />
libbz2-dev libpcre3-dev libssl-dev zlib1g-dev re2c mysql-server postfix libjpeg62 libjpeg62-dbg libjpeg62-dev libpng12-0 libpng12-0-dev</code></p>
<p>Jest to zbiór, który powinien w zupełności wystarczyć.</p>
<h5>Instalacja oraz konfiguracja PHP/PHP-FPM</h5>
<p>Dobrym pomysłem jest stworzenie katalogu gdzie będziemy przechowywać źródła pakietów.<br />
**Uwaga**: znak &#8220;$&#8221; przed komendą oznacza wykonanie jej z poziomu zwykłego użytkownika, zaś &#8220;#&#8221; z poziomu su (root).</p>
<p><code>$ mkdir ~/zrodla<br />
$ cd ~/zrodla<br />
$ wget http://pt.php.net/distributions/php-5.2.8.tar.bz2<br />
$ tar xjf php-5.2.8.tar.bz2<br />
$ wget http://php-fpm.anight.org/downloads/head/php-5.2.8-fpm-0.5.10.diff.gz<br />
$ gzip -cd php-5.2.8-fpm-0.5.10.diff.gz &#124; patch -d php-5.2.8 -p1<br />
$ cd php-5.2.8<br />
$ ./configure --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --with-openssl --with-mysql --with-mysql-sock --with-gd<br />
--with-jpeg-dir=/usr/lib --enable-gd-native-ttf --without-sqlite --disable-pdo --disable-reflection<br />
#make all install<br />
#strip /usr/local/bin/php-cgi</code></p>
<p>Oczywiście można użyć dowolnej wersji PHP. Ewentualnie można opcje ./configure dopasować do własnych potrzeb lub zostawić tak jak jest.</p>
<p>Teraz zajmiemy się edycją pliku konfiguracyjnego PHP-FPM za pomocą dowolnego edytora, np. //vim//.</p>
<p><code># vim /usr/local/etc/php-fpm.conf</code></p>
<p>Przechodzimy do linii pliku konfiguracyjnego numer 63. oraz 66. i ustanawiamy nazwę oraz grupę użytkownika. Pamiętamy przy tym aby dany użytkownik istniał w systemie (ja grupę zostawiłem bez zmian).</p>
<h5>Instalacja oraz konfiguracja XCache</h5>
<p>XCache to dwu modułowe rozszerzenie dla PHP pozwalające na korzystanie z mechanizmu cache. Ma na celu przyspieszać wykonywanie aplikacji PHP.</p>
<p><code>$ cd ~/zrodla<br />
$ wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz<br />
$ tar xzvf xcache-1.2.2.tar.gz<br />
$ cd xcache-1.2.2<br />
$ phpize<br />
$ ./configure --with-php-config=/usr/local/bin/php-config --enable-xcache<br />
# make install</code></p>
<p>Polecenie //phpize// wspomaga instalowanie dodatków dla PHP.</p>
<h5>Instalacja oraz konfiguracja Nginx</h5>
<p><code>$ cd ~/zrodla<br />
$ wget http://sysoev.ru/nginx/nginx-0.7.60.tar.gz<br />
$ tar xzvf nginx-0.7.60.tar.gz<br />
$ cd nginx-0.7.60<br />
$ ./configure --sbin-path=/usr/local/sbin --with-http_ssl_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module<br />
$ make<br />
$make install</code></p>
<p>Edytujemy plik konfiguracyjny:<br />
<code># vim /usr/local/nginx/conf/ngingx.conf</code></p>
<p>Do postaci:<br />
<code>user nazwa_usera;<br />
worker_processes 2;<br />
events {<br />
worker_connections 768;<br />
}<br />
http {<br />
include mime.types;<br />
default_type application/octet-stream;<br />
sendfile on;<br />
tcp_nodelay on;<br />
keepalive_timeout 10 10;<br />
gzip on;<br />
gzip_comp_level 1; gzip_proxied any;<br />
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;<br />
include /usr/local/nginx/sites-enabled/*;<br />
}</code></p>
<p>W 1. linii powyższego pliku należy podać w polu //nazwa_usera// nazwę użytkownika podaną wcześniej w pliku ///usr/local/etc/php-fpm.conf//.</p>
<p>Następnie:<br />
<code># vim /usr/local/nginx/conf/fastcgi_params</code></p>
<p>I na końcu pliku dopisujemy:<br />
<code>fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;</code></p>
<p>Tworzymy potrzebny katalog i plik:</p>
<p><code># mkdir /usr/local/nginx/sites-enabled<br />
# vim /usr/local/nginx/sites-enabled/trycode.net</code></p>
<p>Jeżeli korzystamy z innego edytora aniżeli //vim// i otrzymujemy informację, że plik ///usr/local/nginx/sites-enabled/trycode.net// nie istnieje to należy go stworzyć. Po utworzeniu pliku uzupełniamy go w następujący sposób:</p>
<p><code>server {<br />
listen 80;<br />
server_name www.trycode.net;<br />
index index.php;<br />
root /var/www/wiki;<br />
location / {<br />
error_page 404 = //index.php?q=$uri;<br />
}<br />
location ~ .php$ {<br />
fastcgi_pass 127.0.0.1:9000;<br />
fastcgi_index index.php;<br />
include /usr/local/nginx/conf/fastcgi_params;<br />
}<br />
}<br />
</code></p>
<p>Jeszcze na koniec edycja pliku ///usr/local/lib/php.ini//. Jeśli plik nie istnieje to zachowujemy się identycznie jak wyżej i uzupełniamy go treścią:</p>
<p><code>magic_quotes_gpc=0<br />
[xcache-common]<br />
zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20060613/xcache.so<br />
[xcache]<br />
xcache.shm_scheme = "mmap"<br />
xcache.size = 64M<br />
date.timezone = "Europe/Rome"<br />
default_charset = "utf-8"<br />
</code></p>
<p>Uruchamiamy //PHP-FPM// i //Nginx//:<br />
<code># php-fpm start<br />
# nginx</code></p>
<h5>Czas aby wiki ujrzało światło dzienne</h5>
<p>Instalacja DokuWiki nie jest ani trudna, ani pracochłonna. Ściągamy nową wersję skryptu i rozpakowujemy archiwum:</p>
<p><code>$ wget http://www.splitbrain.org/_media/projects/dokuwiki/dokuwiki-2009-02-14b.tgz<br />
$ tar -xzvf dokuwiki-2009-02-14b.tgz</code></p>
<p>Teraz przenosimy zawartość rozpakowanego katalogu (na serwer) do ///var/www/wiki// i:</p>
<p><code>$ touch /var/www/wiki/data/changes.log<br />
$ cd /var/www/wiki<br />
$ chmod 666 data/changes.log<br />
$ chmod 777 data/<br />
$ chmod 777 data/attic</code></p>
<p>Po tych zabiegach możemy już uruchomić plik instalacyjny:<br />
<code>http://localhost/wiki/install.php</code></p>
<p>Dalej ustalamy użytkownika, hasło, nazwę wiki itp. Gdy chcemy lokalnie odwiedzić własną stronę (np. w celu edycji) to w przeglądarce internetowej wpisujemy:<br />
<code>http://localhost/wiki</code></p>
<h5>Inne</h5>
<p>Jeśli chcemy uruchomić <em>dokuwiki</em> na komputerze bez Xów możemy plik instalacyjny uruchomić (dla pewnego ułatwienia) z innego komputera w sieci LAN wyposażonego w środowisko graficzne. W tym celu należy podać w przeglądarce WWW adres IP serwera, np.:<br />
<code>http://192.168.100.244/wiki/install.php</code></p>
<p>Lub w celu późniejszej edycji stron:<br />
<code>http://192.168.100.244/wiki</code></p>
<p><em>/var/www/wiki/lib/tpl </em>&#8211; przechowujemy szablony<br />
<em>/var/www/wiki/data/media/wiki</em> &#8212; grafikę (zdjęcia) w formacie <em>png</em> lub <em>jpg</em><br />
<em>/var/www/wiki/data/pages</em> &#8212; strony zawarte w plikach tekstowych</p>
<p>Aby zmienić szablon:<br />
Administracja -&#62; Ustawienia -&#62; Podstawowe -&#62; Motyw</p>
<p>Lub edytując plik:</p>
<p>Jeśli chcemy móc stosować kod <em>PHP</em> lub <em>HTML</em> to należy zaznaczyć te opcje, ponieważ standardowo są wyłączone:<br />
Administracja -&#62; Ustawienia -&#62; Edycja -&#62; Wstawki HTML<br />
Administracja -&#62; Ustawienia -&#62; Edycja -&#62; Wstawki PHP</p>
<p><em>Artykuł przetłumaczony, rozszerzony i poprawiony na podst. <a href="http://www.yawn.it/2008/04/30/nginx-php-php-fpm-on-debian-etch-40/">źródła w jęz. angielskim</a></em>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Capistrano + Nginx + Thin deployment on Linode]]></title>
<link>http://gautamrege.wordpress.com/2009/11/10/capistrano-nginx-thin-deployment-on-linode/</link>
<pubDate>Tue, 10 Nov 2009 12:58:16 +0000</pubDate>
<dc:creator>gautamrege</dc:creator>
<guid>http://gautamrege.wordpress.com/2009/11/10/capistrano-nginx-thin-deployment-on-linode/</guid>
<description><![CDATA[This was long lost post I had written about 8 months ago (converted from wiki to HTML &#8211; so par]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>This was long lost post I had written about 8 months ago (converted from wiki to HTML &#8211; so pardon typos if any)</p>
<h2>Terminologies</h2>
<p><strong>Capistrano</strong> is a ruby gem which helps in remote deployment. As against widely known convention, Capistrano can be used for <strong>any</strong> deployment, not just a rails app!</p>
<p><strong>Nginx</strong> is a web-proxy server. This is simply a light weight HTTP web-server which received requests on HTTP and passes them to other applications. This is way more preferable than Application servers like Apache! Moreover, nginx is very easily configurable and can support multiple domain-names very easily. It has an in-build load-balancer which can send requests to apps based on its internal load-balancing mechanism.</p>
<p><strong>Thin</strong> is the next-generation lean, mean rails server. Its much faster, lighter in memory than mongrel. Its has an internal event based mechanism for request processing and a very high concurrency performance ratio than other rails servers.</p>
<p><strong>Linode</strong> is a VPS (a Virtual Private Server) that is hosted by <a href="http://www.linode.com">www.linode.com</a>. As the name suggests <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> , its a &#8220;Linux Node&#8221;.  We are using Ubuntu 8.10 (Tip: To find Ubuntu release, issue command: lsb_release -a) <strong>NOTE:</strong> In the linode we had, it was a raw machine with no packages installed. Please read <a href="http://wiki.rubyonrails.org/getting-started/installation/linux">Linode RoR package installation</a> for details.</p>
<h2>Steps</h2>
<p><strong>Capistrano Configuration</strong> Follow the steps provided by Capistrano for basic instructions: <a href="http://www.capify.org/getting-started/from-the-beginning">Capistrano &#8211; From The Beginning</a> Some modifications that you may need (as I needed for deployment):</p>
<ul>
<li>Edit Capfile and add the following to it. This ensures that remote capistrano deployment does not fork a remote shell using command &#8220;sh -c&#8221;. Some hosting servers do not allow remote shells.</li>
<pre>default_run_options[:shell] = false</pre>
<li>In addition to changes mentioned in Capistrano tutorial, add the following to config/deploy.rb. This ensures that &#8220;sudo&#8221; is not used (default for Capistrano) and the user is &#8220;root&#8221;. Not usually a good practice.. but what the hell!</li>
<pre>set :use_sudo, false            set :user, "root"</pre>
<li> Since capistrano uses default script/spin and script/process/reaper, we need to override the deploy:start, deploy:stop and deploy:restart to ensure that we can start/stop the thin service and the ferret_server. I know that in deply:restart, there is a copy-paste involved but I am trying to find out how to invoke a rake task from another rake task.</li>
</ul>
<pre>namespace :deploy do
    desc "Custom AceMoney deployment: stop."
    task :stop, :roles =&#62; :app do

        invoke_command "cd #{current_path};./script/ferret_server -e production stop"
        invoke_command "service thin stop"
    end

    desc "Custom AceMoney deployment: start."
    task :start, :roles =&#62; :app do

        invoke_command "cd #{current_path};./script/ferret_server -e production start"
        invoke_command "service thin start"
    end

    # Need to define this restart ALSO as 'cap deploy' uses it
    # (Gautam) I dont know how to call tasks within tasks.
    desc "Custom AceMoney deployment: restart."
    task :restart, :roles =&#62; :app do

        invoke_command "cd #{current_path};./script/ferret_server -e production stop"
        invoke_command "service thin stop"
        invoke_command "cd #{current_path};./script/ferret_server -e production start"
        invoke_command "service thin start"
    end
end</pre>
<p><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;"><strong>Thin Configuraion</strong> I looked up most of the default configuration of Thin and Nginx on Ubunto at <a href="http://newwiki.rubyonrails.org/deployment/nginx-thin">Nginx + Thin</a>. Some extra configuration or differences are mentioned below. </span></p>
<ul>
<li><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">The init script for starting thin and nginx during startup is configured during package installation. Leave them as they are.</span></li>
<li><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">The following command generates the /etc/thin/acemoney.yml for 3 server starting from port 3000. Note that the -c option specifies the BASEDIR of the rails app. Do NOT change any settings in this file as far as possible.</span></li>
<pre><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">thin config -C /etc/thin/acemoney.yml -c /home/josh/current --servers 3 -e production -p 3000</span></pre>
<li><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">Starting and stopping thin is as simple as</span></li>
<pre><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">service thin start</span>
<span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">service thin stop</span></pre>
<li><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">This will read the acemoney.yml file and spawn the 3 thin processes. I noticed that each thin server took about 31MB in memory to start with and with caching went upto ~70MB. On the contrary, a mongrel server (tested earlier) started with 31MB but exceeded 110MB later! </span></li>
</ul>
<p><strong>Nginx Configuration</strong> Installation on nginx is simple on Ubuntu <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<pre>apt-get install nginx</pre>
<p>Configure the base /etc/nginx/nginx.conf. The default configuration are fine but I added / edited a few more for as recommended at <a href="http://articles.slicehost.com/2009/3/5/ubuntu-intrepid-nginx-configuration">Nginx Configuration</a></p>
<pre>        worker_processes  4;

        gzip_comp_level 2;
        gzip_proxied any;
        gzip_types  text/plain text/html text/css application/x-javascript
                    text/xml application/xml application/xml+rss text/javascript;</pre>
<p>According to this configuration above, nginx will spawn 4 worker threads and each worker thread can process 1024 connections (default setting). So, nginx can now process ~4000 concurrent HTTP requests !!! See performance article of thin at <a href="http://www.rubyinside.com/thin-a-ruby-http-daemon-thats-faster-than-mongrel-688.html"><span style="color:#000000;"><span style="text-decoration:none;">Thin Server</span></span></a></p>
<p>Configure the domainname, in our case acemoney.in. Ensure that acemoney.in &#8220;A record&#8221; entry points to this server! Check this by doing a nslookup or a ping for the server. In /etc/nginx/sites-available create a file by the domainname to be hosted. So I added /etc/nginx/sites-available/acemoney.in. In /etc/nginx/sites-enabled create a symbolic link to this file.</p>
<pre><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">ln -s /etc/nginx/sites-available/acemoney.in /etc/nginx/sites-enabled/acemoney.in </span></pre>
<p><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;"> </span><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">Now add the contents in /etc/nginx/sites-available/acemoney.in <strong>This</strong> is the key configuration to hook up nginx with thin.</span></p>
<p><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-size:small;"><span style="line-height:19px;white-space:normal;"> </span></span></p>
<p><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-size:small;"> </span></p>
<pre>upstream thin {
     server 127.0.0.1:3000;
     server 127.0.0.1:3001;
     server 127.0.0.1:3002;
}

server {
    listen 80;
    server_name acemoney.in;

    root /home/josh/current/public;

    location / {
      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/index.html) {
        rewrite (.*) $1/index.html break;
      }
      if (-f $request_filename.html) {
        rewrite (.*) $1.html break;
      }
      if (!-f $request_filename) {
        proxy_pass http://thin;
        break;
      }
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
      root html;
    }
}</pre>
<p><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">To analyze this configuration, here are some details: </span></p>
<p><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">The following lines tell nginx to listen on port 80 for HTTP requests to acemoney.in. The &#8216;root&#8217; is the public directory for our rails app deployed at /home/josh/current! </span></p>
<pre>server {
    listen 80;
    server_name acemoney.in;

    root /home/josh/current/public;</pre>
<p><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;"> Now, nginx will try to process all HTTP requests and try to give the response.. for static HTML&#8217;s it will automatically give the data from the &#8216;root&#8217;. If it cannot find the HTML file, it will &#8216;proxy_pass&#8217; it to thin. &#8220;thin&#8221; in the code below is an &#8216;upstream&#8217; directive that tells nginx where to forward the current request it cannot directly serve.</span> <span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-size:small;"> </span></p>
<pre>if (!-f $request_filename) {
        proxy_pass http://thin;
        break;
      }</pre>
<p><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">The upstream code is where load-balancing plays a role in nginx. The following code tells nginx which all processes are running on which different ports and it forwards requests to <strong>any</strong> of the servers based on its internal load balancing algorithm. The servers can be on different machines (i.e. different IP addresses) if needed. In AceMoney, we have started 3 thin servers on 3 different ports! </span> <span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-size:small;"> </span></p>
<pre>upstream thin {
     server 127.0.0.1:3000;
     server 127.0.0.1:3001;
     server 127.0.0.1:3002;
}</pre>
<p><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;"><strong>Performance Statistics</strong></span> <span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;"> Nothing is complete without them. Here is what I found out for 3 thin servers and 1 ferret_server.</span></p>
<pre>top - 14:06:10 up 7 days, 22:58,  2 users,  load average: 0.00, 0.00, 0.00
Tasks:  84 total,   1 running,  83 sleeping,   0 stopped,   0 zombie
Cpu0  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu1  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu2  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu3  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    553176k total,   530868k used,    22308k free,    16196k buffers
Swap:   524280k total,     2520k used,   521760k free,    87280k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
12424 mysql     18   0  127m  42m 5520 S    0  7.9   0:23.01 mysqld
18338 root      15   0 77572  70m 4392 S    0 13.1   0:06.79 thin
18348 root      15   0 71176  64m 4388 S    0 11.9   0:06.51 thin
18343 root      15   0 68964  62m 4384 S    0 11.5   0:07.20 thin
18375 root      18   0 70912  54m 2660 S    0 10.0   2:34.24 ruby
 8141 www-data  15   0  5176 1736  820 S    0  0.3   0:00.07 nginx
 8142 www-data  15   0  5176 1724  816 S    0  0.3   0:00.01 nginx
 8144 www-data  15   0  5152 1720  816 S    0  0.3   0:00.06 nginx
 8143 www-data  15   0  5156 1656  784 S    0  0.3   0:00.00 nginx</pre>
<p><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">As can be seen: </span></p>
<ul>
<li><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">Each thin server takes around 70M</span></li>
<li><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">The Mysql server takes 41M</span></li>
<li><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;">Ruby process (18375 above) is the ferret_serve which takes 54M</span></li>
<li><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;"> 4 nginx threads take about 1.7K in memory. </span></li>
</ul>
<pre><span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;line-height:19px;white-space:normal;font-size:13px;"> Overall: (3 thin server cluster + Mysql + ferret): <strong>300MB</strong></span></pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[为NGINX配置AWStats日志分析]]></title>
<link>http://freshventure.wordpress.com/2009/11/10/%e4%b8%banginx%e9%85%8d%e7%bd%aeawstats%e6%97%a5%e5%bf%97%e5%88%86%e6%9e%90/</link>
<pubDate>Tue, 10 Nov 2009 10:38:04 +0000</pubDate>
<dc:creator>freshventure</dc:creator>
<guid>http://freshventure.wordpress.com/2009/11/10/%e4%b8%banginx%e9%85%8d%e7%bd%aeawstats%e6%97%a5%e5%bf%97%e5%88%86%e6%9e%90/</guid>
<description><![CDATA[虽然AWStats现在已经支持输出静态网页形式的分析结果，但是页面布局没有用Perl生成的动态网页方便，而且用自带的用Perl编写的转换工具稍微有点慢，在流量不大的情况下，还是在Perl+Fast C]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>虽然AWStats现在已经支持输出静态网页形式的分析结果，但是页面布局没有用Perl生成的动态网页方便，而且用自带的用Perl编写的转换工具稍微有点慢，在流量不大的情况下，还是在Perl+Fast CGI上运行更舒服一些。</p>
<p>首先要参考之前的文章，建立好PERL+FCGI的运行环境，这步准备工作就够费劲的。</p>
<p>然后开始切入正题：</p>
<p>1. 下载最新版的AWStats，基本就是Perl包，所以没必要用apt-get，解压缩到/usr/local/awstats下</p>
<p>wget http://prdownloads.sourceforge.net/awstats/awstats-6.95.tar.gz<br />
tar -xzf awstats-6.95.tar.gz<br />
mv awstats-6.95 /usr/local/awstats</p>
<p>2. 创建一个存放awstats分析数据的目录<br />
mkdir /var/lib/awstats<br />
chown www-data /var/lib/awstats  //这是为了让awstats页面上能直接刷新最新数据</p>
<p>3. 自动配置awstats</p>
<p>cd /usr/local/awstats/tools<br />
perl awstats_configure.pl</p>
<p>除了第一步因为是Ngin服务器的关系，所以要选none，其他基本按照提示选默认值</p>
<p>4. 手工编辑配置文件</p>
<p>1) 修改LogFile路径</p>
<p>LogFile = &#8220;/var/log/nginx/access.log&#8221;</p>
<p>如果是压缩格式的日志，可以用LogFile = &#8220;zcat /var/log/nginx/<code>%YYYY-24%MM-24%DD-24.gz<strong><span style="color:#ff0000;">&#124;</span></strong><span style="color:#000000;">"。这里用zcat是因为其使用管道输出，对系统资源消耗比较小，<strong>千万不要忘了最后的管道操作符！</strong><br />
</span></code></p>
<p>假设原来/etc/nginx/nginx.conf中关于log部分是如此定义的：（<span style="color:#993300;"><strong>要小变量心空格，不能少，否则awstats就不认了</strong></span>）</p>
<p>log_format  main  &#8216;$remote_addr $remote_user [$time_local] &#8220;$request&#8221; $status &#8216;<br />
&#8216;$host $body_bytes_sent $gzip_ratio &#8220;$http_referer&#8221; &#8216;<br />
&#8216;&#8221;$http_user_agent&#8221; &#8220;$http_x_forwarded_for&#8221;&#8216;;</p>
<p>很容易知道，对应awstats配置文件中，LogFormat应该设置为<br />
LogFormat= &#8220;%host %logname %time1 %methodurl %code %host_r %bytesd  %gzipratio %refererquot %uaquot %otherquot&#8221;</p>
<p>最后一个选％otherquot是应为$http_x_forwarded_for在AWstats 6.95中还不认识</p>
<p>3) 将AllowToUpdateStatsFromBrowser=1，便于浏览器中即时刷新数据</p>
<p>5. 更新Awstats的分析记录，测试一下刚才的配置<br />
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=yousite.com</p>
<p>如果一切正常，应该看到类似以下的结果：<br />
Create/Update database for config &#8220;/etc/awstats/awstats.yoursite.com.conf&#8221; by AWStats version 6.95 (build 1.943)<br />
From data in log file &#8220;/var/log/nginx/access.log&#8221;&#8230;<br />
Phase 1 : First bypass old records, searching new record&#8230;<br />
Searching new records from beginning of log file&#8230;<br />
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)&#8230;<br />
Jumped lines in file: 0<br />
Parsed lines in file: 1234<br />
Found 0 dropped records,<br />
Found 0 corrupted records,<br />
Found 0 old records,<br />
Found 1234 new qualified records.</p>
<p>6. 修改logrotate.d下的nginx配置文件，在每天切割日志前，更新awstats状态</p>
<p>/var/log/nginx/*.log {<br />
daily<br />
missingok<br />
rotate 7<br />
compress<br />
delaycompress<br />
notifempty<br />
create 640 www-data www-data<br />
dateext<br />
sharedscripts<br />
prerotate<br />
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=yoursite.com<br />
sleep 59<br />
endscript<br />
postrotate<br />
if [ -f /var/run/nginx.pid ]; then<br />
kill -USR1 `cat /var/run/nginx.pid`<br />
fi<br />
endscript<br />
}</p>
<p>7. 接下来是最关键的NGINX配置，</p>
<p>#AWStatus Perl CGI  server<br />
server {<br />
listen       80;<br />
server_name  awstats.yoursite.com;<br />
access_log   /var/log/nginx/awstatus.log main;<br />
root /usr/local/awstats/wwwroot;<br />
auth_basic            &#8220;Restricted&#8221;;<br />
auth_basic_user_file  /etc/nginx/awstatus.pass;</p>
<p>location = / {<br />
rewrite ^ /awstats.pl?config=freshventure.info;<br />
}</p>
<p>location ~ .*(\.cgi&#124;\.pl?)$ {<br />
gzip off; #gzip makes scripts feel slower since they have to complete before getting gzipped<br />
root /usr/local/awstats/wwwroot/cgi-bin;<br />
fastcgi_pass 127.0.0.1:8000;<br />
fastcgi_index awstats.pl;<br />
fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;<br />
include        fastcgi_params;<br />
}</p>
<p>}</p>
<p>好了，测试一下http://awstats.yoursite.com，和前文一样，输入密码后，这次看到的应该就awstats的界面了</p>
<p>8. 如果需要配置静态页面，则可以在logrotate中替换掉上面的awstats.pl, 换成</p>
<p>/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=yoursite.com -lang=cn -dir=/usr/local/awstats/wwwroot -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl。</p>
<p>如果需要更频繁的更新访问情况，则可以把这句命令加入到crontab中，例如crontab -e -uwww-data。</p>
<p>然后nginx相应调整为显示静态网页就可以了</p>
<p>&#160;</p>
<p>参考文章：</p>
<p>1. <a href="http://www.anywolfs.com/liuhui/article.asp?id=320">刘辉 － awstats 配置模板 参考</a></p>
<p>2. 刘辉 －<a href="http://www.anywolfs.com/liuhui/article.asp?id=289"> AWStats：示来访者位置 QQ纯真库IP解析插件安装</a></p>
<p>3. Jeff&#8217;s Blog &#8211; <a href="http://www.jefflei.com/post/321.html">Awstats安装和设置</a></p>
<p>4. Jeff&#8217;s Blog -<a href="http://www.jefflei.com/post/360.html"> NGINX下运行Awstats</a></p>
<p>5. Jeff&#8217;s Blog &#8211; <a href="http://www.jefflei.com/post/464.html">IP地址数据库的自动更新</a></p>
<p>6. <a href="http://www.ibm.com/developerworks/cn/linux/l-cn-awstats-nginx/index.html">使用 awstats 分析 Nginx 的访问日志</a></p>
<p>今后拓展阅读</p>
<p>1. 车东 － <a href="http://www.chedong.com/blog/archives/001293.html">AWStats的千万级日志解决方案</a></p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:0;width:1px;height:1px;"><code>wget http://prdownloads.sourceforge.net/<a class="st_tag internal_tag" title="标签 awstats 下的日志" rel="tag" href="http://www.jefflei.com/tag/awstats">awstats</a>/<a class="st_tag internal_tag" title="标签 awstats 下的日志" rel="tag" href="http://www.jefflei.com/tag/awstats">awstats</a>-6.9.tar.gz<br />
tar -xvzf <a class="st_tag internal_tag" title="标签 awstats 下的日志" rel="tag" href="http://www.jefflei.com/tag/awstats">awstats</a>-6.9.tar.gz<br />
mv <a class="st_tag internal_tag" title="标签 awstats 下的日志" rel="tag" href="http://www.jefflei.com/tag/awstats">awstats</a>-6.9 /usr/local/<a class="st_tag internal_tag" title="标签 awstats 下的日志" rel="tag" href="http://www.jefflei.com/tag/awstats">awstats</a></code></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[为NGINX配置Perl和FCGI网关]]></title>
<link>http://freshventure.wordpress.com/2009/11/10/%e4%b8%banginx%e9%85%8d%e7%bd%aeperl%e5%92%8cfcgi%e7%bd%91%e5%85%b3/</link>
<pubDate>Tue, 10 Nov 2009 05:33:10 +0000</pubDate>
<dc:creator>freshventure</dc:creator>
<guid>http://freshventure.wordpress.com/2009/11/10/%e4%b8%banginx%e9%85%8d%e7%bd%aeperl%e5%92%8cfcgi%e7%bd%91%e5%85%b3/</guid>
<description><![CDATA[1.安装Perl 如果系统的没有的话, apt-get install perl 2.安装Perl的FCGI模块和FCGI进程管理模块 第一次运行-e的shell是，会问一堆关于config.pm的问]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>1.安装Perl</strong><br />
如果系统的没有的话, apt-get install perl<br />
<strong>2.安装Perl的FCGI模块和FCGI进程管理模块</strong><br />
第一次运行-e的shell是，会问一堆关于config.pm的问题。<br />
基本上一路回车，选默认值，当然在选择CSPAN镜像的时候，要挑离服务器近的位置</p>
<p>perl -MCPAN -e &#8216;install FCGI&#8217;<br />
perl -MCPAN -e &#8216;install FCGI::ProcManager&#8217;</p>
<p><strong>3. 创建Perl-fcgi.pl文件，作为Perl-FCGI的分配器(Wrapper）</strong></p>
<p>j网上通常的教程都是参考<a href="http://wiki.nginx.org/NginxSimpleCGI">NGINX SimpleCGI上的设置</a>，其中有一个问题就是cgi-wrapper生成的socket文件可能对www-data是无权操作的，我更喜欢和PHP设置成为一样的TCP/IP Socket, 所以要该以下几个地方：</p>
<p>$socket = FCGI::OpenSocket( &#8220;<span style="color:#0000ff;">127.0.0.1:8000</span>&#8220;, 10 ); #use IP sockets</p>
<p>注释掉 #$socket = FCGI::OpenSocket( &#8220;/var/run/nginx/perl_cgi-dispatch.sock&#8221;,</p>
<p>$proc_manager = FCGI::ProcManager-&#62;new( {n_processes =&#62;<strong> </strong><span style="color:#ff0000;"><strong>3</strong> </span>} ); ＃把进程改为3，节省资源，反正只是为了AWStats用</p>
<p>把文件名改为perl-fcgi.pl, chmod +x perl-fcgi.pl， 并将其复制或移动到/usr/bin/下。</p>
<p>试着运行一下，用 perl-fcgi.pl &#62;/dev/null 2&#62;$1 &#38;<br />
第一个参数表示stdout重定向到空设备，不在屏幕上显示<br />
第二个参数表示stderr重定向到设备1，也就是刚才的空设备，不在屏幕上显示<br />
第三个参数表示该进程作为Daemon独立运行，脱离Dash</p>
<p>如果OK的化，用htops可以看到perl-fcgi-pm主进程以及3个perl-fcgi子进程。另外用netstat -tnlp可以看到端口127.0.0.1:8000正在被perl-fcgi-pm监听。不过以root运行并不安全，在启动脚本要以www-data身份运行</p>
<p><strong>4. 创建Perl-FCGI的启动脚本</strong></p>
<p>编辑启动脚本perlfcgi.sh, 然后在/etc/rc.local中 加入/root/perlfcgi.sh</p>
<p>由于perl-fcgi.pl这个脚本还不完善，不能用Ubuntu自带的start-stop-daemon来启动，也不会保存PID文件，也只能简陋的</p>
<p><strong>5. 编辑/etc/nging/nginx.conf，创建FCGI接口</strong></p>
<p>1) 安装whois工具包，获得mkpasswd命令： apt-get install whois<br />
因为我们想把Awstats的访问限制给网站管理员，需要让NGINX为此添加密码设置，要利用mkpasswd中附带的encrypt(3)对Password进行加密，这是NGINX 0.7.x系列唯一认识的加密方法</p>
<p>如果不装这个包，还有一个方法是用这里的<a href="http://trac.edgewall.org/browser/trunk/contrib/htpasswd.py">htpasswd.py脚本</a>，也可以达到目的</p>
<p>2)运行mkpasswd, 输入想要的密码后，系统为给出一个crypt(3)加密后的Code<br />
编辑 /etc/nginx/awstatus.pass文件，<br />
username:刚才生成的Code<br />
<strong><span style="color:#993300;">chmod +r /etc/nginx/awstatus.pass</span></strong> <strong>这步很重要!!</strong>，否则nginx进程无法读取该文件, 会报500错误</p>
<p>3）编辑/etc/nginx/nginx.conf， 添加一个CGI Server。这里需要在DNS服务器上增加一个CNAME转向awstatus.yoursite.com。 如果修改后不能立即生效的话，可以暂时修改本地host文件，一遍测试（如C:\Windows\System32\Drivers\etc\hosts, 添加一个IP记录）</p>
<p>#AWStatus Perl CGI  server<br />
server {<br />
listen       80;<br />
server_name awstats.yoursite.com;<br />
root /var/www/yoursite;<br />
auth_basic            &#8220;Restricted&#8221;;<br />
auth_basic_user_file  /etc/nginx/awstatus.pass;</p>
<p>location / {<br />
index index.cgi;<br />
}</p>
<p>location ~ .*(\.cgi&#124;\.pl?)$ {<br />
gzip off; #gzip makes scripts feel slower since they have to complete before getting gzipped<br />
fastcgi_pass 127.0.0.1:8000;<br />
fastcgi_index index.cgi;<br />
fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;<br />
include        fastcgi_params;<br />
}</p>
<p>}</p>
<p>重新加载NGINX服务，/etc/init.d/nginx reload</p>
<p>然后在http的根目录下，建立一个index.cgi， 包含</p>
<p>#!/usr/bin/perl</p>
<p>print &#8220;Content-type: text/html\n\n&#8221;;<br />
print &#8220;&#60;html&#62;&#60;body&#62;Hello, world.&#60;/body&#62;&#60;/html&#62;&#8221;;</p>
<p>chmod +x index.cgi<br />
然后用浏览器访问http://awstatus.yoursite.com/index.cgi， 输入完刚才的密码后应该能看到Hello,world.</p>
<p><strong><br />
</strong></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[为Fail2ban添加NGINX的Filter]]></title>
<link>http://freshventure.wordpress.com/2009/11/10/%e4%b8%bafail2ban%e6%b7%bb%e5%8a%a0nginx%e7%9a%84filter/</link>
<pubDate>Tue, 10 Nov 2009 01:31:59 +0000</pubDate>
<dc:creator>freshventure</dc:creator>
<guid>http://freshventure.wordpress.com/2009/11/10/%e4%b8%bafail2ban%e6%b7%bb%e5%8a%a0nginx%e7%9a%84filter/</guid>
<description><![CDATA[其实也很简单，添加以下到/etc/fail2ban/filter.d/nginx-auth.conf就可以了 failregex = no user/password.*client\: &lt;HO]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>其实也很简单，添加以下到/etc/fail2ban/filter.d/nginx-auth.conf就可以了</p>
<p>failregex = no user/password.*client\: &#60;HOST&#62;<br />
user.*authentication failure.*client\: &#60;HOST&#62;<br />
user.*not found.*client\: &#60;HOST&#62;<br />
user.*password mismatch.*client\: &#60;HOST&#62;</p>
<p>fail2ban自身有一个很方便的正则表达式测试工具：</p>
<p>fail2ban-regex  /var/log/nginx/error.log /etc/fail2ban/filter.d/nginx-auth.conf</p>
<p>可以看到究竟命中了多少条记录。</p>
<p>fail2ban比Denyhost等强的地方就在于可以方便的添加filter, 对不同类型服务进行设置，而不是仅仅限于SSH登录</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Cherokee Web Server]]></title>
<link>http://bongo90.wordpress.com/2009/11/09/cherokee-web-server/</link>
<pubDate>Sun, 08 Nov 2009 17:20:16 +0000</pubDate>
<dc:creator>Ariff</dc:creator>
<guid>http://bongo90.wordpress.com/2009/11/09/cherokee-web-server/</guid>
<description><![CDATA[Ada info baru ni tentang webserver yang baru saya kenal namanya Cherokee. Katanya si web server yang]]></description>
<content:encoded><![CDATA[Ada info baru ni tentang webserver yang baru saya kenal namanya Cherokee. Katanya si web server yang]]></content:encoded>
</item>
<item>
<title><![CDATA[Nginx vs Yaws vs MochiWeb : Web Server Performance Deathmatch, Part 2 [Update x 2]]]></title>
<link>http://maheshvnit.wordpress.com/2009/11/05/nginx-vs-yaws-vs-mochiweb-web-server-performance-deathmatch-part-2-update-x-2/</link>
<pubDate>Thu, 05 Nov 2009 07:01:56 +0000</pubDate>
<dc:creator>maheshvnit</dc:creator>
<guid>http://maheshvnit.wordpress.com/2009/11/05/nginx-vs-yaws-vs-mochiweb-web-server-performance-deathmatch-part-2-update-x-2/</guid>
<description><![CDATA[Update 1: Retest data (using different machine and Erlang kernel polling) added near bottom of post.]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><em>Update 1: Retest data (using different machine and Erlang kernel polling) added near bottom of post.</em></p>
<p><em><strong>Update 2</strong>: More details and testing on the weird MochiWeb kernel polling results, bottom of post.</em></p>
<p>Almost a year ago I did some <a href="http://www.joeandmotorboat.com/2008/02/28/apache-vs-nginx-web-server-performance-deathmatch/" target="_blank">Apache and Nginx performance testing</a>. Apparently I have the bug again and have done some performance testing on <a href="http://www.nginx.net/" target="_blank">Nginx</a>, <a href="http://yaws.hyber.org/" target="_blank">Yaws</a> and <a href="http://code.google.com/p/mochiweb/" target="_blank">MochiWeb</a>. The latter two being Erlang based. Again deathmatch may be an overstatement but this is my attempt at gleaning some interesting performance data from some high performance web servers. Also, I attempted to improve the graphs this time around since they were a bit hard to read the last time.</p>
<p><strong>The Setup:</strong></p>
<p>I was not able to use the same server and setup as the last time, so comparing between this and my last deathmatch probably isn’t very accurate. For this test I used a Intel Dual Core 2.2GHz, 4GB RAM machine running Ubuntu 8.10 (64bit) and for the test server. Erlang (R12B-3), Yaws (1.77) and Nginx (0.6.32) are installed from the standard repository and mochiweb from subversion (rev 88). All are using the <strong>default configurations</strong> outside of adjusting listening port numbers. The test is again against a basic robots.txt file. The tests were done using a consumer grade 100mb switch and all tests originated from an old laptop I had laying around. I think that about covers the test bed, if you have any questions let me know.</p>
<p>For the tests I used autobench (httperf under the hood) with the following command, each test ran ten minutes apart. The order of the tests were done in was MochiWeb then Yaws and lastly Nginx.</p>
<blockquote><p>autobench –single_host –host1 HOST –port1 PORT –uri1 /robots.txt –low_rate 10 –high_rate 200 –rate_step 10 –num_call 10 –num_conn 5000 –timeout 5 –file SERVER-results-`date +%F-%H:%M:%S`.ts</p>
<p><a href="http://www.noupe.com/php/php-security-tips.html#more-15885" target="_blank">Read the rest of this entry »</a></p>
<p>&#160;</p>
<p><a href="http://www.joeandmotorboat.com/2009/01/03/nginx-vs-yaws-vs-mochiweb-web-server-performance-deathmatch-part-2/" target="_blank">http://www.joeandmotorboat.com/2009/01/03/nginx-vs-yaws-vs-mochiweb-web-server-performance-deathmatch-part-2/</a></p>
<p>&#160;</p>
</blockquote>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Just Installed Nginx 0.7.63 on my office]]></title>
<link>http://cebudude.net/2009/11/03/just-installed-nginx-0-7-63-on-my-office/</link>
<pubDate>Tue, 03 Nov 2009 01:45:18 +0000</pubDate>
<dc:creator>bonjovax</dc:creator>
<guid>http://cebudude.net/2009/11/03/just-installed-nginx-0-7-63-on-my-office/</guid>
<description><![CDATA[Nginx (pronounced as &#8220;engine X&#8221;) is a lightweight, high performance web server/reverse p]]></description>
<content:encoded><![CDATA[Nginx (pronounced as &#8220;engine X&#8221;) is a lightweight, high performance web server/reverse p]]></content:encoded>
</item>
<item>
<title><![CDATA[Migrating Acemoney onto a different server with nginx+passenger]]></title>
<link>http://gautamrege.wordpress.com/2009/10/27/migrating-acemoney-onto-a-different-server-with-nginxpassenger/</link>
<pubDate>Tue, 27 Oct 2009 12:34:18 +0000</pubDate>
<dc:creator>gautamrege</dc:creator>
<guid>http://gautamrege.wordpress.com/2009/10/27/migrating-acemoney-onto-a-different-server-with-nginxpassenger/</guid>
<description><![CDATA[Acemoney is a hosted application built by us i.e. Josh Software. Currently, its hosted on a linode w]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Acemoney is a hosted application built by us i.e. Josh Software. Currently, its hosted on a linode with nginx+thin configured. The problem here is that there are 3 thin servers which consume humongous &#8217;stagnant&#8217; memory. We have decided to migrate to nginx+passenger so that we an control in greater detail the number of instances, the memory and the performance.</p>
<p>Some things in the post are specific to Josh Software and its client. Overall, this should give a good clean idea about migrating to passenger.</p>
<p>1. Checkout from the branch from the respository (the 2.3.4 version)</p>
<p>2. Ensure  Rails 2.3.4 is installed</p>
<p>3. Edit the nginx configuration. /opt/nginx/conf/servers/acemoney.in</p>
<p>server {</p>
<pre> listen 80;
 server_name acemoney.in;
 passenger_enabled on;
 root &#60;path-to-deployment&#62;/acemoney/public;
}</pre>
<p>4. Restart Nginx. In case you get an error &#8212; something like:</p>
<pre>2009/10/27 16:02:07 [error] 32685#0: *9 directory index of
"/home/gautam/deployment/acemoney/public/" is forbidden, client: 121.247.65.47,
server: acemoney.in, request: "GET / HTTP/1.1", host: "acemoney.in"
</pre>
<p>Check syntax in the conf file (I had forgotten a &#8216;;&#8217;) OR check permissions of the root directory to see if you have given r+x permissions</p>
<p>5. The current gem setup was:</p>
<pre>$:/opt/nginx/conf/servers$ sudo gem search

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (2.3.4, 2.3.3, 2.2.2, 2.1.2)
actionpack (2.3.4, 2.3.3, 2.2.2, 2.1.2)
activerecord (2.3.4, 2.3.3, 2.2.2, 2.1.2)
activeresource (2.3.4, 2.3.3, 2.2.2, 2.1.2)
activesupport (2.3.4, 2.3.3, 2.2.2, 2.1.2)
capistrano (2.5.5)
cgi_multipart_eof_fix (2.5.0)
chronic (0.2.3)
contacts (1.0.13)
daemons (1.0.10)
engineyard-eycap (0.4.7)
erubis (2.6.4)
eventmachine (0.12.6)
fastthread (1.0.7)
gem_plugin (0.2.3)
heywatch (0.0.1)
highline (1.5.0)
hoe (1.12.2)
json (1.1.6)
memcache-client (1.7.2)
mislav-will_paginate (2.3.10)
mongrel (1.1.5)
mongrel_cluster (1.0.5)
mysql (2.7)
net-scp (1.0.2)
net-sftp (2.0.2)
net-ssh (2.0.11)
net-ssh-gateway (1.0.1)
packet (0.1.15)
passenger (2.2.5)
rack (1.0.0, 0.9.1)
rails (2.3.4, 2.3.3, 2.2.2, 2.1.2)
rake (0.8.4)
RedCloth (4.1.9)
right_aws (1.10.0)
right_http_connection (1.2.4)
rubyforge (1.0.3)
rubyist-aasm (2.0.5)
thin (1.0.0)
tidy (1.1.2)
xml-simple (1.0.12)
</pre>
<p>So, I had to add the following gems:</p>
<pre>$ sudo gem install acts_as_reportable</pre>
<p>This added the following dependencies:</p>
<p>Successfully installed fastercsv-1.2.3<br />
Successfully installed archive-tar-minitar-0.5.2<br />
Successfully installed color-1.4.0<br />
Successfully installed transaction-simple-1.4.0<br />
Successfully installed pdf-writer-1.1.8<br />
Successfully installed ruport-1.6.1<br />
Successfully installed acts_as_reportable-1.1.1<br />
Successfully installed json_pure-1.1.9<br />
Successfully installed rubyforge-2.0.3<br />
Successfully installed rake-0.8.7</p>
<pre>$ sudo gem install prawn
$ sudo gem install ferret
$ sudo gem install acts_as_ferret</pre>
<p>6. Then I got the latest database dump from Acemoney server and configured the database locally. Edit the config/database.yml and the following:</p>
<pre>production:
  adapter: mysql
  user: acemoney
  password: &#60;password&#62;
  host: localhost</pre>
<p>Created a new user in mysql and granted ALL  permissions to acemoney database</p>
<pre>mysql&#62; grant all on acemoney.* to 'acemoney'@'localhost' identified by '&#60;password&#62;'
</pre>
<p>Then create the database and dump the contents from the backup</p>
<pre>$ RAILS_ENV=production rake db:create
$ mysql -uacemoney acemoney -p &#60; &#60;backupfile&#62;
</pre>
<p>Start the ferret_server</p>
<pre>$ ./script/ferret_server -eproduction start
</pre>
<p>Build the index:</p>
<pre>$ RAILS_ENV=production rake ace:rebuildFerretIndex
</pre>
<p>NOW, we are good to go. Make some local changes in /etc/hosts file on your machine to point acemoney.in to the linode IP address. Then http://acemoney.in should take you to the hosted application on nginx+passenger.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Ubuntu服务器上相关日志的进一步调整]]></title>
<link>http://freshventure.wordpress.com/2009/10/23/ubuntu%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%b8%8a%e7%9b%b8%e5%85%b3%e6%97%a5%e5%bf%97%e7%9a%84%e8%bf%9b%e4%b8%80%e6%ad%a5%e8%b0%83%e6%95%b4/</link>
<pubDate>Fri, 23 Oct 2009 03:09:35 +0000</pubDate>
<dc:creator>freshventure</dc:creator>
<guid>http://freshventure.wordpress.com/2009/10/23/ubuntu%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%b8%8a%e7%9b%b8%e5%85%b3%e6%97%a5%e5%bf%97%e7%9a%84%e8%bf%9b%e4%b8%80%e6%ad%a5%e8%b0%83%e6%95%b4/</guid>
<description><![CDATA[1. VSFTPD vi /etc/vsftpd.conf xferlog_file=/var/log/vsftpd/vsftpd.log #调整一下目录存放位置，让/var/log下稍微清晰一些 v]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>1. VSFTPD</strong></p>
<p>vi /etc/vsftpd.conf</p>
<p>xferlog_file=/var/log/vsftpd/vsftpd.log #调整一下目录存放位置，让/var/log下稍微清晰一些</p>
<p>vi /etc/logrotate.d/vsftpd<br />
修改日志存放目录<br />
/var/log/vsftpd/vsftpd.log</p>
<p>logrotate -d /etc/logrotate.d/vsftpd 测试一下</p>
<p>没问题的话，重启ftp服务</p>
<p>/etc/init.d/vsftpd restart</p>
<p><strong>2. fail2ban</strong></p>
<p>vi /etc/fail2ban/fail2ban.conf</p>
<p>logtarget = /var/log/fail2ban.log</p>
<p>vi /etc/logrotate.d/fail2ban<br />
修改日志存放目录<br />
/var/log/fail2ban/fail2ban.log</p>
<p>logrotate -d /etc/logrotate.d/fail2ban 测试一下</p>
<p>vi /etc/fail2ban/jail.local<br />
logpath = var/log/vsftpd/vsftpd.log</p>
<p>/etc/init.d/fail2ban restart</p>
<p><strong>3. NGINX</strong></p>
<p>编辑 /etc/logrotate.d/nginx</p>
<p>/var/log/nginx/*.log {<br />
daily<br />
missingok<br />
rotate 7<br />
compress<br />
delaycompress<br />
notifempty<br />
create 640 www-data www-data<br />
dateext<br />
sharedscripts<br />
prerotate<br />
sleep 59<br />
endscript<br />
postrotate<br />
if [ -f /var/run/nginx.pid ]; then<br />
kill -USR1 `cat /var/run/nginx.pid`<br />
fi<br />
endscript<br />
}</p>
<p>含义是：</p>
<p>每天执行，日志文件不存在不报错，最多保留365天，用GZip压缩, 延后压缩，无文件不压缩， 文件后加时间戳。</p>
<p>logrotate -d /etc/logrotate.d/nginx 测试一下</p>
<p>没问题的话，重启服务: /etc/init.d/nginx reload</p>
<p><strong>4. 可选：调整logrotate的运行时间</strong></p>
<p>编辑/etc/cron.daily, 把其中的logrotate的时间提前到5：27或更早一点，以便CPU时间可以合理分配</p>
<p>参考文章：<br />
1. <a href="http://www.jefflei.com/post/375.html">Nginx日志切割脚本</a><br />
2. <a href="http://bluedata.org/2009/09/04/nginx-logrotate/">nginx 使用 logrotate 回滚日志</a><br />
3. <a href="http://blog.csdn.net/pwlazy/archive/2008/10/13/3069671.aspx">nginx日志管理</a></p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:399px;width:1px;height:1px;">/var/log/nginx/*.log {<br />
daily<br />
missingok<br />
rotate 7<br />
compress<br />
delaycompress<br />
notifempty<br />
create 640 www-data adm<br />
sharedscripts<br />
prerotate<br />
sleep 59<br />
endscript<br />
postrotate<br />
if [ -f /var/run/nginx.pid ]; then<br />
kill -USR1 `cat /var/run/nginx.pid`<br />
fi<br />
endscript<br />
}</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Ubuntu 8.04环境下服务器常用维护命令 NGINX,PHP-FPM, APC,Memcached, MYSQL,VSFTP,Iptables,Fail2Ban]]></title>
<link>http://freshventure.wordpress.com/2009/10/19/ubuntu-8-04%e7%8e%af%e5%a2%83%e4%b8%8b%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%b8%b8%e7%94%a8%e7%bb%b4%e6%8a%a4%e5%91%bd%e4%bb%a4-nginxphp-fpm-apcmemcached-mysqlvsftpiptablesfail2ban/</link>
<pubDate>Mon, 19 Oct 2009 03:13:21 +0000</pubDate>
<dc:creator>freshventure</dc:creator>
<guid>http://freshventure.wordpress.com/2009/10/19/ubuntu-8-04%e7%8e%af%e5%a2%83%e4%b8%8b%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%b8%b8%e7%94%a8%e7%bb%b4%e6%8a%a4%e5%91%bd%e4%bb%a4-nginxphp-fpm-apcmemcached-mysqlvsftpiptablesfail2ban/</guid>
<description><![CDATA[1. top命令查看使用CPU最高的进程，还有进阶版htop。通常需要安装：sudo apt-get install htop 2. 更改php.ini和nginx.conf配置文件后，用/etc/i]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>1. top命令查看使用CPU最高的进程，还有进阶版htop。通常需要安装：sudo apt-get install htop</p>
<p>2. 更改php.ini和nginx.conf配置文件后，用<strong>/etc/init.d/fp-php reload </strong>和<strong>/etc/init.d/nginx reload</strong>重启服务。<br />
只要没有添加、更改模块，不用restart参数。重启更平滑</p>
<p>3. iptables -L -v 可以查看当前防火墙的详细配置， iptables -L可以看个简化版的</p>
<p>4. fail2ban-client status ssh 或者fail2ban-client status vsftpd可以查看IP封禁状况</p>
<p>5. netstat -tap 可以查看当前开启的端口，如果memcache成功启动的话，就可以在这里看到</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Mono Asp.Net MVC and Nginx]]></title>
<link>http://bloggingmath.wordpress.com/2009/10/17/mono-asp-net-mvc-and-nginx/</link>
<pubDate>Sat, 17 Oct 2009 10:11:16 +0000</pubDate>
<dc:creator>Bryan Bell</dc:creator>
<guid>http://bloggingmath.wordpress.com/2009/10/17/mono-asp-net-mvc-and-nginx/</guid>
<description><![CDATA[I&#8217;ve been using Mono ASP.Net for a while with Nginx as the server. I recently started playing ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I&#8217;ve been using Mono ASP.Net for a while with Nginx as the server. I recently started playing around with ASP.Net MVC and discovered that it doesn&#8217;t play nice when using Nginx as the server. To make ASP.Net work with Mono and Nginx you need to download the Mono source from <a href="http://ftp.novell.com/pub/mono/sources-stable/">here</a>. And then modify the file mcs/class/System.Web.Routing/System.Web.Routing/Route.cs<br />
in particular comment out the following lines in the GetRouteData function<br />
<code><br />
if (pathInfo != String.Empty)<br />
    throw new NotImplementedException();</code></p>
<p>If you comment out the above two lines your MVC website should work just fine when hosting it using Mono and Nginx. I don&#8217;t know if there are any negative consequences for commenting out the above two lines but I have not encountered any.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Nginx Windows Service]]></title>
<link>http://misterdai.wordpress.com/2009/10/16/nginx-windows-service/</link>
<pubDate>Fri, 16 Oct 2009 13:09:42 +0000</pubDate>
<dc:creator>misterdai</dc:creator>
<guid>http://misterdai.wordpress.com/2009/10/16/nginx-windows-service/</guid>
<description><![CDATA[Introduction Nginx is a web server. It&#8217;s an alternative to the big beasts of Apache/IIS and is]]></description>
<content:encoded><![CDATA[Introduction Nginx is a web server. It&#8217;s an alternative to the big beasts of Apache/IIS and is]]></content:encoded>
</item>

</channel>
</rss>
