编译安装配置内容
index index.php index.html index.htm;
location ~ .*.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
PHP测试文件
vim index.php
<?php
phpinfo();
?>
YUM安装配置内容
location ~ \.php$ {
root /www;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params; #变量配置文件
}
$document_root 相当于URL
$fastcgi_script_name 相当于URI
Nginx+PHP 和Apache+PHP的区别
Nginx是通过fastcgi协议调用php
Apache是已模块的方式加载PHP (YUM安装php后,可以理解成php变成了Apache的一个模块)
FastCGI长连接
upstream fastcgi_backend {
server x.x.x.x:9000;
keepalived 16;
}
server {
…
location /{
fastcgi_pass fastcgi_backend;
fastcgi_keep_conn on; #开启长连接
}
}