nginx下载地址
http://nginx.org/en/download.html

php下载
https://windows.php.net/download#php-7.3

配置PHP
-
解压后在文件夹中找到php.ini-development文件复制一份并改名为php.ini
-
给PHP指定可加载扩展模块的位置
在php.ini中找到extension_dir项目,取消注释并赋值为”./ext”

- 然后让PHP和Nginx联动
在php.ini中找到cgi.fix_pathinfo项目,取消注释。

cgi.fix_pathinfo是用来设置在cgi模式下PHP是否提供PATH_INFO信息。
因为nginx默认不会设置PATH_INFO的值,所以需要通过上面的方法来提供。
配置nginx
- windows下nginx命令
// 开启服务
start nginx
// fast shutdown
nginx -s stop
// graceful shutdown
nginx -s quit
// changing configuration,
// starting new worker processes with a new configuration,
// graceful shutdown of old worker processes
nginx -s reload
// re-opening log files
nginx -s reopen
- 修改nginx.conf文件(支持多站点部署)
- 在http里面加入
include ../modules/*.conf;
#user nobody;
worker_processes 1;
# 打开log
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
include ../modules/*.conf;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
# 打开log
access_log logs/access.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
# 打开log
access_log logs/host.access.log;
location / {
# 设置网站的根目录(类似Apache的www目录)
# 这个路径自己定义就行,下面的是我自己的路径
root D:/work/www;
# 把index.php添加到默认首页,就是输入/时自动打开/index.php
index index.html index.htm index.php;
}
# 打开404页面(可以不动)
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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
# 配置FastCGI,PHP 脚本请求全部转发到 FastCGI处理
location ~ \.php$ {
#
root D:/work/www;
# 设置监听端口
fastcgi_pass 127.0.0.1:9000;
# 设置nginx的默认首页文件(上面已经设置过了,可以删除)
fastcgi_index index.php;
# 设置脚本文件请求的路径
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 引入fastcgi的配置文件
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
}

-
在nginx-1.14.2目录下新建modules目录
在modules下新建配置文件,拓展名是 .conf,名字随便起 -
配置XXX.conf文件
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# 这边的路劲填写项目路劲
root F:/www/youqibackend/backend/web;
# 记得加上 index.php
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite . /index.php 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;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# 这边的路劲填写项目路劲
root F:/www/youqibackend/backend/web;
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;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
启动php-cgi和Nginx
启动php-cgi
D:/xampp/php/php-cgi.exe -b 127.0.0.1:9000 -c D:/xampp/php/php.ini
启动Nginx
E:/conf/nginx-1.14.2/nginx.exe -p E:/conf/nginx-1.14.2
使用批处理快速启动
-
把下载的RunHiddenConsole.exe和批处理文件放在同一目录里。
-
编辑启动的批处理文件(start_nginx.bat)
REM REM是bat文件的注释类似于php的//
REM 设置不输出命令
@ECHO off
REM 设置Nginx和php-cgi的目录
SET php_home=D:/xampp/php/
SET nginx_home=E:/conf/nginx-1.14.2/
REM 输出状态
ECHO Starting PHP FastCGI...
REM 启动php-cgi -b 端口 -c php.ini位置
REM %php_home%为获取上面set的php_home的值
RunHiddenConsole %php_home%php-cgi.exe -b 127.0.0.1:9000 -c %php_home%php.ini
REM 输出状态
ECHO Starting nginx...
REM 启动Nginx -p Nginx的根目录
RunHiddenConsole %nginx_home%nginx.exe -p %nginx_home%
- 编辑停止的批处理文件(stop.bat)
@ECHO off
ECHO Stopping nginx...
REM 结束进程 /F 强制终止 /IM 指定的进程
TASKKILL /F /IM nginx.exe
ECHO Stopping PHP FastCGI...
TASKKILL /F /IM php-cgi.exe
REM 关闭窗口
EXIT

RunHiddenConsole下载
链接: https://pan.baidu.com/s/1WdOb0qyiH-9epeRgnhf7kA 提取码: 7gn4
https://www.inbeijing.org/archives/1181
https://blog.csdn.net/zjiang1994/article/details/72878374
网友评论