nginx proxy minio 默认页配置

原理很简单,就是基于nginx 的rewrite 自动处理模版bucket 的index page 处理

参考配置

  • 环境准备
version: "3"
services:
  nginx:
     image: openresty/openresty:alpine-fat
     ports: 
     - "80:80"
     volumes: 
     - "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
  s3:
    image: minio/minio
    command: server /export
    ports:
    - "9002:9000"
    volumes:
      - ./data:/data
      - ./config:/root/.minio
    environment:
    - "MINIO_ACCESS_KEY=dalongapp"
    - "MINIO_SECRET_KEY=dalongapp"
  • nginx 配置
worker_processes  1;
user root;  
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    lua_code_cache off;
    gzip  on;
    resolver 127.0.0.11 8.8.8.8 ipv6=off;          
    real_ip_header     X-Forwarded-For;
    real_ip_recursive on;
    upstream s3app {
      server s3:9000;
    }
    server {
        listen       80;
        server_name  localhost;
        charset utf-8;
        root html;
        index index.html index.htm;
        default_type text/html;
        location  /demoapp/ {
           default_type text/html;
           index index.html index.htm;
           rewrite ^/(demoapp)(\d*)/$ /$1$2/index.html break;
           proxy_set_header Host $http_host;
           proxy_set_header X-Forwarded-For $remote_addr;
           client_body_buffer_size 10M;
           client_max_body_size 10G;
           proxy_buffers 1024 4k;
           proxy_read_timeout 300;
           proxy_next_upstream error timeout http_404;
           proxy_pass http://s3app;
        }
        location  /demoapp2/ {
           default_type text/html;
           index index.html index.htm;
           rewrite ^/(demoapp)(\d*)/$ /$1$2/index.html break;
           proxy_set_header Host $http_host;
           proxy_set_header X-Forwarded-For $remote_addr;
           client_body_buffer_size 10M;
           client_max_body_size 10G;
           proxy_buffers 1024 4k;
           proxy_read_timeout 300;
           proxy_next_upstream error timeout http_404;
           proxy_pass http://s3app;
        }
        location  /demoapp3/ {
           default_type text/html;
           index index.html index.htm;
           rewrite ^/(demoapp)(\d*)/$ /$1$2/index.html break;
           proxy_set_header Host $http_host;
           proxy_set_header X-Forwarded-For $remote_addr;
           client_body_buffer_size 10M;
           client_max_body_size 10G;
           proxy_buffers 1024 4k;
           proxy_read_timeout 300;
           proxy_next_upstream error timeout http_404;
           proxy_pass http://s3app;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
  • 简单说明
    借用了对于前缀匹配,如果location 包含了/ 那么对于请求不带/ 会自动触发一个301 的重定向,同时按照s3桶的格式进行
    rewrite,比如上边的就是对于请求为 /demoapp/ /demoapp1/ .... 格式的页面自动重定向到/demoapp数字/index.html 的页面
    这样就解决了默认页面的问题,如果使用了openresty周边的产品那么我们可以方便的进行规则重写(基于openresty强大的
    生命周期能力)

访问参考效果

  • minio

注意都开启了* read only 的策略

 

 

  • nginx 访问效果

 

 


 

 

说明

以上是一个参考实践,从github 的issues上 理论上是可以配置禁止列表显示的(但是我们需要的是文件夹的列表),实际上也有直接通过精准匹配
进行重定向默认页面的,但是不是很灵活

参考资料

https://nginx.org/en/docs/http/ngx_http_core_module.html#location
https://docs.min.io/docs/setup-nginx-proxy-with-minio.html
https://github.com/minio/minio/issues/5279
https://stackoverflow.com/questions/46114783/how-to-proxy-pass-from-to-index-html

posted on 2020-12-06 19:41  荣锋亮  阅读(1247)  评论(0编辑  收藏  举报

导航