Windows下的Nginx安装与配置(PHP)

转载:https://blog.csdn.net/zjiang1994/article/details/72878374

下载 PHPPHP
下载Nginx: Nginx

解压到D盘
同时新建php文件,将下载的php解压到php目录下
同时新建php文件,将下载的php解压到php目录下

  1. 找到php.ini-development文件复制一份并改名为php.ini
  2. 给PHP指定可加载扩展模块的位置,extension_dir = “ext”
  3. 让PHP和Nginx联动,cgi.fix_pathinfo=1
  4. php.ini 设置doc_root = “D:/phpstudy/www”

cgi.fix_pathinfo是用来设置在cgi模式下PHP是否提供PATH_INFO信息。
因为nginx默认不会设置PATH_INFO的值,所以需要通过上面的方法来提供。

上面是解压后的目录。

  1. conf 配置目录
  2. log 日志目录
  3. html 默认的网站根目录(类似Apache的www目录)
  4. temp 缓存目录

cmd进入nginx目录

#启动nginx
start nginx
nginx.exe

#重启nginx
nginx.exe -s reload

#停止nginx 
nginx.exe -s stop
nginx.exe -s quit   

#重新打开日志文件
nginx.exe -s reopen

这时在浏览器中输入localhost就能看到nginx的欢迎页面:
在这里插入图片描述
配置nginx的虚拟主机:
在conf目录下打开nginx.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;
    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;
        autoindex       on;   #是否允许访问目录

        #charset koi8-r;

        # 打开log
        access_log  logs/host.access.log;

        location / {
            # 设置网站的根目录(类似Apache的www目录)
            # 这个路径自己定义就行,下面的是我自己的路径
            root  D:/phpstudy/www;
            # 把index.php添加到默认首页,就是输入/时自动打开/index.php
            index  index.html index.htm index.php;
            autoindex       on;   #是否允许访问目录
        }

        # 打开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:/phpstudy/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;
        # }
    }

}

autoindex on; 这个默认是off的 意思是禁止访问目录 需要开启
启动nginx和php-cgi
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值