Skip to content

Instantly share code, notes, and snippets.

@gilangvperdana
Forked from harshavardhana/nginx-minio-static.md
Last active December 19, 2023 00:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilangvperdana/f74a07a5da66303acb644c3aa2b3a221 to your computer and use it in GitHub Desktop.
Save gilangvperdana/f74a07a5da66303acb644c3aa2b3a221 to your computer and use it in GitHub Desktop.
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

  • Add Minio
mc config host add <ALIAS> <YOUR-S3-ENDPOINT> <YOUR-ACCESS-KEY> <YOUR-SECRET-KEY>
mc config host list

4. Create a bucket:

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

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

$ mc anonymous set 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

Reference

@almereyda
Copy link

almereyda commented Dec 18, 2023

There is now also an officially supported Nginx example with S3 backend upstream available at:

@gilangvperdana
Copy link
Author

There is now also an officially supported Nginx example with S3 backend upstream available at:

Cool, thanks for your information, sir!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment