這篇文章將為大家詳細講解有關怎么進行window + nginx-rtmp + php-cgi 服務器搭建,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
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 off 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; }5.參考文獻
1.windows下配置nginx+php環境
關于怎么進行window + nginx-rtmp + php-cgi 服務器搭建就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。