1、首先需要準備的應用程式包。
nginx : nginx-rtmp-win32 或 nginx/windows-1.0.4 (無rtmp子產品)
php:php-5.2.16-nts-win32-vc6-x86.zip (nginx下php是以fastcgi的方式運作,是以我們下載下傳非線程安全也就是nts的php包)
runhiddenconsole: runhiddenconsole.zip(用于cmd 非阻塞運作程序)
2、安裝與配置。
1)php的安裝與配置。
直接解壓下載下傳好的php包,到d盤wnmp目錄(d:wnmp),這裡把解壓出來的檔案夾重命名成php5。進入檔案夾修改php.ini-recommended檔案為php.ini,并用editplus或者notepad++打開來。找到
擴充目錄(去掉注釋)
;extension_dir = "ext"
mysql 擴充(去掉注釋)
;extension=php_mysql.dll
;extension=php_mysqli.dll
前面指定了php的ext路徑後,隻要把需要的擴充包前面所對應的“;”去掉,就可以了。這裡打開php_mysql.dll和php_mysqli.dll,讓php支援mysql。當然不要忘掉很重要的一步就是,把php5目錄下的libmysql.dll檔案複制到c:windows目錄下,也可以在系統變量裡面指定路徑,當然這裡我選擇了更為友善的方法^_^。
到這裡,php已經可以支援mysql了。
接下來我們來配置php,讓php能夠與nginx結合。找到(去掉注釋)
;cgi.fix_pathinfo=1
這一步非常重要,這裡是php的cgi的設定。
2)nginx的安裝與配置。
把下載下傳好的nginx-1.0.4的包同樣解壓到d盤的wnmp目錄下,并重命名為nginx。接下來,我們來配置nginx,讓它能夠和php協同工作。進入nginx的conf目錄,打開nginx的配置檔案nginx.conf,找到
worker_processes 1;
error_log logs/error.log debug;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1936;
application live {
live on;
pull rtmp://live.hkstv.hk.lxdns.com/live/hks live=1 name=1;
}
}
http {
access_log logs/access.http.log;
server_tokens off;
default_type application/octet-stream;
client_max_body_size 10g;
sendfile on;
目前目錄建立 other.conf
server {
listen 7777;
server_name live_stream;
root www;
index index.php;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last; # rewrite mode
#rewrite ^(.*)$ /index.php/$1 last; # pathinfo mode
}
location ~ \.php$ {
fastcgi_hide_header x-powered-by;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param path_info $fastcgi_path_info;
fastcgi_param path_translated $document_root$fastcgi_path_info;
fastcgi_param script_filename $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
儲存配置檔案,就可以了。
nginx+php的環境就初步配置好了,來跑跑看。我們可以輸入指令
x:\wnp\php\php-cgi.exe -b 127.0.0.1:900 -c x:\wnp\php\php.ini
輕按兩下nginx.exe
完成!!!
3.批處理腳本控制開關伺服器
1.start.cmd
@echo off
rem windows 下無效
rem set php_fcgi_children=5
rem 每個程序處理的最大請求數,或設定為 windows 環境變量
set php_fcgi_max_requests=1000
echo starting php fastcgi...
runhiddenconsole d:/wnmp/php5/php-cgi.exe -b 127.0.0.1:9000 -c d:/wnmp/php5/php.ini
echo starting nginx...
runhiddenconsole d:/wnmp/nginx/nginx.exe -p d:/wnmp/nginx
2.end.cmd
echo stopping nginx...
taskkill /f /im nginx.exe > nul
echo stopping php fastcgi...
taskkill /f /im php-cgi.exe > nul
exit
4.填坑
php 檔案無法接收參數,$_get,$_post,$_request,為空
解決辦法:other.conf 檔案中, “include fast_params” nginx官網示例
location ~ \.php$ {
fastcgi_hide_header x-powered-by;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param path_info $fastcgi_path_info;
fastcgi_param path_translated $document_root$fastcgi_path_info;
fastcgi_param script_filename $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
本文作者:penguinseven
來源:51cto