rancher里的ingress如何配置gzip压缩

方案一,未试验成功,但配置过程值得记录一下

通过配置configmap,然后在ingress的deployment里引用configmap实现。

参考文章

创建configmap

XML 复制代码
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-ingress-controller
  annotations:
    {}
#    key: string
  creationTimestamp: '2024-03-12T01:53:01Z'
  labels:
    {}
#    key: string
  namespace: ingress-nginx
  resourceVersion: '101812971'
  uid: afe0261e-848a-4af3-a3fd-e0260dd226fd
  fields:
    - nginx-ingress-controller
    - 1
    - 89m
data:
  server-snippet: >
    use-gzip: true
  
    gzip-level: 5
  
    gzip-types: "application/xml+rss application/atom+xml application/javascript
    application/x-javascript application/json applica-tion/rss+xml
    application/vnd.ms-fontobject application/x-font-ttf
    application/x-web-app-manifest+json application/xhtml+xml application/xml
    font/opentype image/svg+xml image/x-icon text/css text/javascript text/plain
    text/x-com-ponent"
#  key: string
__clone: true
#binaryData:
#  key: string
#immutable: boolean

在ingress的定义里,引用configmap

在环境变量里

配置后,通过观察浏览器里的输出,response并没有gzip,js文件的大小也没变。试验失败。

方案二,试验成功了

在发布前端的docker里的nginx里写gzip配置

直接写gzip配置即可

bash 复制代码
server {
    
    listen      80 default_server;
    #listen      [::]:80;
    server_tokens off;
    server_name _;
    client_max_body_size 0;
    underscores_in_headers on;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    #gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types text/plain application/x-javascript application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary off;
    gzip_disable "MSIE [1-6]\.";
相关推荐
ping某3 天前
为什么 Nginx 明明监听了 80,转发后端时却用了 4xxxx 端口?
后端·nginx
難釋懷5 天前
Nginx反向代理中的容错机制
运维·nginx
bloglin999995 天前
Nginx高危漏洞CVE-2021-23017及配置样例
运维·nginx
进阶的小名5 天前
Spring Boot SSE + Nginx 配置:解决 EventSource 不实时返回、连接超时、流式响应被缓冲问题
spring boot·后端·nginx
難釋懷5 天前
Nginx获取客户端真实IP
服务器·前端·nginx
qq_谁赞成_谁反对5 天前
甲方IT的成长之路--nginx实战--2604
服务器·数据库·nginx
图灵追慕者5 天前
Nginx安裝以及配置顯示本地服務器文件夾
运维·nginx
rabbit_pro5 天前
Nginx配置维护模式
运维·nginx
楠目5 天前
Nginx 解析漏洞利用总结
nginx·网络安全
Coisinier6 天前
RHCE中shell脚本基础(磁盘剩余空间监控,Web 服务状态检查,curl 访问 Web 服务并返回状态)
linux·运维·服务器·前端·nginx·操作系统