Search posterous

Search all posts and users. Type a name, type a favorite song title, whatever! See what comes up.
  

More posterous blogs











More recommended blogs »

Here are posterous posts filed under nginx...

Brian says...

So if you're doing any uploads in a ruby/rails webapp and nginx, you should be using the nginx upload module. In fact it'd work with any web app running nginx, but the conf file may be a little different. So why is the upload module so awesome? Lets start off going over a typical upload process in ruby:

  • File is sent to server
  • File is buffered by ruby
  • File is available for use
However, using the upload module the process goes like this:
  • File is sent to server
  • File is buffered by c
  • File is available for use
Guess which one is faster? This will take some tweaking to your app to get it to work. You can either create a new file instance from the file path variable or try using rack-uploads. I took the former route. On our staging server I noticed a huge speed increase. I didn't measure it, but is noticeably faster, espicially for larger files. So no the grand question: How do I use it? Well here's what I added to my nginx.conf file to make it work. If you're unfamiliar with nginx, these go inside the server block. Now this may not work perfect for you if you're not using unicorn. I was banging my head against the wall for a while trying to figure out why rails couldn't recognize the request. Turns out nginx doesn't forward the host by default. You can checkout the source here http://github.com/vkholodkov/nginx-upload-module. As for version compatibility:
  • 2.0.9 is compatible with nginx 0.6.x, 0.7.52-0.7.62, 0.8.1-0.8.8
  • 2.0.10 is compatible with nginx 0.6.x, 0.7.52-0.7.62, 0.8.1-0.8.16

Lastly, here's the conf bits, enjoy!

Filed under: nginx

Brian says...

So there's a new kid on the block in the ruby server world, Unicorn. The guys over at github have a good writeup on their blog about what it is and how to user it, that also posted a god config file to monitor it. Also if you want a good explanation of why unicorn is cool, check out Ryan Tomayko's article "I like Unicorn because it's Unix". One important note on both their unicorn config and their config, the paths they have are very specific to their setup. If you're running a normal capistrano setup, you'll want to store the sockets and pids in the shared directory rather than the current. So now the only part is the front end web server. This typically tends to be nginx(pronounced engine x) or apache these days, though litespeed and lighttpd are good as well. My personal choice is nginx, installing it and getting running is pretty easier and straight forward. All that's left to do is tweak the nginx.conf file. I used a modified version of ezra's nginx.conf file. Here's the conf with my optimizations:

Note if you're not using a socket just set the server in the upstream block to 127.0.0.1:<%=@port %>

Filed under: nginx

hdknr says...

nginxで中間CA証明書を使用する

nginxには中間CA証明書を直接指定するための方法がありません。
そのため、ちょっと面倒ですが、サーバ証明書に追記する必要があります。
サーバ証明書と中間証明書が以下のような形式だとすると、

サーバ証明書

-----BEGIN CERTIFICATE-----
(サーバ証明書の内容)
-----END CERTIFICATE-----

中間CA証明書

-----BEGIN CERTIFICATE-----
(中間CA証明書の内容)
-----END CERTIFICATE-----

サーバ証明書に中間証明書を追記する形で、サーバ証明書を以下のように編集します。

-----BEGIN CERTIFICATE-----
(サーバ証明書の内容)
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
(中間CA証明書の内容)
-----END CERTIFICATE-----

Filed under: nginx

hdknr says...

hdknr@debsq:~$ sudo gem1.8 install passenger
Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
Successfully installed fastthread-1.0.7
Successfully installed passenger-2.2.5
2 gems installed
Installing ri documentation for fastthread-1.0.7...
No definition for dummy_dump
No definition for dummy_dump
No definition for rb_queue_marshal_load
No definition for rb_queue_marshal_dump
No definition for dummy_dump
No definition for dummy_dump
No definition for rb_queue_marshal_load
No definition for rb_queue_marshal_dump
Installing ri documentation for passenger-2.2.5...
Installing RDoc documentation for fastthread-1.0.7...
No definition for dummy_dump
No definition for dummy_dump
No definition for rb_queue_marshal_load
No definition for rb_queue_marshal_dump
No definition for dummy_dump
No definition for dummy_dump
No definition for rb_queue_marshal_load
No definition for rb_queue_marshal_dump
Installing RDoc documentation for passenger-2.2.5...

