第一步:修改php-fpm运行方式为 socket
打开/Data/apps/php7/etc/php-fpm.d/www.conf文件,并将listen = 127.0.0.1:9000修改为listen = /tmp/php-cgi.sock
Socket是使用unix domain socket连接套接字/dev/shm/php-cgi.sock(很多教程使用路径/tmp,而路径/dev/shm是个tmpfs,速度比磁盘快得多)listen = /dev/shm/php-cgi.sock
第二步:修改nginx配置文件
location ~ [^/]\.php(/|$) {
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
第三步:重启fpm和nginx
==================================================================
测试php-fpm配置
/usr/local/php/sbin/php-fpm -t
/usr/local/php/sbin/php-fpm -c /chenamu/server/php/etc/php.ini -y /chenamu/server/php/etc/php-fpm.conf -t
启动php-fpm
/usr/local/php/sbin/php-fpm
/usr/local/php/sbin/php-fpm -c /chenamu/server/php/etc/php.ini -y /chenamu/server/php/etc/php-fpm.d/www.conf.1
关闭php-fpm
kill -INT cat /usr/local/php/var/run/php-fpm.pid
重启php-fpm
kill -USR2 cat /usr/local/php/var/run/php-fpm.pid
/chenamu/server/php/etc/php-fpm.d/www.conf.1
/chenamu/server/php/etc/php-fpm.d/www.conf
=================================================
加强优化
第一步:修改php-fpm运行方式为 socket
第二步:cp多个www.conf,并修改listen = /tmp/php-cgi.sock.1
第三步:修改nginx的配置文件
upstream phpbackend {
server unix:/tmp/php-cgi.sock weight=100 max_fails=10 fail_timeout=30;
server unix:/tmp/php-cgi.sock.1 weight=100 max_fails=10 fail_timeout=30;
}
server {
server_name 127.0.0.1;
listen 444;
ssl on;
ssl_certificate /prefix/nginx/conf/33iq.crt;
ssl_certificate_key /prefix/nginx/conf/33iq_nopass.key;
ssl_protocols SSLv2 TLSv1;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
client_max_body_size 512M;
add_header X-Frame-Options SAMEORIGIN;
charset utf-8;
root /prefix/admin;
index index.html index.htm index.php;
location / {
index index.htm index.html index.php;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php last;
}
}
location ~ \.php(.*)$ {
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass phpbackend;
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
# fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
# fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}```
#### 第四步:重启nginx和php-fpm(php-fpm启动时指定相应的配置文件)