Programster's Blog

Tutorials focusing on Linux, programming, and open source

Static Web Hosting With Nginx And Docker

If you need to host some static content online, then you can do this incredibly easily with the pre-prepared official NGINX docker image.

Steps

Install docker on your server if you haven't already.

Navigate to just above the folder that contains your site. For this tutorial, I will refer to it as my-site.

Run the following command to run your site in NGINX.

docker run -d \
--name $CONTAINER_NAME \
-p 80:80 \
-v `pwd`/my-site:/usr/share/nginx/html:ro \
nginx

Your site is now online!

If you need to tweak the nginx configuration, such as to enable directory listings, create an nginx.conf file. Then use this command instead.

docker run -d \
--name $CONTAINER_NAME \
-p 80:80 \
-v `pwd`/my-site:/usr/share/nginx/html:ro \
-v `pwd`/nginx.conf:/etc/nginx/nginx.conf:ro \
nginx

Quick Cheat

If that sounded a little bit like too much effort, I have tried to simplify things for you with a public Github repository. All you have to do is clone/download the repository and dump your site into the folder called content. If you wish to edit the nginx configuration, you will find the config file within the config folder. Then simply execute the run.sh script to start your site.