AI教程网 - 未来以来,拥抱AI;新手入门,从AI教程网开始......

Window搭建 Nginx PHP 开发环境

PHP教程 AI君 65℃

NGINX 可以通过 FastCGI 守护进程与 Windows 上的PHP进行连接

你可以使用 php-cgi.exe -b 127.0.0.1:<端口> 启用 FastCGI

启动后,php-cgi.exe 将继续在命令提示符窗口中监听连接。

如果你要隐藏该窗口,请使用小型实用程序: RunHiddenConsole

安装Nginx

1. 根据需要下载 Nginx 下载地址: http://nginx.org/en/download.html

2. 解压下载的压缩包


这样就可以使用 CMD 进入 D:\nginx-1.10.3> 执行启动, 关闭, 重启 等操作,可以进行以下操作

nginx -s stop	快速关闭Nginx
nginx -s quit	优雅的关闭Nginx
nginx -s reload 更改配置,使用新配置启动新工作进程,正常关闭旧工作进程
nginx -s reopen 重新打开日志文件

安装PHP

1. 根据需要下载 PHP 下载地址: https://windows.php.net/

2. 解压下载的压缩包


这样就可以使用 CMD 进入 D:\php-5.6.34-Win32-VC11-x64> 开启 FastCGI 

D:\php-5.6.34-Win32-VC11-x64>php-cgi.exe -b 127.0.0.1:9000

配置nginx.conf

nginx.conf (该文件在nginx安装目录的conf里面,如我的是: D:\nginx-1.10.3\conf)

server {

        listen       80;

        server_name  localhost;

root   html;

index  index.php;


if (!-e $request_filename) {

rewrite ^(.+)$ /index.php$1 last;

}

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        

location ~* .*\.php($|/)

{

if ($request_filename ~* (.*)\.php) {

set $php_url $1;

}

if (!-e $php_url.php) {

return 403;

}

fastcgi_pass  127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi.conf;

}

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

注意:Windows 版本的 nginx 使用原生 Win32 API 实现(而不是使用 Cygwin 模拟)。现在只使用了 select() 连接处理方法,所以不要期望高性能和可扩展性,加上还有很多其他的问题,现在Windows 版本的nginx也就是一个 BETA 版本。以下是官方描述

Version of nginx for Windows uses the native Win32 API (not the Cygwin emulation layer). Only the select() connection processing method is currently used, so high performance and scalability should not be expected. Due to this and some other known issues version of nginx for Windows is considered to be a beta version.

转载请注明:www.ainoob.cn » Window搭建 Nginx PHP 开发环境

喜欢 (0)or分享 (0)