windows下ngnix+php配置

一、須要工具:
    下載ngnix  網址:http://nginx.org/php

    下載:RunHiddenConsole         html

二、將下載文件解壓後,將RunHiddenConsole拷貝到ngnix目錄與php所在目錄nginx

    修改conf目錄下ngnix.conf,使其支持php緩存

server {
    listen      80;  #端口
    server_name example.org www.example.org; #域名
    root        e:/www;

    location / {
        index   index.html index.php;
    }

    location ~* \.(gif|jpg|png)$ {
        expires 30d;   #緩存圖片文件
    }
#支持php
    location ~ \.php$ {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME
                        e:/www$fastcgi_script_name;
        include       fastcgi_params;
    }
}

 

另外能夠把虛擬主機單獨出來。在ngnix.conf文件中加入以下代碼bash

http{
 
#其它代碼
 
include vhost/*.conf; #加載vhost目錄下的虛擬主機配置文件
 
}
 
能夠在conf文件夾中新建一個vhost文件夾,在此目錄下創建新文件自定義文件名,擴展名爲conf便可,在文件中加入以下代碼
 
 
 server {
        listen       80;
        server_name  www.szs.com;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   E:/20nc;
            index  index.php index.html index.htm;
        }
 
        #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           D:/wamp/www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME E:/20nc$fastcgi_script_name;
            include        fastcgi_params;
        }
        location ~* \.(gif|jpg|png)$ {
        expires 30d;
         }
 
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
          deny  all;
        }
    }

三、配置php.ini文件使其支持cgi工具

;cgi.force_redirect = 1,刪除前面的分號:cgi.force_redirect = 1.net

;cgi.fix_pathinfo=1,刪除前面的分號:cgi.fix_pathinfo=1code

;cgi.rfc2616_headers = 0,刪除前面的分號:cgi.rfc2616_headers = 1server

四、製做啓動和關閉ngnix文件htm

注意:路徑請自行更改
 
start.bat
 
@echo off
      echo start_nginx.bat
  echo Starting PHP FastCGI...
    cd D:/bin/php/php5.5.12
    d:
  RunHiddenConsole php-cgi.exe -b 127.0.0.1:9000 -c php.ini
  echo Starting nginx...
    cd C:/nginx
    c:
  RunHiddenConsole nginx.exe
  Exit
 
 
exit.bat
 
@echo off
  echo stop_nginx.bat
  echo Stopping nginx...
  taskkill /F /IM nginx.exe > nul
  echo Stopping PHP FastCGI...
  taskkill /F /IM php-cgi.exe > nul
  exit
相關文章
相關標籤/搜索