Skip to content

Instantly share code, notes, and snippets.

@syedmhashim
Last active February 29, 2024 06:41
Show Gist options
  • Save syedmhashim/86afb7ef7a10a1e15dbc481c0cdd1adf to your computer and use it in GitHub Desktop.
Save syedmhashim/86afb7ef7a10a1e15dbc481c0cdd1adf to your computer and use it in GitHub Desktop.
Serve static build using nginx
version: '3.1'
services:
web:
image: nginx
volumes:
- $PWD:/usr/share/nginx/html
- $HOME/mystuff/docker/nginx/nginx.conf:/etc/nginx/nginx.conf
ports:
- "8080:80"
events {
worker_connections 1024;
}
http{
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
@syedmhashim
Copy link
Author

Add the following function to .zshrc or .bashrc file:

  function website-up() {
          docker-compose -f $HOME/mystuff/docker/nginx/docker-compose.yaml up
          docker-compose -f $HOME/mystuff/docker/nginx/docker-compose.yaml down
  }

Now you can run website-up command in any directory to serve it on localhost:8080.

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