Nginx和apache伺服器中php運行方式

來源:互聯網
上載者:User

標籤:服務   位置   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運行方式

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.