返回首页 - Notes - 2014

Nginx 在 Windows 下的配置


准备软件

首先下载 NginxPHP 的安装包,然后下载一个叫 RunHiddenConsole 的工具,将这三者的可执行文件路径都加入 PATH 环境变量

Nginx 的根目录下新建 start_ng.batstop_ng.bat,内容分别如下(里面的路径需要换成你本机的实际路径):

@echo off
echo Starting PHP FastCGI...
RunHiddenConsole php-cgi -b 127.0.0.1:9000 -c D:/Ruchee/PHP/php.ini

echo Starting Nginx...
RunHiddenConsole nginx -c D:/Ruchee/Nginx/conf/nginx.conf
@echo off
echo Stopping Nginx...
taskkill /F /IM nginx.exe > nul

echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit

基本配置

打开 php.ini,找到 cgi.fix_pathinfo=1,如果没有开启则去掉它前面的注释开启

打开 nginx.conf,下面是基本的配置:

worker_processes  4;

events {
    worker_connections  1024;
}

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

    keepalive_timeout 65;

    sendfile  on;
    gzip      on;
    autoindex on;


    server {
        listen       80;
        server_name  localhost;
        location / {
            root   D:/Ruchee/Files/code;
            index  index.html index.php;
        }
        location ~ \.php$ {
            root           D:/Ruchee/Files/code;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }


    server {
        listen       80;
        server_name  www.laravel.test;
        location / {
            root   D:/Ruchee/Files/code/self/laravel/public;
            index  index.html index.php;
        }
        location ~ \.php$ {
            root           D:/Ruchee/Files/code/self/laravel/public;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

}

开启服务

双击 start_ng.bat 开启服务

双击 stop_ng.bat 停止服务

先停止再开启以实现重启效果


date : 2014-08-12