hdknr@debsq:~$ sudo passenger-install-nginx-module
Welcome to the Phusion Passenger Nginx module installer, v2.2.5.

This installer will guide you through the entire installation process. It
shouldn't take more than 5 minutes in total.

Here's what you can expect from the installation process:

 1. This installer will compile and install Nginx with Passenger support.
 2. You'll learn how to configure Passenger in Nginx.
 3. You'll learn how to deploy a Ruby on Rails application.

Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.

Press Enter to continue, or Ctrl-C to abort.


--------------------------------------------

Checking for required software...

 * GNU C++ compiler... found at /usr/bin/g++
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /usr/bin/rake
 * Zlib development headers... found

--------------------------------------------

Automatically download and install Nginx?

Nginx doesn't support loadable modules such as some other web servers do,
so in order to install Nginx with Passenger support, it must be recompiled.

Do you want this installer to download, compile and install Nginx for you?

 1. Yes: download, compile and install Nginx for me. (recommended)
    The easiest way to get started. A stock Nginx 0.7.61 with Passenger
    support, but with no other additional third party modules, will be
    installed for you to a directory of your choice.

 2. No: I want to customize my Nginx installation. (for advanced users)
    Choose this if you want to compile Nginx with more third party modules
    besides Passenger, or if you need to pass additional options to Nginx's
    'configure' script. This installer will  1) ask you for the location of
    the Nginx source code,  2) run the 'configure' script according to your
    instructions, and  3) run 'make install'.

Whichever you choose, if you already have an existing Nginx configuration file,
then it will be preserved.

Enter your choice (1 or 2) or press Ctrl-C to abort: 2

--------------------------------------------

PCRE (required by Nginx) not installed, downloading it...
# wget -O /tmp/pcre-7.8.tar.gz ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz
--2009-09-26 08:22:13--  ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz
           => `/tmp/pcre-7.8.tar.gz'
ftp.csx.cam.ac.uk をDNSに問いあわせています... 131.111.8.80
ftp.csx.cam.ac.uk|131.111.8.80|:21 に接続しています... 接続しました。
anonymous としてログインしています... ログインしました!
==> SYST ... 完了しました。    ==> PWD ... 完了しました。
==> TYPE I ... 完了しました。  ==> CWD /pub/software/programming/pcre ... 完了しました。
==> SIZE pcre-7.8.tar.gz ... 1168513
==> PASV ... 完了しました。    ==> RETR pcre-7.8.tar.gz ... 完了しました。
長さ: 1168513 (1.1M)

100%[==========================================================================================================>] 1,168,513    224K/s 時間 6.8s   

2009-09-26 08:22:26 (168 KB/s) - `/tmp/pcre-7.8.tar.gz' へ保存終了 [1168513]

