windows用nginx部署php项目,windows下 用nginx部署php项目

http://nginx.org/en/download.html

260bcb10173540470631b82747046412.png nginx_download1.png

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

f6f55655ab65a94d1a02424cfdd79146.png php_download.png

配置PHP

解压后在文件夹中找到php.ini-development文件复制一份并改名为php.ini

给PHP指定可加载扩展模块的位置

在php.ini中找到extension_dir项目,取消注释并赋值为”./ext”

af3929a95f8ee5348d8e3dec41e6b880.png 1.png

然后让PHP和Nginx联动

在php.ini中找到cgi.fix_pathinfo项目,取消注释。

4bdf599a902528195fadc3a9ef986e1e.png 2.png

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;

#}

}

}

8901561be3921a32c6269dc83f3fbfbb.png 3.png

在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

bf87a3fa30c09d30e38fcb5f539b2d6c.png 4.png

链接: https://pan.baidu.com/s/1WdOb0qyiH-9epeRgnhf7kA 提取码: 7gn4

作者:徐大亮

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值