nginx proxy minio 默认页配置(二)

前边有写过一个配置死的默认default 页面处理,以下是一个相对通用的nginx 集成minio 的默认页面配置

基本原理

核心原理还是url rewrite, 只是这次全部都放到了default 的location,同时使用了两次url rewrite
一次是添加/ 一次是进行s3 bukcet 匹配,同时替换模版的s3 list 页面,替换为自己的index.html

参考nginx 配置

  • nginx.conf
 
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 / {
           default_type text/html;
           index index.html index.htm;
           rewrite ^/([a-zA-Z0-9]+)$ $1/ permanent;
           rewrite ^/([a-zA-Z0-9]+)/$ /$1/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;
        }
    }
}
  • 一些说明
    上边对于s3 bukcet 的命名需要是字母以及数字,首先一次rewrite 添加/ 然后是配置,添加index.html 对于其他的按照正常的url 请求就可以了
    同时需要注意minio 配置桶的策略 * read only

参考资料

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
https://stackoverflow.com/questions/645853/add-slash-to-the-end-of-every-url-need-rewrite-rule-for-nginx

原文地址:https://www.cnblogs.com/rongfengliang/p/14094424.html