Nginx + Redis + srcache + PHP-FPM架构部署
Nginx Redis srcache PHP-FPM架构请求流程客户端发起 HTTP 请求 → Nginx 接收。Nginx 先检查 Redis 中是否有对应缓存命中直接从 Redis 读取内容并返回给客户端无需 PHP 参与。未命中将请求转发给 PHP-FPM 处理PHP 生成内容后Nginx 再将其缓存到 Redis同时返回给客户端。核心模块ngx_http_redis_module让 Nginx 直接与 Redis 通信读取缓存。ngx_http_srcache_module负责将 PHP 生成的响应内容缓存到 Redis。流程图源码安装nginx[rootnginx ~]# wget https://nginx.org/download/nginx-1.28.1.tar.gz[rootnginx ~]# tar zxf nginx-1.28.1.tar.gz[rootnginx ~]# cd nginx-1.28.1/#安装依赖[rootnginx ~]# dnf install gcc pcre-devel zlib-devel openssl-devel -y#选择要使用的模块[rootnginx nginx-1.28.1]# ./configure --prefix/usr/local/nginx --usernginx --groupnginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module/root/echo-nginx-module-0.64 --add-module/root/redis2-nginx-module-0.15 --add-module/root/srcache-nginx-module-0.33[rootnginx nginx-1.28.1]# make make install#创建运行用户[rootnginx]# useradd -s /sbin/nologin -M nginx#设定环境变量[rootnginx sbin]# vim ~/.bash_profileexportPATH$PATH:/usr/local/nginx/sbin[rootnginx sbin]# source ~/.bash_profile#编写Nginx启动文件systemd[rootnginx ~]# cd /lib/systemd/system[rootnginx system]# vim nginx.service[Unit]DescriptionThe NGINX HTTP and reverse proxy serverAftersyslog.target network.target remote-fs.target nss-lookup.target[Service]TypeforkingPIDFile/usr/local/nginx/logs/nginx.pid#指定nginx启动的pidExecStartPre/usr/local/nginx/sbin/nginx -t#指定nginx -t检查配置文件命令ExecStart/usr/local/nginx/sbin/nginx#指定nginx启动命令ExecReload/bin/kill -s HUP$MAINPIDExecStop/bin/kill -s QUIT$MAINPIDPrivateTmptrue[Install]WantedBymulti-user.target#使编写的配置生效[rootnginx system]# systemctl daemon-reload#在启动时要确保nginx已经关闭不然会冲突导致报错[rootnginx system]# systemctl enable --now nginx源码安装php[rootnginx ~]# wget https://www.php.net/distributions/php-8.3.30.tar.gz[rootnginx ~]# wget https://mirrors.aliyun.com/rockylinux/9.7/devel/x86_64/os/Packages/o/oniguruma-devel-6.9.6-1.el9.6.x86_64.rpm #下载依赖包[rootnginx ~]# tar zxf php-8.3.30.tar.gz#安装依赖[rootnginx ~]# dnf install gcc systemd-devel-252-51.el9.x86_64 libxml2-devel.x86_64 sqlite-devel.x86_64 libcurl-devel.x86_64 libpng-devel.x86_64 oniguruma-devel-6.9.6-1.el9.6.x86_64.rpm -y[rootnginx php-8.3.30]# ./configure \--prefix/usr/local/php\#安装路径--with-config-file-path/usr/local/php/etc\#指定配置路径--enable-fpm\#用cgi方式启动程序--with-fpm-usernginx\#指定运行用户身份--with-fpm-groupnginx\--with-curl\#打开curl浏览器支持--with-iconv\#启用iconv函数转换字符编码--with-mhash\#mhash加密方式扩展库--with-zlib\#支持zlib库用于压缩http压缩传输--with-openssl\#支持ssl加密--enable-mysqlnd\#mysql数据库--with-mysqli\--with-pdo-mysql\--disable-debug\#关闭debug功能--enable-sockets\#支持套接字访问--enable-soap\#支持soap扩展协议--enable-xml\#支持xml--enable-ftp\#支持ftp--enable-gd\#支持gd库--enable-exif\#支持图片元数据--enable-mbstring\#支持多字节字符串--enable-bcmath\#打开图片大小调整,用到zabbix监控的时候用到了这个模块--with-fpm-systemd#支持systemctl 管理cgi[rootnginx php-8.3.30]# make make instsall配置优化php[rootnginx ~]# cd /usr/local/php/etc[rootnginx etc]# cp php-fpm.conf.default php-fpm.conf #复制模板[rootnginx etc]# vim php-fpm.conf#去掉注释pidrun/php-fpm.pid#指定pid文件存放位置[rootnginx etc]# cd php-fpm.d/[rootnginx php-fpm.d]# cp www.conf.default www.conf[rootnginx php-fpm.d]# vim www.conf41listen0.0.0.0:9000#可以修改端口#生成主配置文件[rootnginx php-8.3.30]# cp php.ini-production /usr/local/php/etc/php.ini[rootnginx ~]# vim /usr/local/php/etc/php.ini989date.timezoneAsia/Shanghai#修改时区#生成启动文件[rootnginx etc]# cp ~/php-8.3.30/sapi/fpm/php-fpm.service /lib/systemd/system/[rootnginx etc]# vim /lib/systemd/system/php-fpm.service#ProtectSystemfull #注释该内容[rootnginx etc]# systemctl daemon-reload[rootnginx etc]# systemctl enable --now php-fpm.service[rootnginx etc]# netstat -antlupe | grep phptcp00127.0.0.1:90000.0.0.0:* LISTEN0120615147595/php-fpm: masrpm包安装redis[rootnginx ~]# dnf install redis -ynginx配置整合redis与php[rootnginx ~]# vim /usr/local/nginx/conf.d/php.confupstream redis{server127.0.0.1:6379;keepalive10;}server{listen80;server_name php.fjw.org;root /webdir/fjw.org/php/html;location /redis{internal;set$redis_key$query_string;redis2_query get$redis_key;redis2_query setex$redis_key300$srcache_response_body;redis2_pass redis;}location ~\.php${set$key$uri$args;srcache_fetch GET /redis$key;srcache_store PUT /redis$key;fastcgi_pass127.0.0.1:9000;fastcgi_index index.php;include fastcgi.conf;}}[rootnginx ~]# nginx -s reload测试编写测试文件[rootnginx ~]# vim /webdir/fjw.org/php/html/test.php?phpechoGenerated by PHP at .date(Y-m-d H:i:s);?访问测试第一次访问http://服务器IP/test.php页面显示当前时间此时 Nginx 缓存未命中请求由 PHP 处理并缓存到 Redis。刷新页面若显示的时间与第一次相同说明缓存命中Nginx 直接从 Redis 返回内容绕过了 PHP。

