Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to configure static website using Nginx with MinIO ?

How to configure static website using Nginx with MinIO ?

1. Install nginx

2. Install minio

3. Install mc client

4. Create a bucket:

$ mc mb myminio/static
Bucket created successfully ‘myminio/static’.

5. Make bucket public to host/access static content.

$ mc policy download myminio/static
Access permission for ‘myminio/static’ is set to ‘download’

6. 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/

7. 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

8. Open your browser and type http://localhost

@gatspy

This comment has been minimized.

Copy link

commented Mar 16, 2019

step 5, is very important...

@bachnxhedspi

This comment has been minimized.

Copy link

commented Jun 11, 2019

Hi @harshavardhana,

The error page of minio will be served as default; do you know about how to specific a file to be a custom error page (like 404).

@harshavardhana

This comment has been minimized.

Copy link
Owner Author

commented Jun 11, 2019

@bachnxhedspi - you may consult nginx docs for that

@Gordonei

This comment has been minimized.

Copy link

commented Sep 2, 2019

Just a note on a subtly I encountered while getting this up and running - MIME type of the file in Minio matters.

By default, the minio client does the right thing (i.e. as described in these instructions), but if you're uploading via something like the Python client, it defaults to everything being application/octet-stream. If you have a web page you want to serve up, MIME type for that file will need to be text/html, CSS files will need to be text/css, etc.

@harshavardhana

This comment has been minimized.

Copy link
Owner Author

commented Sep 2, 2019

If you use a tool like mc tries to set mime type for most common types appropriately..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.