系統(tǒng)環(huán)境:RHEL5 [ 2.6.18-8.el5xen ]
軟件環(huán)境: 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 (最新穩(wěn)定版為0.6.32) http://www.lighttpd.net/download/lighttpd-1.4.20.tar.gz ########################################################################## 一、安裝支持軟件 1、安裝lighttpd以提取spawn-fcgi (如果站點(diǎn)不包含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運(yùn)行控制 1、檢查配置文件有無語法錯(cuò)誤 shell> nginx -t 2、啟動(dòng)(不帶任何參數(shù)直接運(yùn)行即可) shell> nginx 3、重新加載nginx配置 shell> killall -s HUP nginx #//或者 killall -1 nginx 4、處理完當(dāng)前請求后退出nginx shell> killall -s QUIT nginx #//或者 killall -3 nginx 四、nginx配置用例 1、常規(guī)配置 shell> vi /opt/nginx/conf/nginx.conf worker_processes 1; #//工作進(jìn)程數(shù) 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; #//設(shè)置監(jiān)聽端口,注意不要和Apache等其他Web程序沖突 server_name www.linux.org; #//指定使用的主機(jī)名 charset utf-8; #//指定站點(diǎn)文件的默認(rèn)編碼 location / { root html; #//設(shè)置網(wǎng)站根目錄 index index.html index.html; } error_page 500 502 503 504 /50x.html location = /50x.html { root html; } } } 2、添加狀態(tài)監(jiān)控 shell> vi /opt/nginx/conf/nginx.conf #//增加以下內(nèi)容 location ~ ^/NginxStatus/ { stub_status on; access_log off; } shell> killall -1 nginx #//使用瀏覽器訪問 http://nginx_server_ip/NginxStatus/ 即可看到狀態(tài)統(tǒng)計(jì)頁面。(三個(gè)數(shù)字分別表示:總共處理連接數(shù)、成功創(chuàng)建的握手次數(shù)、總共處理的請求數(shù)) 3、通過FastCGI方式支持PHP語言 1)啟動(dòng)FastCGI服務(wù)(用php-cgi做實(shí)際處理php頁面的程序,用spawn-fcgi是便于同時(shí)開啟多個(gè)php-cgi進(jìn)程――“-C”選項(xiàng)控制子進(jìn)程數(shù)) 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配置文件,添加以下內(nèi)容: location ~ /.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;新聞熱點(diǎn)
疑難解答
圖片精選