一般现在我们配置的PHP的web环境,如LNMP(linux+Nginx+Mysql+PHP), 这里linux可能是centos, ubuntu..., 数据库可能是mysql, postgresql, sql server等。。
在服务器上安装PHP-FPM, nginx后, 我们要配置Nginx的http模块, 让 .php的文件由nginx 转发给PHP-FPM处理,然后在将php-fpm的处理结果通过http响应传给浏览器,就完成了一次http的请求。。
在配置 Nginx 的http模块的时候, 通常是这样:
server ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass 127.0.0.1:9000;
}
也可以这样,
server ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
那么这两种方式有什么区别呢??
这就是我这篇博文所要解释的问题。下面,我带大家来分析一下其中的原理,一下是我的一些理解,不对的地方还请大家不吝赐教,我将很感激~~
PHP-FPM can listen on multiple sockets. I also listen on Unix sockets, or TCP sockets. See how this works and how to ensure Nginx is properly sending requests to PHP-FPM.
Command Rundown
Default Configuration
Edit PHP-FPM configuration
# Configure PHP-FPM default resource pool
sudo vim /etc/php5/fpm/pool.d/www.conf
PHP-FPM Listen configuration:
# Stuff omitted
listen = /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
Also edit Nginx and see where it's sending request to PHP-FPM:
# Files: /etc/nginx/sites-available/default
# ... stuff omitted
server ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
We can see above that Nginx is sending requests to PHP-FPM via a unix socket (faux file) at /var/run/php5-fpm.sock. This i