系統環境:RHEL5 [ 2.6.18-8.el5xen ]
軟件環境:
nginx-0.7.17
lighttpd-1.4.20.tar.gz
pcre-6.6-1.1
pcre-devel-6.6-1.1
php-5.1.6-5.el5
參考下載地址:
http://sysoev.ru/nginx/nginx-0.7.17.tar.gz (最新穩定版為0.6.32)
http://www.lighttpd.net/download/lighttpd-1.4.20.tar.gz
##########################################################################
一、安裝支持軟件
1、安裝lighttpd以提取spawn-fcgi (如果站點不包含php頁面,可以不安裝spaw-fcgi、PHP)
shell> tar zxvf lighttpd-1.4.20.tar.gz
shell> cd lighttpd-1.4.20/
shell> ./configure && make
shell> cp -p src/spawn-fcgi /usr/sbin/spawn-fcgi
2、安裝pcre和php(以下軟件)
可使用RHEL5自帶的rpm包安裝,過程略。
二、安裝nginx
shell> tar zxvf nginx-0.7.17.tar.gz
shell> cd nginx-0.7.17/
shell> ./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module
shell> make && make install
shell> ln -sf /opt/nginx/sbin/nginx /usr/sbin/
三、nginx運行控制
1、檢查配置文件有無語法錯誤
shell> nginx -t
2、啟動(不帶任何參數直接運行即可)
shell> nginx
3、重新加載nginx配置
shell> killall -s HUP nginx #//或者 killall -1 nginx
4、處理完當前請求后退出nginx
shell> killall -s QUIT nginx #//或者 killall -3 nginx
四、nginx配置用例
1、常規配置
shell> vi /opt/nginx/conf/nginx.conf
worker_processes 1; #//工作進程數
events {
use epoll; #//增加該事件提高I/O性能
work_connections 4096;
}
http {
include mime.types;
default_types application/octet-stream;
sendfile on;
tcp_nodelay on
keepalive_timeout 60;
server {
listen 80; #//設置監聽端口,注意不要和Apache等其他Web程序沖突
server_name www.linux.org; #//指定使用的主機名
charset utf-8; #//指定站點文件的默認編碼
location / {
root html; #//設置網站根目錄
index index.html index.html;
}
error_page 500 502 503 504 /50x.html
location = /50x.html {
root html;
}
}
}
2、添加狀態監控
shell> vi /opt/nginx/conf/nginx.conf #//增加以下內容
location ~ ^/NginxStatus/ {
stub_status on;
access_log off;
}
shell> killall -1 nginx
#//使用瀏覽器訪問 http://nginx_server_ip/NginxStatus/ 即可看到狀態統計頁面。(三個數字分別表示:總共處理連接數、成功創建的握手次數、總共處理的請求數)
3、通過FastCGI方式支持PHP語言
1)啟動FastCGI服務(用php-cgi做實際處理php頁面的程序,用spawn-fcgi是便于同時開啟多個php-cgi進程——“-C”選項控制子進程數)
shell>/usr/sbin/spawn-fcgi -a 127.0.0.1 -p 9000 -f /usr/bin/php-cgi -C 10
2)修改/opt/nginx/conf/nginx.conf配置文件,添加以下內容:
location ~ /.php$ {
root html;
新聞熱點
疑難解答