您现在的位置是:首页 > 文章详情

window + nginx-rtmp + php-cgi 服务器搭建

日期:2016-10-13点击:469

【大咖・来了 第7期】10月24日晚8点观看《智能导购对话机器人实践》

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++打开来。找到

扩展目录(去掉注释)

 
  1. ;extension_dir = "ext" 

mysql 扩展(去掉注释)

 
  1. ;extension=php_mysql.dll 
  2. ;extension=php_mysqli.dll  

前面指定了php的ext路径后,只要把需要的扩展包前面所对应的“;”去掉,就可以了。这里打开php_mysql.dll和php_mysqli.dll,让php支持mysql。当然不要忘掉很重要的一步就是,把php5目录下的libmysql.dll文件复制到C:Windows目录下,也可以在系统变量里面指定路径,当然这里我选择了更为方便的方法^_^。

到这里,php已经可以支持mysql了。

接下来我们来配置php,让php能够与nginx结合。找到(去掉注释)

 
  1. ;cgi.fix_pathinfo=1 

这一步非常重要,这里是php的CGI的设置。

2)nginx的安装与配置。

把下载好的nginx-1.0.4的包同样解压到D盘的wnmp目录下,并重命名为nginx。接下来,我们来配置nginx,让它能够和php协同工作。进入nginx的conf目录,打开nginx的配置文件nginx.conf,找到

 
  1. worker_processes  1; 
  2.  
  3. error_log  logs/error.log debug; 
  4.  
  5. events { 
  6.     worker_connections  1024; 
  7.  
  8. rtmp { 
  9.     server { 
  10.         listen 1936; 
  11.  
  12.         application live { 
  13.             live on
  14.             pull rtmp://live.hkstv.hk.lxdns.com/live/hks live=1 name=1; 
  15.         } 
  16.     } 
  17.  
  18. http { 
  19.      
  20.     access_log logs/access.http.log; 
  21.     server_tokens off
  22.     default_type application/octet-stream; 
  23.     client_max_body_size 10G; 
  24.     sendfile on 

当前目录创建 other.conf

 
  1. server { 
  2.         listen      7777; 
  3.         server_name live_stream; 
  4.         root www; 
  5.          
  6.         index index.php; 
  7.  
  8.         location / { 
  9.             if (!-e $request_filename) { 
  10.                 rewrite ^(.*)$ /index.php?s=/$1 last; # rewrite mode 
  11.                 #rewrite ^(.*)$ /index.php/$1 last; # pathinfo mode 
  12.             } 
  13.         } 
  14.          
  15.         location ~ \.php$ {             
  16.             fastcgi_hide_header X-Powered-By
  17.             fastcgi_pass 127.0.0.1:9000; 
  18.             fastcgi_split_path_info ^(.+\.php)(.*)$; 
  19.             fastcgi_param PATH_INFO $fastcgi_path_info; 
  20.             fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 
  21.             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
  22.             include fastcgi_params; 
  23.             fastcgi_connect_timeout 300; 
  24.             fastcgi_send_timeout 300; 
  25.             fastcgi_read_timeout 300; 
  26.  
  27.         } 
  28.     }  

保存配置文件,就可以了。

nginx+php的环境就初步配置好了,来跑跑看。我们可以输入命令

 
  1. X:\wnp\php\php-cgi.exe -b 127.0.0.1:900 -c X:\wnp\php\php.ini 

双击nginx.exe

完成!!!

3.批处理脚本控制开关服务器

1.start.cmd

 
  1. @echo off 
  2. REM Windows 下无效 
  3. REM set PHP_FCGI_CHILDREN=5 
  4.  
  5. REM 每个进程处理的***请求数,或设置为 Windows 环境变量 
  6. set PHP_FCGI_MAX_REQUESTS=1000 
  7.   
  8. echo Starting PHP FastCGI... 
  9. RunHiddenConsole D:/wnmp/php5/php-cgi.exe -b 127.0.0.1:9000 -c D:/wnmp/php5/php.ini 
  10.   
  11. echo Starting nginx... 
  12. RunHiddenConsole D:/wnmp/nginx/nginx.exe -p D:/wnmp/nginx  

2.end.cmd

 
  1. @echo off 
  2. echo Stopping nginx...   
  3. taskkill /F /IM nginx.exe > nul 
  4. echo Stopping PHP FastCGI... 
  5. taskkill /F /IM php-cgi.exe > nul 
  6. exit  

4.填坑

php 文件无法接收参数,$_GET,$_POST,$_REQUEST,为空

解决办法:other.conf 文件中, “include fast_params” nginx官网示例

 
  1. location ~ \.php$ {             
  2.                 fastcgi_hide_header X-Powered-By
  3.                 fastcgi_pass 127.0.0.1:9000; 
  4.                 fastcgi_split_path_info ^(.+\.php)(.*)$; 
  5.                 fastcgi_param PATH_INFO $fastcgi_path_info; 
  6.                 fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 
  7.                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
  8.                  
  9.                 include fastcgi_params;  
  10.                  
  11.                 fastcgi_connect_timeout 300; 
  12.                 fastcgi_send_timeout 300; 
  13.                 fastcgi_read_timeout 300; 
  14.      
  15.             }  

5.参考文献

1.windows下配置nginx+php环境

原文链接:http://server.51cto.com/News-518800.htm
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章