相关新闻

用数据说话 10个AI论文工具测评:专科生毕业论文+科研写作必备神器

用数据说话 10个AI论文工具测评:专科生毕业论文+科研写作必备神器

在当前学术研究日益数字化的背景下,AI写作工具已成为科研与论文写作中不可或缺的辅助手段。然而,面对市场上琳琅满目的产品,如何选择真正适合自己的工具成为难题。为此,我们基于2026年的实测数据与用户真实反馈,对多款…

2026/7/6 1:34:03 阅读更多 →
cv_resnet50_face-reconstruction模型压缩:知识蒸馏技术实践

cv_resnet50_face-reconstruction模型压缩:知识蒸馏技术实践

cv_resnet50_face-reconstruction模型压缩:知识蒸馏技术实践 想把人脸重建模型塞进手机里?这听起来像是个不可能的任务。原版的cv_resnet50_face-reconstruction模型,也就是那个在CVPR 2023上大放异彩的HRN模型,效果确实惊艳&…

2026/5/17 4:20:42 阅读更多 →
直接上结论:圈粉无数的降AIGC平台 —— 千笔·专业降AIGC智能体

直接上结论:圈粉无数的降AIGC平台 —— 千笔·专业降AIGC智能体

在AI技术迅速发展的今天,越来越多的研究生开始借助AI工具辅助论文写作,以提升效率和内容质量。然而,随之而来的AI生成内容痕迹过重、查重率偏高问题,却让不少学生陷入困境。知网、Turnitin等平台对AI生成内容的识别愈发严格&#…

2026/7/6 1:26:32 阅读更多 →

最新新闻

新手入门:5分钟学会使用openEuler迁移助手

新手入门:5分钟学会使用openEuler迁移助手

新手入门:5分钟学会使用openEuler迁移助手 【免费下载链接】migration-assistant Migration assistant helps users migrate business applications from other Linux hairstyles to openEuler OS. 项目地址: https://gitcode.com/openeuler/migration-assistant …

2026/7/6 8:33:50 阅读更多 →
MIL 增量学习实战:基于注意力与原型映射,3数据集F1分数提升2-4%

MIL 增量学习实战:基于注意力与原型映射,3数据集F1分数提升2-4%

MIL增量学习实战:基于注意力与原型映射的性能突破1. 前沿交叉领域的创新实践在动态数据环境下,多示例学习(MIL)与增量学习的结合正成为解决现实问题的关键技术。传统MIL方法在静态封闭环境中表现优异,但当面对持续新增…

2026/7/6 8:33:50 阅读更多 →
Cantian connector for MySQL故障排查手册:常见问题与解决方案

Cantian connector for MySQL故障排查手册:常见问题与解决方案

Cantian connector for MySQL故障排查手册:常见问题与解决方案 【免费下载链接】cantian-connector-mysql Cantian connector for MySQL is a MySQL storage engine plugin. It is capable of forming MySQL instances into a multi-read, multi-write transparent …

2026/7/6 8:31:50 阅读更多 →
如何快速上手warpdrive:10分钟完成硬件加速环境搭建

如何快速上手warpdrive:10分钟完成硬件加速环境搭建

如何快速上手warpdrive:10分钟完成硬件加速环境搭建 【免费下载链接】libwd 项目地址: https://gitcode.com/openeuler/libwd 前往项目官网免费下载:https://ar.openeuler.org/ar/ warpdrive(libwd)是openEuler生态中的硬…

2026/7/6 8:31:50 阅读更多 →
NestOS-Config性能优化指南:从内核配置到系统调优的10个关键技巧

NestOS-Config性能优化指南:从内核配置到系统调优的10个关键技巧

NestOS-Config性能优化指南:从内核配置到系统调优的10个关键技巧 【免费下载链接】nestos-config nestos-config provides base manifest configuration for building NestOS. 项目地址: https://gitcode.com/openeuler/nestos-config 前往项目官网免费下载&…

2026/7/6 8:31:50 阅读更多 →
NestOS-Config社区贡献指南:如何参与配置开发与维护

NestOS-Config社区贡献指南:如何参与配置开发与维护

NestOS-Config社区贡献指南:如何参与配置开发与维护 【免费下载链接】nestos-config nestos-config provides base manifest configuration for building NestOS. 项目地址: https://gitcode.com/openeuler/nestos-config 前往项目官网免费下载:h…

2026/7/6 8:27:49 阅读更多 →

日新闻

H2 与 MySQL 单元测试兼容性:5 个关键 SQL 语句差异与规避方案

H2 与 MySQL 单元测试兼容性:5 个关键 SQL 语句差异与规避方案

H2与MySQL单元测试兼容性:5个关键SQL语句差异与规避方案1. 单元测试中的数据库兼容性挑战在Java开发领域,单元测试是保证代码质量的重要环节。当应用涉及数据库操作时,测试环境的搭建往往成为开发者的痛点。H2数据库因其轻量级、内存模式和快…

2026/7/6 0:01:17 阅读更多 →
Windows任务栏终极清理指南:用RBTray一键隐藏窗口到系统托盘

Windows任务栏终极清理指南:用RBTray一键隐藏窗口到系统托盘

Windows任务栏终极清理指南:用RBTray一键隐藏窗口到系统托盘 【免费下载链接】rbtray A fork of RBTray from http://sourceforge.net/p/rbtray/code/. 项目地址: https://gitcode.com/gh_mirrors/rb/rbtray 你是否厌倦了Windows任务栏上密密麻麻的图标&…

2026/7/6 0:01:17 阅读更多 →
Visual C++ 运行时库一键安装终极指南:告别DLL缺失烦恼

Visual C++ 运行时库一键安装终极指南:告别DLL缺失烦恼

Visual C 运行时库一键安装终极指南:告别DLL缺失烦恼 【免费下载链接】vcredist AIO Repack for latest Microsoft Visual C Redistributable Runtimes 项目地址: https://gitcode.com/gh_mirrors/vc/vcredist 你是否曾经遇到过这样的情况:下载了…

2026/7/6 0:05:19 阅读更多 →

周新闻

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容 【免费下载链接】BiliTools A cross-platform bilibili toolbox. 跨平台哔哩哔哩工具箱,支持下载视频、番剧等等各类资源 项目地址: https://gitcode.com/GitHub_Trending/bilit/BiliTools …

2026/7/6 8:11:50 阅读更多 →
威胁模型全解析:从新手入门到实战应用,助你构建安全产品!

威胁模型全解析:从新手入门到实战应用,助你构建安全产品!

威胁模型的陌生现状在忙碌疲惫的一天里,参与了关于混合后量子密码学的讨论,应付端点攻击找茬的人,还参与留言板讨论后,发现“威胁模型”对多数人仍是陌生概念,且多被当作时髦用语。有趣的相关画作有一幅由 Embyr 创作的…

2026/7/6 8:11:52 阅读更多 →
渗透测试入门指南:从零基础到实战环境搭建

渗透测试入门指南:从零基础到实战环境搭建

1. 从“看热闹”到“入门”:我理解的渗透测试到底是什么?每次看到新闻里说某个大公司的数据被“黑”了,或者某个网站被攻击导致服务瘫痪,你是不是和我一样,心里会冒出两个念头:一是“这黑客真厉害”&#x…

2026/7/6 6:52:56 阅读更多 →

月新闻