首先先安裝php-fpm,
yum install php-fpm
查看
php-fpm.conf
[www]
listen = /tmp/php-cgi.sock
nginx.conf
server{
location ~ \.php{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
service nginx restart
service php-fpm restart
unix:/tmp/php-cgi.sock
為什么要用unix:/tmp/php-cgi.sock,最主要的特征就是unix socket比tcp快,當網站流量大的時候,服務器的優化是分毫必爭的.
當我們用php-fpm來管理我們的php啟動時,按照如下的配置,就會自動生成/tmp/php-cgi.sock。在php-fpm.conf文件中設置
[www]
listen = /tmp/php-cgi.sock
修改nginx.conf為:
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/tmp/php-cgi.sock;
重啟php-fpm和ngix