lnmp使用socket方式连接nginx优化php-fpm性能
lnmp使用socket方式连接nginx优化php-fpm性能
Nginx连接fastcgi的方式有2种:TCP和unix domain socket
什么是Unix domain socket?—— 维基百科
Unix domain socket 或者 IPC socket是一种终端,可以使同一台操作系统上的两个或多个进程进行数据通信。与管道相比,Unix domain sockets 既可以使用字节流和数据队列,而管道通信则只能通过字节流。Unix domain sockets的接口和Internet socket很像,但它不使用网络底层协议来通信。Unix domain socket 的功能是POSIX操作系统里的一种组件。
Unix domain sockets 使用系统文件的地址来作为自己的身份。它可以被系统进程引用。所以两个进程可以同时打开一个Unix domain sockets来进行通信。不过这种通信方式是发生在系统内核里而不会在网络里传播。
将tcp改成socket方式的配置方法:
1、修改php-fpm的配置文件(如果是编译安装可能是/etc/php-fpm,视具体情况而定)
vim /etc/php-fpm.d/www.conf
;listen = 127.0.0.1:9000
listen = /dev/shm/php-cgi.sock
2、修改.sock文件权限(修改为运行php-fpm的用户)
方法:
ps -ef|grep php-fpm
root 6940 1 0 17:03 ? 00:00:00 php-fpm: master process (/etc/php-fpm.conf)
nginx 6941 6940 0 17:03 ? 00:00:00 php-fpm: pool www
nginx 6942 6940 0 17:03 ? 00:00:00 php-fpm: pool www
nginx 6943 6940 0 17:03 ? 00:00:00 php-fpm: pool www
nginx 6944 6940 0 17:03 ? 00:00:00 php-fpm: pool www
nginx 6945 6940 0 17:03 ? 00:00:00 php-fpm: pool www
修改用户权限
chown nginx:nginx /dev/shm/php-cgi.sock
其中nginx是php-fpm.conf里面设置的用户和群组
ll /dev/shm/php-cgi.sock
srw-rw-rw- 1 nginx nginx 0 Oct 8 17:03 /dev/shm/php-cgi.sock
3、修改nginx配置文件
vim /etc/nginx/nginx.conf
将 fastcgi_pass 127.0.0.1:9000;
改为
fastcgi_pass unix:/dev/shm/php-cgi.sock;
具体:
location ~ \.php$ {
try_files $uri = 404;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
4、重启nginx和php-fpm
systemctl restart php-fpm
systemctl restart nginx
经过测试,php应用正常使用
参考链接:
https://blog.linuxeye.com/364.html
http://blog.csdn.net/niao_ye/article/details/39666695
http://yangjunwei.com/a/1760.html
http://blog.csdn.net/liv2005/article/details/7741732
http://www.cnxct.com/default-configuration-and-performance-of-nginx-phpfpm-and-tcp-socket-or-unix-domain-socket/
lnmp使用socket方式连接nginx优化php-fpm性能的更多相关文章
- 使用socket方式连接Nginx优化php-fpm性能
Nginx连接fastcgi的方式有2种:TCP和unix domain socket 什么是Unix domain socket?-- 维基百科 Unix domain socket 或者 IPC ...
- Nginx优化之服务性能优化
优化Nginx服务的worker进程个数 修改nginx主配置文件 worker_processes 1; #指定了Nginx要开启的进程数,结尾数字就是进程个数 Nginx有Master进程和wor ...
- 高性能网站服务器的架设优化-Nginx优化
一:对于高性能网站 ,请求量大,如何支撑?思路 在网站架构设计中,大家一定对 LNMP (Linux Nginx Mysql Php) 不陌生.LNMP 确实是一个非常优秀的架构,秉承着自由,开放,高 ...
- 18、nginx优化
一.性能优化概述 基询imm能优化,那么在性能优化这一章,我们将分为如下几个方面做介绍 1.首先我们需要了解性能优化要考虑哪些方面. 2.然后我们需要了解性能优化必须要用到的压力测试工具ab. 3.最 ...
- NGINX优化参数
(1)nginx运行工作进程个数,一般设置cpu的核心或者核心数x2 如果不了解cpu的核数,可以top命令之后按1看出来,也可以查看/proc/cpuinfo文件 grep ^processor / ...
- Nginx优化思路
对于高性能网站 ,请求量大,如何支撑? 1方面,要减少请求 对于开发人员----合并css, 背景图片, 减少mysql查询等. 2: 对于运维 nginx的expires ,利用浏览器缓存等,减少查 ...
- nginx优化配置大全
由于面试被问到nginx优化做过哪些 后来发现,其实做过的也不少,忘了的更不少,因此写个博客记录一下(里面有一些内容来源于其他作者). 配置文件样例为生产环境样例. 1.nginx基本优化 安装方式有 ...
- Nginx优化之一
一.Nginx安全优化 1.1:隐藏nginx版本信息 官方配置参数说明:http://nginx.org/en/docs/http/ngx_http_core_module.html#server_ ...
- nginx优化
此文章非原创,出自鸟哥之手~ http://blog.chinaunix.net/uid-25266990-id-2985541.html 改排版改得多,当然红色部分要注意下,用得较多 ------- ...
随机推荐
- OI生涯回忆录 2017.9.10~2018.11.11
然而并没有退役 为了这两天,也准备了一年. 高一零基础的蒟蒻,NOIP2017仅有80pts 之后看着luogu的倒计时, 300天,200天,100天,30天, 直到10天.1天. 10号,11号的 ...
- A1020. Tree Traversals
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and i ...
- Android: View换切后,无法正常设置焦点或切换后TextView的虚拟键盘不弹出
边学.边测试,花了三天时间完工一个小应用. 遇到很多问题,但最终还是解决了. 我的手机是Android2.2版,所以我也在是2.2版环境下学习,开发. 1. 在同一个Activity中的不同View( ...
- 泛型List小项目
页面设计: 显示图书列表运行效果: 添加集合元素运行效果: 插入集合元素运行效果: 删除选中对象: 项目我已经上传到我的百度云盘,下载链接:http://pan.baidu.com/s/1mi3BjY ...
- java程序中加入@SuppressWarnings("serial")是什么意思?
比如有个类实现了java.io.Serialize接口:package com.onede4.test; public class TestSerial implements java.io.Seri ...
- windows安装zabbix监控
在windows下安装zabbix agent,方法非常简单. 首先到zabbix官方下载windows版本agent,地址:http://www.zabbix.com/download.php,找到 ...
- mysql -- 逻辑语句
1.if语句 delimiter \\ create procedure p1() begin declare i ; then ; elseif i = then ; else ; end if; ...
- Kafka 0.10 Coordinator概述
由Kafka内置实现了失败检测和Rebalance(ZKRebalancerListener),但是它存在羊群效应和脑裂的问题,客户端代码实现低级API也不能解决这个问题.如果将失败探测和Rebala ...
- Study 8 —— 行块元素及定位
行&块元素display:inline;display:block;display:inline-block; 盒模型padding[内边距]padding: 上下内边距 左右内边距;padd ...
- Neural Networks and Deep Learning 课程笔记(第三周)浅层神经网络(Shallow neural networks)
3.1 神经网络概述(Neural Network Overview ) (神经网络中,我们要反复计算a和z,最终得到最后的loss function) 3.2 神经网络的表示(Neural Netw ...