Minio: ecosystem: Add a caddy plugin to serve static files from Minio server.

Created on 2 Nov 2016  ·  5Comments  ·  Source: minio/minio

Expected Behavior

Serve static assets for serving index.html without the need or S3 API.

Current Behavior

Cannot serve static assets like web-hosting even after setting buckets as public.

Possible Solution

Write a new plugin for Caddy which can serve files directly from Minio.

Context

This affects all deployments where users want to use Minio but want to serve another endpoint where they can serve their website as well.

community low wont fix

Most helpful comment

In case anyone comes across this ticket wanting more of a clue about hosting a static site (in this example hugo) from minio via caddy here's my personal notes on what worked for me:

Serve static pages from minio through caddy

Assumptions:

  • caddy version (tested): 0.11.1
  • minio version (tested): `2019-01-10T00:21:20Z'
  • world facing domain URL is: http://localtest.me

    • add to hosts file if paranoid

      127.0.0.1 localtest.me

  • minio data storage directory: /data
  • minio static website bucket: /site
  • minio static website bucket index.html object: site/index.html
  • url for the local minio site/index.html instance object: http://localhost:9000/site/index.html
  • mc (the minio client) is configured as such for this minio instance:
    mc config host add myminio http://127.0.0.1:9000 <AccessKey> <SecretKey>

General procedure:

  1. start mnio server:
    ./minio server --address localhost:9000 /data
  2. create site bucket in minio
    mc mb myminio/site
  3. configure object folder for download policy
    mc policy download myminio/site
  4. copy files into site
    # example mc cp --recursive ~/MyHugoProject/public/* myminio/site/
  5. configure caddy config file Caddyfile
    http://localtest.me/myhugosite { rewrite / { r ^.*/$ to {path} {path}/ {dir}/index.html } proxy / http://localhost:9000/site/ { #transparent #superfluious } }
  6. restart caddy
  7. test static site deployment: http://localtest.me/myhugosite

All 5 comments

Alternative workarounds can address the requirement here. Eg. nginx + read-only bucket policy.

In case anyone comes across this ticket wanting more of a clue about hosting a static site (in this example hugo) from minio via caddy here's my personal notes on what worked for me:

Serve static pages from minio through caddy

Assumptions:

  • caddy version (tested): 0.11.1
  • minio version (tested): `2019-01-10T00:21:20Z'
  • world facing domain URL is: http://localtest.me

    • add to hosts file if paranoid

      127.0.0.1 localtest.me

  • minio data storage directory: /data
  • minio static website bucket: /site
  • minio static website bucket index.html object: site/index.html
  • url for the local minio site/index.html instance object: http://localhost:9000/site/index.html
  • mc (the minio client) is configured as such for this minio instance:
    mc config host add myminio http://127.0.0.1:9000 <AccessKey> <SecretKey>

General procedure:

  1. start mnio server:
    ./minio server --address localhost:9000 /data
  2. create site bucket in minio
    mc mb myminio/site
  3. configure object folder for download policy
    mc policy download myminio/site
  4. copy files into site
    # example mc cp --recursive ~/MyHugoProject/public/* myminio/site/
  5. configure caddy config file Caddyfile
    http://localtest.me/myhugosite { rewrite / { r ^.*/$ to {path} {path}/ {dir}/index.html } proxy / http://localhost:9000/site/ { #transparent #superfluious } }
  6. restart caddy
  7. test static site deployment: http://localtest.me/myhugosite

You may also consider using Nginx https://gist.github.com/harshavardhana/f05b60fe6f96803743f38bea4b565bbf

Ubuntu 16.04

  1. Install nginx
  2. Install minio
  3. Install mc client
  4. Create a bucket:
$ mc mb myminio/static
Bucket created successfully ‘myminio/static’.
  1. Make bucket public to host/access static content.
$ mc policy download myminio/static
Access permission for ‘myminio/static’ is set to ‘download’
  1. Upload a sample static HTML site to minio bucket, in my case i used example: http://www.oswd.org/user/profile/id/12362/
$ mc cp -r terrafirma/ myminio/static
...ma/readme.txt:  39.37 KB / 39.37 KB ┃▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┃ 100.00% 31.94 KB/s 1s

Note: this is how my bucket content appears to me currently.

$ mc ls myminio/static
[2017-03-22 18:20:52 IST] 4.7KiB default.css
[2017-03-22 18:20:54 IST] 5.4KiB index.html
[2017-03-22 18:20:54 IST]   612B readme.txt
[2017-03-22 18:24:03 IST]     0B images/
  1. Configure Nginx as proxy to serve static pages from public bucket name static from Minio.

Remove default configuration and replace it with the below. Please change as per your local setup.

$ cat /etc/nginx/sites-enabled/default 
server {
 listen 80;
 server_name localhost;
 location / {
   rewrite ^/$ /static/index.html break;
   proxy_set_header Host $http_host;
   proxy_pass http://localhost:9000/static/;
 }
}

$ sudo service nginx reload
  1. Open your browser and type http://localhost

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings