A. nginx 与 php 协同工做原理:php
首先,nginx 的转发端口 与 php 的监听端口需一致。而后 nginx 将 http 请求映射成 fastcgi 请求,经过对应端口向 php 发送。php 获取并处理请求后,经过对应端口反馈给 nginx 处理后的数据,nginx 将数据输出到浏览器,一次 http 请求结束。html
B. Nginx 变量访问控制:nginx
http { var1; # 变量1可以被 http 下全部的 server | location 块识别 server { var2; # 变量2可以被全部的 location 块识别 location { var3; # 变量3只可以被当前的 localtion 块识别 } location { } } server { var2; location { var3; } location { } } }
C. nginx.conf 配置文件:浏览器
server { # 监听端口 listen 80; # 指明具体的监听端口 listen 127.0.0.1:80; server_name fuckyou.com; charset utf-8; # 注意下面这个 root ! root D:/Website/FrontToolLib; # 目录访问设置 location / { # 目录访问目标文件设置 index index.php index.html index.htm; # 是否容许访问目录 autoindex on; } # PHP 文件访问设置 location ~ \.php$ { # PHP fastcgi 程序监听端口 fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; # 注意 $document_root fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
D. 注意点测试
E. 调试
nginx 经常使用命令,注意了:这些命令须要先切换到nginx目录下才能使用!即便你将其添加到了系统路径!spa
启动: start nginx 关闭: nginx -s stop 重载配置文件:nginx -s reload
php-cgi 经常使用命令:调试
php-cgi -b 127.0.0.1:9000 -c php.ini -b:代表监听的端口(ip + port实际上就是为了惟一肯定监听的端口号用的) -c:代表加载的配置文件
启动 nginx:code
启动 php(启动后不能关掉 cmd 窗口,不然 php 会被关闭):server
测试:htm
E. 结语以上内容属三个晚上研究得出,看仔细喽。