Nginx和PHP-FPM结合

PHP-FPM运行模式:

1.socket 
listen = /usr/local/php/var/run/www.sock

2.tcp
listen = 127.0.0.1:9000

Nginx结合PHP-FPM的两种模式:

1.socket
fastcgi_pass unix:/usr/local/php/var/run/www.sock;
2.tcp
fastcgi_pass  127.0.0.1:9000;
Nginx支持PHP程序:
location ~ \.php$ {       
	fastcgi_index index.php;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
	include fastcgi_params;
}

测试php动态脚本:

1.配置文件语法检测

nginx -t

2.配置index.php默认首页的优选级

location / {
	index index.php index.html
}

3.nginx结合php

vi /etc/nginx/default.d/php.conf
location ~ \.php$ {       
	fastcgi_index index.php;
	#fastcgi_pass unix:/run/php-fpm/www.sock;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
	include fastcgi_params;
}

4.重启nginx或重载nginx

/usr/local/nginx/sbin/nginx -s reload
pkill -HUP nginx

5.客户端测试

http://192.168.2.1

Leave a Reply

您的邮箱地址不会被公开。 必填项已用 * 标注