windows下搭建nginx+php+虚拟主机配置过程

需要软件信息:

  nginx

  php

  RunHiddenConsole

 

首先安装之前要规划一下把他们放到那里,比如我将他们统一放在e :/web下

那么将这些都拷贝过来,开始吧,window要执行php-cgi.exe, nginx等,都要配置环境变量,将nginx和php的目录加到里面就好了

 

php.ini的配置信息我就不说明了

就说nginx配置吧

nginx.conf

#user  nobody;
worker_processes  1;

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;
    sendfile        on;

    keepalive_timeout    65;

    #gzip  on; 

    include vhost/*.conf;        #加载vhost目录下的虚拟主机配置文件,这里主要用于配置虚拟主机
}

 然后在conf目录下新建虚拟主机(可以配置很多)

server {
        listen       8888;
        server_name  localhost;
        location / {
             root   e:/web/nginx/local;        #网站文件路径
            index  index.php;
            if  (  !-f  $request_filename  )  {
                rewrite  ^/(.*)$  /index.php last;#rewrite
            }
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
          location ~ \.php$ {
            root           e:/web/nginx/local;#这个目录自己定
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

  然后在命令控制台执行

 e:/web/php/php-cgi.exe -b 127.0.0.1:9000 -c e:/web/php/php.ini
开启php监听


 e:/web/nginx/nginx.exe -p e:/web/nginx

打开nginx

然后在html目录下新加index.php,写代码查看就好了

 

由于默认启动php-cgi,控制台不隐藏,所以RunHiddenConsole搞定就好

单独写一个bat处理文件

@echo off


echo Starting PHP FastCGI...
RunHiddenConsole e:/web/php/php-cgi.exe -b 127.0.0.1:9000 -c e:/web/php/php.ini

echo Starting nginx...
RunHiddenConsole e:/web/nginx/nginx.exe -p e:/web/nginx

  再写一个stop的bat

@echo off
echo Stopping nginx...  
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul

exit

就然后执行一下ok

posted on 2014-01-03 14:33  牛-_-蜗  阅读(5197)  评论(1编辑  收藏  举报

导航