Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

amazon s3 - S3 virtual-host style nginx configuration for subdomains

I am trying to get a min.io server up and running with virtual-host style and am failing to configure nginx to do so correctly.

Expected result

bucket.s3.domain.com works to access bucket

Actual result

bucket.s3.domain.com is redirected to s3.domain.com/bucket – this does not generate virtual host style URLs.

My config (I omitted default port 80 to 443 redirect and other not relevant docker containers):

     http {
         upstream minio-s3 {
      server 127.0.0.1:9000;

     }

server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/s3.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/s3.domain.com/privkey.pem;
server_name s3.domain.com;
location / {
proxy_pass http://minio-s3;

}

}

server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/s3.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/s3.domain.com/privkey.pem;
server_name "~^(?<subdomain>[^.]+).s3.domain.com";
location / {
proxy_pass http://127.0.0.1/$subdomain$request_uri;
proxy_set_header Host s3.domain.com;

}

}

Notes

Nginx running on Ubuntu Server LTS 20.04 (no Docker) Min.io running on Docker port 9000

MINIO_DOMAIN is correctly set to s3.domain.com bucket subdomain is correctly set wildcard certificate for *.s3.domain.com is configured

Questions

  • How can I configure Min.io (besides passing env MINIO_DOMAIN) to use virtual host style URLs together with nginx?
  • How can I set up nginx to support this case?
question from:https://stackoverflow.com/questions/66053177/s3-virtual-host-style-nginx-configuration-for-subdomains

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

So the answer to my original question is pretty simple:

Only one server block is needed, the subdomain regex is added to the server name and min.io resolves this correctly

server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/s3.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/s3.domain.com/privkey.pem;
server_name "~^(?<subdomain>[^.]+).s3.domain.com" s3.domain.com;
location / {
proxy_pass http://minio-s3;

I hope this helps someone struggling with the same. Virtual host in in short with Min.io:

  1. Register domain, subdomain (per bucket)
  2. Point domains all to your server (CNAME etc.)
  3. Generate certificates with certbot (domain, wildcard for subdomains)
  4. Launch min.io passing MINIO_DOMAIN as environment variable
  5. Point all domains to Min.io application (domain and subdomains)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...