欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Nginx 配置 MinIO 访问指南:从单机到集群的最佳实践

最编程 2024-10-07 07:06:23
...

Nginx 配置 MinIO 访问指南:从单机到集群的最佳实践

文章目录

  • Nginx 配置 MinIO 访问指南:从单机到集群的最佳实践
        • Nginx 配置 MinIO 访问指南:从单机到集群的最佳实践
          • 一 单机配置
          • 二 集群配置

本文详细介绍了如何通过 Nginx 配置来访问和管理 MinIO 存储服务,涵盖了单机和集群两种部署模式的配置方法。在单机配置部分,您将学习如何通过 Nginx 代理将请求转发至 MinIO 实例,实现存储桶的访问。在集群配置部分,本文展示了如何在多个 MinIO 实例和控制台之间进行负载均衡,确保高可用性和可扩展性。文章包含了详尽的 Nginx 配置示例和注释,帮助读者快速掌握 MinIO 与 Nginx 集成的核心技术。

预备课

Docker 安装与配置:从入门到部署

Docker 环境下安装和配置 Nginx 实践

Docker 安装与配置单机多磁盘 MinIO:高效存储解决方案

Nginx 配置 MinIO 访问指南:从单机到集群的最佳实践

修改 default.conf 文件

一 单机配置
 upstream minio {
    server yourminioip:9000;
 }

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;


    location / {
        root   /usr/share/nginx/html;
        index  /index.html /index.htm;
    }

    location /bucket/ {
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;

      proxy_connect_timeout 300;
      # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
      proxy_http_version 1.1;
      proxy_set_header Connection "";
      chunked_transfer_encoding off;

      proxy_pass http://minio;
    }
}
二 集群配置

这个是基于 nginx.conf 编写的,可以改为 default.conf 的配置。

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid     /var/run/nginx.pid;

events {
  worker_connections  4096;
}

http {
  include    /etc/nginx/mime.types;
  default_type  application/octet-stream;

  log_format main '$remote_addr - $remote_user [$time_local] "$request" '
           '$status $body_bytes_sent "$http_referer" '
           '"$http_user_agent" "$http_x_forwarded_for"';

  access_log  /var/log/nginx/access.log  main;
  sendfile     on;
  keepalive_timeout  65;

  # include /etc/nginx/conf.d/*.conf;

  upstream minio {
    server 192.168.0.1:9000;
    server 192.168.0.2:9000;
    server 192.168.0.3:9000;
    server 192.168.0.4:9000;
   }

  upstream console {
    ip_hash;
    server 192.168.0.1:9001;
    server 192.168.0.2:9001;
    server 192.168.0.3:9001;
    server 192.168.0.4:9001;
   }

  server {
    listen    9000;
    listen  [::]:9000;
    server_name  localhost;

    # To allow special characters in headers
    ignore_invalid_headers off;
    # Allow any size file to be uploaded.
    # Set to a value such as 1000m; to restrict file size to a specific value
    client_max_body_size 0;
    # To disable buffering
    proxy_buffering off;
    proxy_request_buffering off;

    location / {
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;

      proxy_connect_timeout 300;
      # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
      proxy_http_version 1.1;
      proxy_set_header Connection "";
      chunked_transfer_encoding off;

      proxy_pass http://minio;
     }
   }

  server {
    listen    9001;
    listen  [::]:9001;
    server_name  localhost;

    # To allow special characters in headers
    ignore_invalid_headers off;
    # Allow any size file to be uploaded.
    # Set to a value such as 1000m; to restrict file size to a specific value
    client_max_body_size 0;
    # To disable buffering
    proxy_buffering off;
    proxy_request_buffering off;

    location / {
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-NginX-Proxy true;

      # This is necessary to pass the correct IP to be hashed
      real_ip_header X-Real-IP;

      proxy_connect_timeout 300;
      
      # To support websocket
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      
      chunked_transfer_encoding off;

      proxy_pass http://console;
     }
   }
}

推荐阅读