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