当前位置: 首页 > news >正文

Rocky Linux使用nginx时启用图片压缩

查看目前配置

通过命令获取nginx当前配置信息nginx -V,输出如下

nginx version: nginx/1.20.1
built by gcc 11.5.0 20240719 (Red Hat 11.5.0-5) (GCC) 
built with OpenSSL 3.2.2 4 Jun 2024 (running with OpenSSL 3.0.1 14 Dec 2021)
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --with-ld-opt='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,-E'

可以通过 configure arguments看到nginx/1.20.1 已经在打包时内置了 --with-http_image_filter_module=dynamic“也就是说 官方 RPM 已经把模块编好了,只是没有自动帮你把 .so 文件装进系统。因此你不需要再自己编译源码,只要找到并安装对应的 RPM 子包即可。”

安装压缩图的动态库

Rocky 9 的包名叫 nginx-mod-http-image-filter(不是 nginx-module-image-filter);

dnf install -y nginx-mod-http-image-filter # 或者将dnf替换成你熟悉的语法糖yum也行

安装完成后,模块文件会被放到 /usr/lib64/nginx/modules

重启

此时重启nginx即可,你要是不放心,可以nginx -t验证一下配置是否有误!

其他

不需要手动加载

Rocky 9 的 nginx-mod-http-image-filter 包在安装时,会自动在 /etc/nginx/modules-enabled/ 里放一个软链接,Nginx 主配置里又通过 include /etc/nginx/modules-enabled/*.conf; 把这些模块全部加载,所以你无需再手动写 load_module,即不需要再添加一下代码

// nginx.conf
load_module /usr/lib64/nginx/modules/ngx_http_image_filter_module.so;

不能与代理一起使用

image_filter 只能用在「本地文件」location,
不能和 proxy_pass 同用。
你需要先把文件落地,或使用专用的图片处理服务。

http://www.sczhlp.com/news/1359.html

相关文章:

  • 7.29随笔
  • kali安装maven-cnblog
  • 【ESP8266】模组对比(ESP-12F)以及拆盖图
  • log4j2 远程代码执行漏洞复现(CVE-2021-44228)-cnblog
  • 第四天
  • Luogu-P3455 [POI 2007] ZAP-Queries
  • PDF转Word免费工具!批量处理PDF压缩,合并, OCR识别, 去水印, 签名等全功能详解
  • npm构建公共组件库
  • 空间复杂度 O(1) 解决力扣的困难算法:k个一组翻转链表
  • HotSpot虚拟机对象探秘
  • 6
  • 【设计模式】创建者模式——1.简单工厂模式
  • 智谱 GLM-4.5 也支持了Claude Code
  • 做题记录
  • 若依
  • Rust 性能优化秘籍:write! 宏让字符串构建提速 75%
  • 基于文件对比的技术写作内容碎片统一与上下文还原方法论
  • Rust 编译优化指南:如何让你的代码更小更快?
  • Windows下CMake安装及环境变量配置
  • Rust 字节处理入门指南:掌握 Vec、Cow 和零拷贝技术
  • 408-OS之阻塞IO和非阻塞IO
  • Python中字符串前“b”,“r”,“u”,“f”的作用
  • (个人思考) 直接使用GE,不用Ability
  • goethereum-地址检查 - Charlie
  • js高级第三天
  • 无需重训练即可教语音识别器学习新词
  • llama.cpp编译过程中的cmake版本问题 - Luna
  • 如何高效使用Cursor AI编程助手提升开发效率 | 完整配置与使用指南
  • WPF MVVM 入门学习笔记:从零开始理解 CommunityToolkit 与 ObservableObject 详解
  • 为所有人提供TSC频率:更精准的性能分析与基准测试