windows nginx安装 php

PhpPhp 2023-08-29 02:32:18 1128
摘要: 在搭建web服务器时,Nginx是一款高性能的web服务器,而PHP是一种常用的web开发语言,当我们想把Nginx将PHP集成在一起使用时,就需要对它们进行安装和配置。本文将介绍在Windows环境下安装和配置Nginx和PHP...

在搭建 web 服务器时,Nginx 是一款高性能的 web 服务器,而 PHP 是一种常用的 web 开发语言,当我们想把 Nginx 将 PHP 集成在一起使用时,就需要对它们进行安装和配置。本文将介绍在 Windows 环境下安装和配置 Nginx 和 PHP 的详细过程。

安装 Nginx

  1. 下载 Nginx

首先,我们需要在 Nginx 的官网(https://nginx.org/en/download.html)上下载最新的 Windows 版本,选择 32 位或 64 位的版本,再将其解压到一个自定义的目录。例如,可以将 Nginx 解压到 C:
ginx。

  1. 配置 Nginx

接着,我们需要在 Nginx 目录下创建一个 conf 目录,然后在 conf 目录下创建一个 nginx.conf 文件。在 nginx.conf 文件中,输入以下内容:

worker_processes  1;

error_log  logs/error.log;
pid        logs/nginx.pid;

events {
 worker_connections  1024;
}

http {
 include       mime.types;
 default_type  application/octet-stream;

 sendfile        on;
 keepalive_timeout  65;

 server {
   listen       80;
   server_name  localhost;
   root         html;
   index        index.php index.html index.htm;

   location / {
     try_files $uri $uri/ /index.php?$query_string;
   }

   error_page   500 502 503 504  /50x.html;
   location = /50x.html {
     root   html;
   }

   location ~ .php$ {
     fastcgi_pass   127.0.0.1:9000;
     fastcgi_index  index.php;
     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     include        fastcgi_params;
   }
 }
}