14
Jan
08

nginx + PHP + FastCGI:輕型網頁伺服器

nginx是一個非常輕型的網頁伺服器,而且也有在大型網站上使用。

安裝PHP和FastCGI

# aptitude install php5-cgi libfcgi0c2

下載FastCGI的init script

# cd /etc/init.d
# wget -O php-fastcgi http://daufu.files.wordpress.com/2008/01/php-fastcgiinit.txt

修改檔案屬性

# chmod +x php-fastcgi

下載FastCGI init script的設定檔

# cd /etc/default
# wget -O php-fastcgi http://daufu.files.wordpress.com/2008/01/php-fastcgidefault.txt

如果執行後沒有問題就把init script安裝到系統

# update-rc.d php-fastcgi defaults 19 21

  1. 啟動php-fastcgi
    # /etc/init.d/php-fastcgi start
  2. 可用ps aux指令檢查php-fastcgi有沒有執行

安裝nginx的必要套件〈以下的套件足以compile所有nginx的功能〉

# aptitude install zlib1g-dev libpcre3-dev libssl-dev libgcrypt11-dev

官網下載nginx

# cd /usr/src
# wget http://sysoev.ru/nginx/nginx-0.5.35.tar.gz

解壓縮檔案

# tar zxvf nginx-0.5.35.tar.gz

Compile及安裝nginx

# cd nginx-0.5.35
# ./configure --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --user=www-data --group=www-data --with-http_ssl_module  --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module--http-client-body-temp-path=/var/cache/nginx/client_body_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --with-sha1=/usr/lib
# make
# make install
# mkdir /var/cache/nginx
# chown www-data:www-data /var/cache/nginx

安裝nginx的init script

# cd /etc/init.d
# wget -O nginx http://daufu.files.wordpress.com/2008/01/nginxinit.txt
# chmod +x nginx
# update-rc.d nginx defaults

這個init script是從Debian的套件提出的

為nginx設定FastCGI

# cd /etc/nginx
# wget -O fastcgi_params http://daufu.files.wordpress.com/2008/01/fastcgi_params.txt

修改nginx的設定檔

# nano nginx.conf

同學可參考nginx的英文wiki或我的設定檔

修改完設定檔後,nginx便要重新讀取設定檔

# kill -HUP 'cat /var/run/nginx.pid'

nginx的一個特色是重啟並不需要先關閉伺服器,所以訪客的連線是不會中斷的。而將來nginx出了新版也可以用同樣的方法升級。

參考資料:

Technorati Tags: , ,


0 Responses to “nginx + PHP + FastCGI:輕型網頁伺服器”



  1. No Comments Yet

Leave a Reply