Nginx和PHP-FPM的进程间通信有两种方式,一种是TCP,一种是UNIX Domain Socket.
其中TCP是IP加端口,可以跨服务器.而UNIX Domain Socket不经过网络,只能用于Nginx跟PHP-FPM都在同一服务器的场景.用哪种取决于你的PHP-FPM配置:
方式1:
php-fpm.conf: listen = 127.0.0.1:9073
nginx.conf: fastcgi_pass 127.0.0.1:9073;
方式2:
php-fpm.conf: listen = /tmp/php-fpm.sock
nginx.conf: fastcgi_pass unix:/tmp/php-fpm.sock;
其中php-fpm.sock是一个文件,由php-fpm生成,类型是srw-rw----.
server {
listen 80;
server_name aaa.bbb.cn;
root /data/webroot/aaa.bbb.cn/htdocs;
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite "^/(.*)$" /index.php last;
break;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9073; #假设PHPFastCGI管理器9073
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHPENV development;
include fastcgi.conf;
}
access_log /data/logs/nginx/aaa.bbb.cnlog main;
error_log /data/logs/nginx/aaa.bbb.cn.error.log;
}
================================================
server {
listen 80;
listen 443;
server_name aaa.bbb.com;
root /data/webroot/aaa.bbb.com/htdocs;
index index.html index.htm index.php;
if ($scheme = http ) {
return 301 https://$host$request_uri;
}
ssl_certificate cert/1_aaa.bbb.com_bundle.crt;
ssl_certificate_key cert/2_aaa.bbb.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
if (!-e $request_filename) {
rewrite "^/(.*)$" /index.php last;
break;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9073; #假设PHPFastCGI管理器9073
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
fastcgi_param HTTP_X-Sendfile-Type X-Accel-Redirect;
fastcgi_param HTTP_X-Accel-Mapping /udisk=/data/webroot/edu.cda.cn/app/data/udisk;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 128k;
}
access_log /data/logs/nginx/host.log main;
}
===================================================
server {
listen 80;
listen 443;
server_name aaa.bbb.cn;
root /data/webroot/aaa.bbb.cn/htdocs;
index index.html index.htm index.php;
include vhost/aaa.bbb.cn.ssl;
if (!-e $request_filename) {
rewrite "^/(.*)$" /index.php last;
break;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9073; #假设PHPFastCGI管理器9073
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
fastcgi_param HTTP_X-Sendfile-Type X-Accel-Redirect;
fastcgi_param HTTP_X-Accel-Mapping /udisk=/data/webroot/edu.cda.cn/app/data/udisk;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 128k;
}
access_log /data/logs/nginx/host.log main;
}
aaa.bbb.cn.ssl文件代码:
ssl on;
ssl_certificate cert/cda.cn.pem;
ssl_certificate_key cert/cda.cn.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;