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]\.";
相关推荐
码里法8 小时前
centos安装nginx并配置https完整版
nginx·https·centos
zly35008 小时前
linux查看正在运行的nginx的当前工作目录(webroot)
linux·运维·nginx
fbllfbll9 小时前
Alpine下部署Nginx+MAZANOKE在线批量压缩图片
服务器·nginx·pve·alpine·lxc容器·在线压缩图片·mazanoke
irisart16 小时前
第二章【NGINX 开源功能】—— 七层反向代理(上)
运维·nginx
single3717 小时前
Nginx 生产环境平滑升级实战:从 1.24.0 到 1.28.0 的零宕机操作全记录
nginx
苹果醋318 小时前
vue + iview + vue-i18n中英翻译
java·运维·spring boot·mysql·nginx
OnlyEasyCode18 小时前
Linux部署Nginx前后端web教程
linux·前端·nginx
IvyWangT18 小时前
Uvicorn的多进程&Nginx的负载均衡 区别
nginx·负载均衡
Hui Baby18 小时前
LVS+Nginx实现高负载均衡框架(四层负载LVS+七层应用负载Nginx)
nginx·负载均衡·lvs
程序员爱德华20 小时前
Nginx 服务器
nginx