站长论坛

标题: windows下nginx+php配置 [打印本页]

作者: tznktg    时间: 2012-6-27 09:46
标题: windows下nginx+php配置
版本 nginx0.8.20    php5.2.10

解压nginx到C:/web/nginx-0.8.20
解压php 到C:/web/php
//--------------------------------------------------------------------------------------
修改配置nginx.conf

gzip  on;

    server {
        listen       80;
        server_name  localhost;

        charset utf-8;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;        
            #index  index.html index.htm;
        root    D:/var/www;
        index   index.html index.htm index.php;
        autoindex on; #充许列表目录
        }

        #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
        #
        location ~ \.php$ {
        #    root           html;
        root       D:/var/www; #PHP文件目录
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name; #PHP文件
            include        fastcgi_params;
        #fastcgi_intercept_errors on;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

//-------------------------------------------------------------------
修改配置php.ini

enable_dl = On
cgi.force_redirect = 0
cgi.fix_pathinfo=1
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1

这几项和nginx相关,其它和mysql等相关的配置略

//--------------------------------------------------------------------

下载RunHiddenConsole

把"  @echo off
echo Starting PHP FastCGI...
RunHiddenConsole.exe c:\web\php\php-cgi.exe -b 127.0.0.1:9000 -c c:\web\php\php.ini   "引号中间部分用记事本保存并重命名为bat文件  和上面下载的文件放同一目录下,用于启动php-cgi

nginx启动直接双击nginx.exe


把"  @echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit " 引号中间部分用记事本保存,并重命名为bat文件,用于关闭php和nginx

//-------------------------------------------------------------------------
测试时浏览器中出现no input file specified错误时,注掉php.ini中的doc_root,解决

//-------------------------------------------------------------------------
nginx.conf添加两个虚拟机  bug和db

server {
        server_name  bug;
        location / {
            root   D:/var/www/bug/;
            index  index.html index.htm index.php;
        autoindex on;
        }
    location ~ \.php$ {
        root       D:/var/www/bug/;
            fastcgi_pass   127.0.0.1:9000;           
            include        fastcgi_params;      
        }
    }
    server {
        server_name  db;
        location / {
            root   D:/var/www/db/;
            index  index.html index.htm index.php;
        autoindex on;
        }
    location ~ \.php$ {
        root       D:/var/www/db/;
            fastcgi_pass   127.0.0.1:9000;           
            include        fastcgi_params;      
        }
    }








欢迎光临 站长论坛 (http://www.tzlink.com/bbs/) Powered by Discuz! X3.2