ngx_http_fastcgi_module fastcgi模块
http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html
The ngx_http_fastcgi_module module allowspassing requests to a FastCGI server.
配置示例:
location / {
fastcgi_pass localhost:9000;
fastcgi_indexindex.php;
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
}
1、配置在PHP中使用fastcgi模块
编辑default.conf,开启如下内容:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
编辑fastcgi_params,修改为如下内容
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only,required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
案例1、安装php-fpm并使用fastcgi模块
[root@www conf.d]# yum install php-fpm
[root@www conf.d]# rpm -ql | grep php-fpm
rpm: noarguments given for query
[root@www conf.d]# rpm -ql php-fpm
/etc/logrotate.d/php-fpm
/etc/php-fpm.conf
/etc/php-fpm.d
/etc/php-fpm.d/www.conf
/etc/rc.d/init.d/php-fpm
/etc/sysconfig/php-fpm
/usr/sbin/php-fpm
/usr/share/doc/php-fpm-5.3.3
/usr/share/doc/php-fpm-5.3.3/LICENSE
/usr/share/doc/php-fpm-5.3.3/php-fpm.conf.default
/usr/share/fpm/status.html
/usr/share/man/man8/php-fpm.8.gz
/var/log/php-fpm
/var/run/php-fpm
php-fpm参数
[root@www nginx]# /usr/sbin/php-fpm -h
Usage: php-fpm [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p<prefix>] [-g <pid>] [-c <file>] [-d foo[=bar]] [-y<file>] [-D] [-F]
-c<path>|<file> Look for php.ini file in this directory
-n No php.ini file will be used
-dfoo[=bar] Define INI entry foo withvalue 'bar'
-e Generate extended informationfor debugger/profiler
-h This help
-i PHP information
-m Show compiled in modules
-v Version number
-p, --prefix<dir>
Specify alternative prefix path to FastCGI process manager (default:/usr).
-g, --pid<file>
Specify the PID file location.
-y,--fpm-config <file>
Specify alternative path to FastCGI process manager config file.
-t,--test Test FPM configuration andexit
-D,--daemonize force to run in background,and ignore daemonize option from config file
-F,--nodaemonize
force to stay in foreground, and ignore daemonize option from configfile
-R,--allow-to-run-as-root
Allow pool to run as root (disabled by default)
在后台启动php-fpm
[root@www nginx]# /usr/sbin/php-fpm -D
[root@www ~]# ss -tnlup | grep 9000
tcp 0 128 127.0.0.1:9000 *:* users:(("php-fpm",10512,7),("php-fpm",10513,0),("php-fpm",10514,0),("php-fpm",10515,0),("php-fpm",10516,0),("php-fpm",10517,0))
[root@wwwnginx]# vim conf.d/default.