Ubuntu14.04 配置nginx 與 php-fpm

來源:互聯網
上載者:User

1、什麼是CGI?

 CGI全稱是“公用網關介面”(Common Gateway Interface),HTTP伺服器與你的或其它機器上的程式進行“交談”的一種工具,其程式須運行在網路伺服器上。

2、什麼是FastCGI?

FastCGI像是一個常駐(long-live)型的CGI,它可以一直執行著,只要啟用後,不會每次都要花費時間去fork一次(這是CGI最 為人詬病的fork-and-execute 模式)。它還支援分布式的運算, 即 FastCGI 程式可以在網站伺服器以外的主機上執行並且接受來自其它網站伺服器來的請求。

3、什麼PHP-CGI?

PHP-CGI是PHP內建的FastCGI管理器。

4、什麼是PHP-FPM?

PHP-FPM是一個PHP FastCGI管理器,是只用於PHP的。PHP-FPM其實是PHP原始碼的一個補丁,旨在將FastCGI進程管理整合進PHP包中。PHP5.3.3以後得版本 已經整合php-fpm了,不再是第三方的包了。PHP-FPM提供了更好的PHP進程管理方式,可以有效控制記憶體和進程、可以平滑重載PHP配置,所以 被PHP官方收錄了。在./configure的時候帶 --enable-fpm參數即可開啟PHP-FPM。使用PHP-FPM來控制PHP-CGI的FastCGI進程。

5、安裝PHP-FPM?

 apt-get install php5-fpm

6、配置nginx與php-fpm

配置/ect/nginx/nginx.conf

user www-data;worker_processes  8;timer_resolution 100ms;worker_rlimit_nofile 20240;worker_priority -5;error_log  /var/log/nginx/error.log;pid        /var/run/nginx.pid;events {    worker_connections  2048;    use epoll;    # multi_accept on;}http {    include       /etc/nginx/mime.types;    access_log  /var/log/nginx/access.log;    sendfile        on;    tcp_nopush     on;    #keepalive_timeout  0;    keepalive_timeout  65;    tcp_nodelay        on;    gzip  on;    gzip_min_length 1100;    gzip_buffers 64 8k;    gzip_comp_level 3;    gzip_http_version 1.1;    gzip_proxied any;    gzip_types text/plain application/xml application/x-javascript text/css;    gzip_disable "MSIE [1-6]\.(?!.*SV1)";    include /etc/nginx/conf.d/*.conf;#   include /etc/nginx/sites-enabled/*;    client_max_body_size 100M;    server_tokens off;}

配置/ect/nginx/conf.d/default.conf

 server {    listen       80;    server_name  bishe.xy.com;    charset UTF-8;    #access_log  /var/log/nginx/log/host.access.log  main;    location / {        root   /www/bishe.xy.com;        index  index.html index.htm index.php;    }    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 {#nginx 預設的www root 檔案為如下, 這裡可以修改為自己的指定的目錄        root   /www;    }    # 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           /www/bishe.xy.com;    fastcgi_pass   unix:/var/run/php5-fpm.sock;        fastcgi_index  index.php;        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;        include        fastcgi_params;    }    # deny access to .htaccess files, if Apache's document root    # concurs with nginx's one    #    location ~ /\.ht {        deny  all;    }}server {    listen       80;    }    #        proxy_pass   http://127.0.0.1;                                                                                                                              1,1           Top

按如上配置,完成後在/www/bishe.xy.com這個目錄下建立一個phpinfo.php檔案,內容如下:

 <?php phpinfo(); ?>

此時需要配置/etc/hosts檔案,加入如下的內容:

 127.0.0.1 bishe.xy.com

在瀏覽器的地址欄輸入如下內容:

 bishe.xy.com/phpinfo.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.