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]\.";
相关推荐
Joy T1 小时前
从 Nginx 到 Gateway 再到微服务:一次 AI 请求的完整链路
nginx·微服务·gateway·controller·路由转发·ai service·接口错误排查
小匠石钧知1 小时前
07_在k8s集群中安装ingress-nginx
nginx·容器·kubernetes·ingress
百度一下吧13 小时前
Nginx 使用手册:从安装配置到实战部署
运维·nginx
JAVA面经实录9171 天前
Java高级后端 · 全套面试通关手册(Nginx)
java·nginx·面试
紫神2 天前
DDS 通信技术说明
网络·云原生·容器·k8s·dds·弱网
lpfasd1233 天前
WinSW在Win7上失败真相-实测与修复
windows·nginx
lpfasd1233 天前
nginx服务化五套方案原理解剖与选型
运维·nginx
ue星空3 天前
ALS V4 中文拆解手册
运维·nginx
大圣编蚕4 天前
Rancher证书轮换过期导致不能访问UI问题处理
ui·rancher
吴声子夜歌4 天前
Nginx应用与运维——Nginx集群负载与配置管理(二)
运维·nginx