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

服务器
首先需要准备的应用程序包,然后分别安装与配置php、nginx和批处理脚本控制开关服务器。

[[173425]]

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环境

责任编辑:庞桂玉 来源: segmentfault
相关推荐

2021-01-29 14:41:43

Nginx直播服务器rtmp

2021-09-10 10:07:17

Nginx虚拟主机服务器

2009-07-06 17:34:38

JSP HTTP服务器

2018-10-26 09:52:25

Nginx服务器负载均衡

2023-10-12 19:46:26

Nginx服务器

2019-04-08 08:39:47

Nginx代理服务器

2011-11-28 21:56:41

2012-09-21 10:36:54

PHPPHP搭建Web

2018-10-29 09:39:34

NginxVSFTP服务器

2010-05-12 18:04:41

IIS服务器

2016-10-19 08:36:51

2013-05-30 09:25:43

2010-05-27 16:41:38

MySQL服务器

2011-07-06 16:55:56

iPhone php Push

2018-01-30 10:49:49

Nginx服务器PHP

2013-05-06 11:04:07

2018-10-12 08:43:54

2017-03-06 09:26:56

Nginx服务器 SSL

2011-11-21 15:45:28

CGI

2019-12-24 14:42:51

Nginx服务器架构
点赞
收藏

51CTO技术栈公众号