Windows搭建 Nginx PHP 开发环境

发布时间:2024-10-13 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Windows搭建 Nginx PHP 开发环境脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

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.



脚本宝典总结

以上是脚本宝典为你收集整理的Windows搭建 Nginx PHP 开发环境全部内容,希望文章能够帮你解决Windows搭建 Nginx PHP 开发环境所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。