windows下Nginx安装与配置

1、下载nginx/windows

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

        blob.png    

2、解压:

        blob.png

    提示:父级目录不要中文命名


3、配置

    找到下面的代码:

location / {
            root  html;
            index  index.html index.htm;
}

    修改为:

location / {
            root   D:/phpStudy/WWW;
            index  index.php index.html index.htm;
}

    打开nginx目录的conf/nginx.conf,把下面配置前面的#去掉:

    location ~ \.php$ {
            root           D:/phpStudy/WWW;  #指定项目的根目录
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  D:/phpStudy/WWW/$fastcgi_script_name;  //$前面设置为项目的根目录绝对路径
            include        fastcgi_params;
     }



4. 启动php-cgi

打开cmd命令窗口,切换到php的安装目录,执行php-cgi -b 127.0.0.1:9000,即可启动php-cgi,启动完成后,cmd窗口切勿关闭,否则php-cgi也会被关掉的。

特别提醒:只有在开启php-cgi的情况下,nginx才能正常访问php。



5、启动nginx:        

    按下win+R键,输入cmd进入命令窗口,进行到nginx的根目录

    blob.png

    执行:start nginx 启动nginx,然后在任务管理器查看进程

    blob.png

    启动:start nginx

    停止:nginx -s stop

    退出:nginx -s quit


6、测试:

    在项目根目录建立php测试文件,输入localhost:blob.png



版权声明: 此文为本站源创文章[或由本站编辑从网络整理改编],
转载请备注出处:
[狂码一生] https://www.sindsun.com/articles/26/56
[若此文确切存在侵权,请联系本站管理员进行删除!]


--THE END--