Skip to content

Instantly share code, notes, and snippets.

@pdonorio
Created September 19, 2015 14:14
Show Gist options
  • Save pdonorio/ab00442f5829abffdf0b to your computer and use it in GitHub Desktop.
Save pdonorio/ab00442f5829abffdf0b to your computer and use it in GitHub Desktop.
Nginx for serving your current directory static HTML locally in one command

How to provide a quick web server to test your static content

Warning: this is going to work for a fish shell on a Mac host.

Add the function to your fish shell, e.g.

source serve_static_web_docker.fish

Then go to your path (warning, make sure there is an index.html file)

cd my/path/to/html
serve

Your browser will open the page and your terminal will show logs from nginx.

function serve
# Remove image if exists
docker rm -f webservestatic
# Launch nginx
docker run -d -v (pwd):/usr/share/nginx/html --name webservestatic -p 80:80 nginx
# Remove caching related to Vitualbox
docker exec -it webservestatic bash -c "sed -i 's/localhost;/localhost;\n\tsendfile off;/' /etc/nginx/conf.d/default.conf && nginx -s reload"
# Open web 'localhost' or (docker-machine ip dev), it depends
open http://(boot2docker ip) &
# Show logs
docker logs -f webservestatic
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment