標籤:服務 位置 port ddr 檔案 usr location stc 設定檔
PHP5的CGI方式的一大優勢是內建了FastCGI的支援,只需指明綁定的地址和連接埠參數便可以以FastCGI的方式運行,如下:
php-cgi -b 127.0.0.1:9000
配置Nginx的PHP FastCGI
請將以下內容儲存為fastcgi_params檔案,儲存於/usr/local/nginx/conf下(Ubuntu可儲存於/etc/nginx下),他為我們的FastCGI模組設定了基本的環境變數:
#fastcgi_paramsfastcgi_param GATEWAY_INTERFACE CGI/1.1;fastcgi_param SERVER_SOFTWARE nginx;fastcgi_param QUERY_STRING $query_string;fastcgi_param REQUEST_METHOD $request_method;fastcgi_param CONTENT_TYPE $content_type;fastcgi_param CONTENT_LENGTH $content_length;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param SCRIPT_NAME $fastcgi_script_name;fastcgi_param REQUEST_URI $request_uri;fastcgi_param DOCUMENT_URI $document_uri;fastcgi_param DOCUMENT_ROOT $document_root;fastcgi_param SERVER_PROTOCOL $server_protocol;fastcgi_param REMOTE_ADDR $remote_addr;fastcgi_param REMOTE_PORT $remote_port;fastcgi_param SERVER_ADDR $server_addr;fastcgi_param SERVER_PORT $server_port;fastcgi_param SERVER_NAME $server_name;# PHP only, required if PHP was built with --enable-force-cgi-redirectfastcgi_param REDIRECT_STATUS 200;
請特別注意”fastcgi_script_name”一行,PHP-CGI特別需要此行資訊來確定PHP檔案的位置。
另外需要在PHP-CGI的設定檔(Ubuntu 上此設定檔位於/etc/php5/cgi/php.ini)中,開啟cgi.fix_pathinfo選項:
cgi.fix_pathinfo=1;
這樣php-cgi方能正常使用SCRIPT_FILENAME這個變數。
接下來在nginx的配置中針對php檔案配置其利用FastCGI進程來執行:
server { index index.php; root /usr/local/nginx/html; location ~ .*.php$ { include /usr/local/nginx/conf/fastcgi_params; #請根據自己儲存的路徑進行設定 fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; #請根據自己的FastCGI綁定的地址和連接埠進行配置 }}
Nginx和apache伺服器中php運行方式