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

扩展目录(去掉注释)

;extension_dir = "ext" 
  • 1.

mysql 扩展(去掉注释)

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

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

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

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

;cgi.fix_pathinfo=1 
  • 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 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.

当前目录创建 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; 
 
        } 
    }  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.

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

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

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

双击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  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.

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  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

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; 
     
            }  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.

5.参考文献

1.windows下配置nginx+php环境

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

2021-01-29 14:41:43

Nginx直播服务器rtmp

2021-09-10 10:07:17

Nginx虚拟主机服务器

2012-09-21 10:36:54

PHPPHP搭建Web

2009-07-06 17:34:38

JSP HTTP服务器

2019-04-08 08:39:47

Nginx代理服务器

2018-10-26 09:52:25

Nginx服务器负载均衡

2023-10-12 19:46:26

Nginx服务器

2011-11-28 21:56:41

2010-05-27 16:41:38

MySQL服务器

2011-07-06 16:55:56

iPhone php Push

2010-05-12 18:04:41

IIS服务器

2013-05-30 09:25:43

2016-10-19 08:36:51

2018-10-29 09:39:34

NginxVSFTP服务器

2018-01-30 10:49:49

Nginx服务器PHP

2013-05-06 11:04:07

2017-03-06 09:26:56

Nginx服务器 SSL

2011-11-21 15:45:28

CGI

2019-09-10 15:22:17

Nginx服务器架构

2019-12-24 14:42:51

Nginx服务器架构
点赞
收藏

51CTO技术栈公众号