Extracting PCRE source tarball...
# tar xzvf pcre-7.8.tar.gz
pcre-7.8/
pcre-7.8/doc/
pcre-7.8/doc/html/
pcre-7.8/doc/html/pcre.html
pcre-7.8/doc/html/pcreperform.html
pcre-7.8/doc/html/pcrepartial.html
pcre-7.8/doc/html/pcre_study.html
pcre-7.8/doc/html/pcre_get_named_substring.html
pcre-7.8/doc/html/pcreapi.html
pcre-7.8/doc/html/pcre_copy_substring.html
pcre-7.8/doc/html/pcre_maketables.html
pcre-7.8/doc/html/pcrecompat.html
pcre-7.8/doc/html/pcre_info.html
pcre-7.8/doc/html/pcre_compile2.html
pcre-7.8/doc/html/index.html
pcre-7.8/doc/html/pcre_get_stringnumber.html
pcre-7.8/doc/html/pcre_refcount.html
pcre-7.8/doc/html/pcre_get_stringtable_entries.html
pcre-7.8/doc/html/pcrecpp.html
pcre-7.8/doc/html/pcre_get_substring_list.html
pcre-7.8/doc/html/pcresyntax.html
pcre-7.8/doc/html/pcre_free_substring.html
pcre-7.8/doc/html/pcrestack.html
pcre-7.8/doc/html/pcre_fullinfo.html
pcre-7.8/doc/html/pcrecallout.html
pcre-7.8/doc/html/pcretest.html
pcre-7.8/doc/html/pcreprecompile.html
pcre-7.8/doc/html/pcrepattern.html
pcre-7.8/doc/html/pcre-config.html
pcre-7.8/doc/html/pcre_config.html
pcre-7.8/doc/html/pcre_version.html
pcre-7.8/doc/html/pcreposix.html
pcre-7.8/doc/html/pcrebuild.html
pcre-7.8/doc/html/pcre_exec.html
pcre-7.8/doc/html/pcrematching.html
pcre-7.8/doc/html/pcre_get_substring.html
pcre-7.8/doc/html/pcresample.html
pcre-7.8/doc/html/pcre_free_substring_list.html
pcre-7.8/doc/html/pcregrep.html
pcre-7.8/doc/html/pcre_copy_named_substring.html
pcre-7.8/doc/html/pcre_compile.html
pcre-7.8/doc/html/pcre_dfa_exec.html
pcre-7.8/doc/pcre_maketables.3
pcre-7.8/doc/index.html.src
pcre-7.8/doc/pcre_get_substring_list.3
pcre-7.8/doc/pcreposix.3
pcre-7.8/doc/pcrebuild.3
pcre-7.8/doc/pcregrep.txt
pcre-7.8/doc/pcreperform.3
pcre-7.8/doc/pcreapi.3
pcre-7.8/doc/pcrecpp.3
pcre-7.8/doc/pcre_get_substring.3
pcre-7.8/doc/pcre_free_substring.3
pcre-7.8/doc/pcrepattern.3
pcre-7.8/doc/pcretest.txt
pcre-7.8/doc/pcregrep.1
pcre-7.8/doc/pcre_dfa_exec.3
pcre-7.8/doc/pcre_free_substring_list.3
pcre-7.8/doc/pcre_version.3
pcre-7.8/doc/pcrecompat.3
pcre-7.8/doc/pcretest.1
pcre-7.8/doc/pcre_exec.3
pcre-7.8/doc/pcrecallout.3
pcre-7.8/doc/pcre_info.3
pcre-7.8/doc/pcre_copy_substring.3
pcre-7.8/doc/pcresyntax.3
pcre-7.8/doc/pcrestack.3
pcre-7.8/doc/pcre-config.txt
pcre-7.8/doc/pcre_study.3
pcre-7.8/doc/pcrematching.3
pcre-7.8/doc/pcre_get_named_substring.3
pcre-7.8/doc/pcre.3
pcre-7.8/doc/pcre_compile.3
pcre-7.8/doc/pcre.txt
pcre-7.8/doc/perltest.txt
pcre-7.8/doc/pcre_config.3
pcre-7.8/doc/pcre_get_stringnumber.3
pcre-7.8/doc/pcre_compile2.3
pcre-7.8/doc/pcre_get_stringtable_entries.3
pcre-7.8/doc/pcreprecompile.3
pcre-7.8/doc/pcrepartial.3
pcre-7.8/doc/pcre_copy_named_substring.3
pcre-7.8/doc/pcre_fullinfo.3
pcre-7.8/doc/pcresample.3
pcre-7.8/doc/pcre-config.1
pcre-7.8/doc/pcre_refcount.3
pcre-7.8/NEWS
pcre-7.8/pcre_maketables.c
pcre-7.8/pcreposix.c
pcre-7.8/pcreposix.h
pcre-7.8/pcre.h.in
pcre-7.8/depcomp
pcre-7.8/pcre_scanner_unittest.cc
pcre-7.8/pcre_stringpiece.h.in
pcre-7.8/pcrecpp.h
pcre-7.8/PrepareRelease
pcre-7.8/LICENCE
pcre-7.8/pcre_get.c
pcre-7.8/cmake/
pcre-7.8/cmake/FindPackageHandleStandardArgs.cmake
pcre-7.8/cmake/FindReadline.cmake
pcre-7.8/cmake/COPYING-CMAKE-SCRIPTS
pcre-7.8/aclocal.m4
pcre-7.8/pcre_printint.src
pcre-7.8/pcre_ucd.c
pcre-7.8/ucp.h
pcre-7.8/perltest.pl
pcre-7.8/README
pcre-7.8/pcrecpp.cc
pcre-7.8/pcredemo.c
pcre-7.8/makevp.bat
pcre-7.8/pcre_globals.c
pcre-7.8/ltmain.sh
pcre-7.8/configure
pcre-7.8/pcregrep.c
pcre-7.8/pcre_dfa_exec.c
pcre-7.8/CMakeLists.txt
pcre-7.8/pcre_newline.c
pcre-7.8/pcre_valid_utf8.c
pcre-7.8/configure.ac
pcre-7.8/pcre_version.c
pcre-7.8/testdata/
pcre-7.8/testdata/testoutput1
pcre-7.8/testdata/testoutput2
pcre-7.8/testdata/testoutput3
pcre-7.8/testdata/testoutput4
pcre-7.8/testdata/testoutput5
pcre-7.8/testdata/testoutput6
pcre-7.8/testdata/testoutput7
pcre-7.8/testdata/testoutput8
pcre-7.8/testdata/testoutput9
pcre-7.8/testdata/testinput10
pcre-7.8/testdata/testinput1
pcre-7.8/testdata/testinput2
pcre-7.8/testdata/testinput3
pcre-7.8/testdata/testinput4
pcre-7.8/testdata/testinput5
pcre-7.8/testdata/testinput6
pcre-7.8/testdata/testinput7
pcre-7.8/testdata/testinput8
pcre-7.8/testdata/testinput9
pcre-7.8/testdata/greplist
pcre-7.8/testdata/grepinput
pcre-7.8/testdata/testoutput10
pcre-7.8/testdata/grepinput8
pcre-7.8/testdata/grepinputv
pcre-7.8/testdata/grepinputx
pcre-7.8/testdata/grepoutput
pcre-7.8/testdata/grepoutput8
pcre-7.8/testdata/grepoutputN
pcre-7.8/testdata/wintestoutput3
pcre-7.8/testdata/wintestinput3
pcre-7.8/config.guess
pcre-7.8/pcre_try_flipped.c
pcre-7.8/install-sh
pcre-7.8/pcre_ord2utf8.c
pcre-7.8/Detrail
pcre-7.8/pcretest.c
pcre-7.8/RunGrepTest
pcre-7.8/pcre_exec.c
pcre-7.8/config.sub
pcre-7.8/missing
pcre-7.8/dftables.c
pcre-7.8/pcregexp.pas
pcre-7.8/HACKING
pcre-7.8/pcrecpp_internal.h
pcre-7.8/pcre_info.c
pcre-7.8/pcrecpp_unittest.cc
pcre-7.8/pcre_stringpiece.cc
pcre-7.8/config.h.generic
pcre-7.8/Makefile.am
pcre-7.8/Makefile.in
pcre-7.8/NON-UNIX-USE
pcre-7.8/pcre_xclass.c
pcre-7.8/RunTest.bat
pcre-7.8/pcre_study.c
pcre-7.8/pcre_internal.h
pcre-7.8/config.h.in
pcre-7.8/CleanTxt
pcre-7.8/pcre_compile.c
pcre-7.8/RunTest
pcre-7.8/pcrecpparg.h.in
pcre-7.8/makevp_c.txt
pcre-7.8/makevp_l.txt
pcre-7.8/pcre_scanner.cc
pcre-7.8/pcre_config.c
pcre-7.8/AUTHORS
pcre-7.8/pcre_tables.c
pcre-7.8/libpcrecpp.pc.in
pcre-7.8/INSTALL
pcre-7.8/libpcre.pc.in
pcre-7.8/pcre.h.generic
pcre-7.8/config-cmake.h.in
pcre-7.8/pcre_stringpiece_unittest.cc
pcre-7.8/pcre_scanner.h
pcre-7.8/ChangeLog
pcre-7.8/132html
pcre-7.8/COPYING
pcre-7.8/pcre_fullinfo.c
pcre-7.8/pcre-config.in
pcre-7.8/pcre_chartables.c.dist
pcre-7.8/pcre_refcount.c

