windows上nginx + php配置
apache下載失敗,正好對apache那種把php解譯器做成module當動態庫載入到自身進程的預設做法不太滿意,網上大家又都說nginx好,就使用nginx+php+mysql配置一下。
?
環境:Windows 7 32bit
版本:nginx 1.2.3,php-5.4.7-Win32-VC9-x86,mysql 5.5.27
?
nginx和php都是下載後解壓縮就可以用,mysql需要安裝。
?
在php解壓目錄下,將php.ini-development拷貝到php.ini檔案,同時啟用其中的mysql模組:
?
;extension=php_exif.dll ; Must be after mbstring as it depends on itextension=php_mysql.dll;extension=php_mysqli.dll;extension=php_oci8.dll ; Use with Oracle 10gR2 Instant Client;extension=php_oci8_11g.dll ; Use with Oracle 11gR2 Instant Client;extension=php_openssl.dll;extension=php_pdo_firebird.dllextension=php_pdo_mysql.dll;extension=php_pdo_oci.dll
?
注意,必須將指定extension目錄那一行的注釋去掉,否則php不會自動使用ext作為預設值來載入這些擴充:
?
; Directory in which the loadable extensions (modules) reside.; http://php.net/extension-dir; extension_dir = "./"; On windows:extension_dir = "ext"
?
?
然後啟動php內建的cgi程式,在9000連接埠監聽nginx發過來的請求:
?
php-5.4.7-Win32-VC9-x86> php-cgi.exe -b 127.0.0.1:9000
?
在nginx目錄下,修改conf/nginx.conf,啟用fastcgi:
?
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_param SCRIPT_FILENAME D:/software/nginx-1.2.3/html$fastcgi_script_name; include fastcgi_params; }
?
注意,預設設定檔中,fastcgi_param SCRIPT_FILENAME配置的是/scripts$fastcgi_script_name;,表示從這裡找.php檔案。這個預設配置是錯的,使用這個配置時,訪問php頁面會返回“No input file specified”錯誤。需要改成下面這兩種:或者用$document_root,表示當前根web路徑,或者直接用根web路徑的絕對路徑。
?
一般還要將index.php放到根路徑的index中:
location / { root html; index index.html index.htm index.php; }?
?
配置完成後,啟動nginx:
?
D:\software\nginx-1.2.3> start nginx
?
在document_root建立一個簡單的php檔案,測試一下:
?
?
在本地驗證一下:http://localhost:8080/index.php,一般都可以開啟訪問,並可以查看其中的myspartan1
最近訪客 更多訪客>>
dylinshi126
wangshuqin0716
風沙星辰
hbezwwl