--------------------------------------------

Where is your Nginx source code located?
Please specify the directory: /home/hdknr/nginx-0.7.62

--------------------------------------------

Where do you want to install Nginx to?

Please specify a prefix directory [/opt/nginx]:

--------------------------------------------

Extra Nginx configure options

If you want to pass extra arguments to the Nginx 'configure' script, then
please specify them. If not, then specify nothing and press Enter.

If you specify nothing then the 'configure' script will be run as follows:

  ./configure --prefix='/opt/nginx' --with-pcre='/tmp/pcre-7.8' --add-module='/usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/ext/nginx'

Extra arguments to pass to configure script: --with-md5=/usr/lib --with-sha1=/usr/lib --with-http_ssl_module

--------------------------------------------

Confirm configure flags

The Nginx configure script will be run as follows:

  ./configure --prefix='/opt/nginx' --with-pcre='/tmp/pcre-7.8' --add-module='/usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/ext/nginx' --with-md5=/usr/lib --with-sha1=/usr/lib --with-http_ssl_module

Is this what you want? (yes/no) [default=yes]:
--------------------------------------------

Compiling Passenger support files...
# /usr/bin/ruby1.8 -S /usr/bin/rake clean nginx
(in /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5)
rm -rf ext/apache2/libboost_oxt.a ext/apache2/libboost_oxt
rm -rf ext/apache2/libpassenger_common.a ext/apache2/ApplicationPoolServerExecutable ext/apache2/libpassenger_common
rm -rf ext/apache2/Configuration.o ext/apache2/Bucket.o ext/apache2/Hooks.o ext/apache2/mod_passenger.o ext/apache2/mod_passenger.so
rm -rf ext/nginx/libboost_oxt.a ext/nginx/libboost_oxt
rm -rf ext/nginx/libpassenger_common.a ext/nginx/libpassenger_common
rm -rf ext/nginx/HelperServer
rm -rf test/libboost_oxt.a test/libboost_oxt
rm -rf test/libpassenger_common.a test/ApplicationPoolServerExecutable test/libpassenger_common
rm -rf test/oxt/oxt_test_main test/oxt/*.o test/CxxTests test/*.o
rm -r pkg
cd ext/phusion_passenger && make clean
rm -f ext/phusion_passenger/Makefile
mkdir -p ext/nginx/libboost_oxt/boost
g++ -Iext  -D_REENTRANT -I/usr/local/include -Wall -g -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -o ext/nginx/libboost_oxt/boost/thread.o -c ext/boost/src/pthread/thread.cpp
g++ -Iext  -D_REENTRANT -I/usr/local/include -Wall -g -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -o ext/nginx/libboost_oxt/boost/once.o -c ext/boost/src/pthread/once.cpp
g++ -Iext  -D_REENTRANT -I/usr/local/include -Wall -g -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -o ext/nginx/libboost_oxt/boost/exceptions.o -c ext/boost/src/pthread/exceptions.cpp
mkdir -p ext/nginx/libboost_oxt/oxt
g++ -Iext  -D_REENTRANT -I/usr/local/include -Wall -g -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -o ext/nginx/libboost_oxt/oxt/tracable_exception.o -c ext/oxt/tracable_exception.cpp
g++ -Iext  -D_REENTRANT -I/usr/local/include -Wall -g -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -o ext/nginx/libboost_oxt/oxt/thread.o -c ext/oxt/thread.cpp
g++ -Iext  -D_REENTRANT -I/usr/local/include -Wall -g -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -o ext/nginx/libboost_oxt/oxt/backtrace.o -c ext/oxt/backtrace.cpp
g++ -Iext  -D_REENTRANT -I/usr/local/include -Wall -g -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -o ext/nginx/libboost_oxt/oxt/system_calls.o -c ext/oxt/system_calls.cpp
mkdir -p ext/nginx/libboost_oxt/boost ext/nginx/libboost_oxt/oxt
rm -rf ext/nginx/libboost_oxt.a
ar cru ext/nginx/libboost_oxt.a ext/nginx/libboost_oxt/boost/*.o ext/nginx/libboost_oxt/oxt/*.o
ranlib ext/nginx/libboost_oxt.a
mkdir -p ext/nginx/libpassenger_common
g++ -Iext -Iext/common  -D_REENTRANT -I/usr/local/include -Wall -g -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -o ext/nginx/libpassenger_common/Utils.o -c ext/common/Utils.cpp
g++ -Iext -Iext/common  -D_REENTRANT -I/usr/local/include -Wall -g -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -o ext/nginx/libpassenger_common/Logging.o -c ext/common/Logging.cpp
g++ -Iext -Iext/common  -D_REENTRANT -I/usr/local/include -Wall -g -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -o ext/nginx/libpassenger_common/SystemTime.o -c ext/common/SystemTime.cpp
g++ -Iext -Iext/common  -D_REENTRANT -I/usr/local/include -Wall -g -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -o ext/nginx/libpassenger_common/CachedFileStat.o -c ext/common/CachedFileStat.cpp
g++ -Iext -Iext/common  -D_REENTRANT -I/usr/local/include -Wall -g -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -o ext/nginx/libpassenger_common/Base64.o -c ext/common/Base64.cpp
mkdir -p ext/nginx/libpassenger_common
rm -rf ext/nginx/libpassenger_common.a
ar cru ext/nginx/libpassenger_common.a ext/nginx/libpassenger_common/*.o
ranlib ext/nginx/libpassenger_common.a
g++ ext/nginx/HelperServer.cpp -o ext/nginx/HelperServer -Iext -Iext/common -D_REENTRANT -I/usr/local/include -Wall -g -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS  ext/nginx/libpassenger_common.a ext/nginx/libboost_oxt.a -lpthread

......

adding module in /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/ext/nginx
 + ngx_http_passenger_module was configured
checking for OpenSSL library ... not found

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

--------------------------------------------

It looks like something went wrong

Please read our Users guide for troubleshooting tips:

   /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/doc/Users guide Nginx.html

If that doesn't help, please use our support facilities at:

   http://www.modrails.com/

We'll do our best to help you.

hdknr@debsq:~$ sudo  aptitude install libpcre3-dev zlib1g-dev
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
タスクの記述を読み込んでいます... 完了       
以下の新規パッケージがインストールされます:
  libpcre3-dev libpcrecpp0{a}
更新: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。
356kB のアーカイブを取得する必要があります。展開後に 844kB のディスク領域が新たに消費されます。
先に進みますか? [Y/n/?] y
拡張状態情報を書き込んでいます... 完了
取得:1 http://ftp.jp.debian.org squeeze/main libpcrecpp0 7.8-2+b1 [97.8kB]
取得:2 http://ftp.jp.debian.org squeeze/main libpcre3-dev 7.8-2+b1 [258kB]
356kB を 1s 秒でダウンロードしました (190kB/s)
未選択パッケージ libpcrecpp0 を選択しています。
(データベースを読み込んでいます ... 現在 31381 個のファイルとディレクトリがインストールされています。)
(.../libpcrecpp0_7.8-2+b1_i386.deb から) libpcrecpp0 を展開しています...
未選択パッケージ libpcre3-dev を選択しています。
(.../libpcre3-dev_7.8-2+b1_i386.deb から) libpcre3-dev を展開しています...
man-db のトリガを処理しています ...
libpcrecpp0 (7.8-2+b1) を設定しています ...
libpcre3-dev (7.8-2+b1) を設定しています ...
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
拡張状態情報を書き込んでいます... 完了       
タスクの記述を読み込んでいます... 完了 

hdknr@debsq:~$ sudo aptitude install libssl-dev -y
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
タスクの記述を読み込んでいます... 完了       
以下の新規パッケージがインストールされます:
  libssl-dev
更新: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
2,137kB のアーカイブを取得する必要があります。展開後に 5,980kB のディスク領域が新たに消費されます。
拡張状態情報を書き込んでいます... 完了
取得:1 http://ftp.jp.debian.org squeeze/main libssl-dev 0.9.8k-5 [2,137kB]
2,137kB を 24s 秒でダウンロードしました (86.3kB/s)                                     
未選択パッケージ libssl-dev を選択しています。
(データベースを読み込んでいます ... 現在 31632 個のファイルとディレクトリがインストールされています。)
(.../libssl-dev_0.9.8k-5_i386.deb から) libssl-dev を展開しています...
man-db のトリガを処理しています ...
libssl-dev (0.9.8k-5) を設定しています ...
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
拡張状態情報を書き込んでいます... 完了       
タスクの記述を読み込んでいます... 完了 

もう一回。。。。

hdknr@debsq:~$ sudo passenger-install-nginx-module

--------------------------------------------

Nginx with Passenger support was successfully installed.

The Nginx configuration file (/usr/local/nginx/conf/nginx.conf)
must contain the correct configuration options in order for Phusion Passenger
to function correctly.

This installer has already modified the configuration file for you! The
following configuration snippet was inserted:

  http {
      ...
      passenger_root /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5;
      passenger_ruby /usr/bin/ruby1.8;
      ...
  }

After you start Nginx, you are ready to deploy any number of Ruby on Rails
applications on Nginx.

Press ENTER to continue.

--------------------------------------------

Deploying a Ruby on Rails application: an example

Suppose you have a Ruby on Rails application in /somewhere. Add a server block
to your Nginx configuration file, set its root to /somewhere/public, and set
'passenger_enabled on', like this:

   server {
      listen 80;
      server_name www.yourhost.com;
      root /somewhere/public;   # <--- be sure to point to 'public'!
      passenger_enabled on;
   }

And that's it! You may also want to check the Users Guide for security and
optimization tips and other useful information:

  /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/doc/Users guide Nginx.html

Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
http://www.modrails.com/

Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.


hdknr@debsq:~$ more /usr/local/nginx/conf/nginx.conf

http {
    passenger_root /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5;
    passenger_ruby /usr/bin/ruby1.8;

    server {
    root /home/hdknr/tmp/pgr/public;    #passenger:rails "pgr" app
    passenger_enabled on;            #passenger:on

hdknr@debsq:~$ sudo /usr/local/nginx/sbin/nginx

hdknr@debsq:~$ sudo lsof -i:80
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   7368   root    6u  IPv4  11793      0t0  TCP *:www (LISTEN)
nginx   7369 nobody    6u  IPv4  11793      0t0  TCP *:www (LISTEN)


hdknr@debsq:~$ curl -I http://localhost/
HTTP/1.1 200 OK
Server: nginx/0.7.62
Date: Sat, 26 Sep 2009 02:31:23 GMT
Content-Type: text/html
Content-Length: 7466
Last-Modified: Sat, 26 Sep 2009 02:21:43 GMT
Connection: keep-alive
Accept-Ranges: bytes

Filed under: nginx

月日长弓 says...

1,查看apache进程:
ps aux | grep httpd | grep -v grep | wc -l

2,查看80端口的tcp连接:
netstat -tan | grep "ESTABLISHED" | grep ":80" | wc -l

3,通过日志查看当天ip连接数,过滤重复:

cat access_log | grep "24/Jul/2007" | awk '{print $2}' | sort | uniq -c | sort -nr

4,当天ip连接数最高的ip都在干些什么(原来是蜘蛛):
cat access_log | grep "24/Jul/2007:00" | grep "61.135.166.230" | awk '{print $8}' | sort | uniq -c | sort -nr | head -n 10

5,当天访问页面排前10的url:

cat access_log | grep "24/Jul/2007:00" | awk '{print $8}' | sort | uniq -c | sort -nr | head -n 10

6,用tcpdump嗅探80端口的访问看看谁最高
tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr
接着从日志里查看该ip在干嘛:
cat access_log | grep 220.181.38.183| awk '{print $1"\t"$8}' | sort | uniq -c | sort -nr | less


7,查看某一时间段的ip连接数:
grep "2006:0[7-8]" www20060723.log | awk '{print $2}' | sort | uniq -c| sort -nr | wc -l

Filed under: nginx

月日长弓 says...

Check out this website I found at limylau.blog.51cto.com

1.确定Centos系统中是否安装如下软件包:
Apache
GCC compiler
GD development libraries
2.如果没有安装,则按如下方式进行安装:
yum -y install httpd
yum -y install gcc
yum -y install glibc glibc-common
yum -y install gd gd-devel
3.创建一个nagios user并为其设置password
useradd nagios
passwd nagios
4.创建用户组并将nagios user和apache user加入到用户组中
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache
5.下载nagios软件包及nagios插件
wget [url]http://osdn.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.6.tar.gz[/url]
wget [url]http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz[/url]
6.编译安装nagios
tar xzf nagios-3.0.6.tar.gz
cd nagios-3.0.6
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
7.配置web接口
make install-webconf
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagios
重启apache服务器,让刚才的配置生效。
8.安装nagios插件
tar xzf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --with-nagios-user=nagios --with-nagios group=nagios
make
make install
9.把nagios服务增加到服务清单中并设置开机自启动
chkconfig --add nagios
chkconfig nagios on
10.检查nagios服务器是否存在配置错误。
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
若没有错误信息就启动nagios服务器
service nagios start
11.在ie中输入http://“nagios server ipaddress”/nagios/,测试nagios服务器是否已经能正确安装。
安装到此完成,之后做troubleshooting.
-----------------------------

Filed under: nginx

hdknr says...

We've just asked Nginx to listen to fcgi on port 9000. So we have to start now the fcgi process. I've chosen to use spawn-fcgi and to make my own init script of it (so the process will start after reboot). To have spawn-fcgi you have to get lighttpd configured but without the need to install it. Let's grab the latest version:

 wget http://www.lighttpd.net/download/lighttpd-1.4.18.tar.bz2

 tar -xvjf lighttpd-1.4.18.tar.bz2 

cd lighttpd-1.4.18

 ./configure

 make

 cp src/spawn-fcgi /usr/bin/spawn-fcgi

Note that we did not type make install so lighttpd is not running!

Filed under: nginx

ssk says...

> $ cat /etc/nginx/sites-available/default
> # You may add here your
> # server {
> #       ...
> # }
> # statements for each of your virtual hosts
>
> server {
>         listen   80;
>         server_name  localhost;
>
>         access_log  /var/log/nginx/localhost.access.log;
>
> #       location / {
> #               root   /var/www/nginx-default;
> #               index  index.html index.htm;
> #       }
>
>         location /doc {
>                 root   /usr/share;
>                 autoindex on;
>                 allow 127.0.0.1;
>                 deny all;
>         }
>
>         location /images {
>                 root   /usr/share;
>                 autoindex on;
>         }
>
>         #error_page  404  /404.html;
>
>         # redirect server error pages to the static page /50x.html
>         #
>         error_page   500 502 503 504  /50x.html;
>         location = /50x.html {
>                 root   /var/www/nginx-default;
>         }
>
>         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
>         #
>         #location ~ \.php$ {
>                 #proxy_pass   http://127.0.0.1;
>         #}
>
>         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
>         #
>         #location ~ \.php$ {
>                 #fastcgi_pass   127.0.0.1:9000;
>                 #fastcgi_index  index.php;
>                 #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
>                 #includefastcgi_params;
>         #}
>
>         # deny access to .htaccess files, if Apache's document root
>         # concurs with nginx's one
>         #
>         #location ~ /\.ht {
>                 #deny  all;
>         #}
>
>         location / {
>                 proxy_pass http://127.0.0.1:8000;
>                 proxy_redirect     off;
>                 proxy_set_header   Host             $host;
>                 proxy_set_header   X-Real-IP        $remote_addr;
>                 proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
>
>         }
> }
>
>
> # another virtual host using mix of IP-, name-, and port-based configuration
> #
> #server {
> #listen   8000;
> #listen   somename:8080;
> #server_name  somename  alias  another.alias;
>
> #location / {
> #root   html;
> #index  index.html index.htm;
> #}
> #}
>
>
> # HTTPS server
> #
> #server {
> #listen   443;
> #server_name  localhost;
>
> #ssl  on;
> #ssl_certificate  cert.pem;
> #ssl_certificate_key  cert.key;
>
> #ssl_session_timeout  5m;
>
> #ssl_protocols  SSLv2 SSLv3 TLSv1;
> #ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
> #ssl_prefer_server_ciphers   on;
>
> #location / {
> #root   html;
> #index  index.html index.htm;
> #}
> #}

Filed under: nginx

月日长弓 says...

Check out this website I found at timyang.net

如何写nginx module

对于一些访问量特别大,业务逻辑也相对简单的Web调用来说,通过一个nginx module来实现是一种比较好的优化方法。实现一个nginx module实际上比较简单。

1. nginx 配置添加

./configure --add-module=/path/to/module1/source

2. 添加 /path/to/module1/source/config 文件,内容

ngx_addon_name=ngx_http_hello_module
HTTP_MODULES="$HTTP_MODULES ngx_http_hello_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_hello_module.c"
CORE_LIBS="$CORE_LIBS -lfoo"

最后一行如果没有使用其他library, 可以去掉

3. 源代码 /path/to/module1/source/ngx_http_hello_module.c, 主要的业务逻辑在make_http_get_body 中完善。典型的hello world源代码如下

Filed under: nginx

月日长弓 says...

# /usr/local/awstats/tools/awstats_buildstaticpages.pl -update  \
-config=www.moabc.net -lang=cn -dir=/data/admin_web/awstats  \
-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl


上述命令的具体意思如下:

    * /usr/local/awstats/tools/awstats_buildstaticpages.pl Awstats 静态页面生成工具
    * -update -config=www.moabc.net 更新配置项
    * -lang=cn 语言为中文
    * -dir=/data/admin_web/awstats 统计结果输出目录
    * -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl Awstats 日志更新程序路径。

Filed under: nginx