Skip to content

Instantly share code, notes, and snippets.

@zettca
Last active September 23, 2024 16:57
Show Gist options
  • Save zettca/bba8739695959883ce36e14599a3c669 to your computer and use it in GitHub Desktop.
Save zettca/bba8739695959883ce36e14599a3c669 to your computer and use it in GitHub Desktop.
nginx static file server
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
gzip on;
gzip_min_length 256;
gzip_types text/plain text/css application/javascript application/json;
location / {
autoindex on;
default_type text/html;
}
# Generic location for any sub-path
location ~ ^/([^/]+)/ {
try_files $uri /$1/index.html =404;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
@zettca
Copy link
Author

zettca commented Sep 23, 2024

Run for the public/ sub-directory with docker

docker run -d --name nginx-server -p 8000:80 \
  -v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf \
  -v $(pwd)/public:/usr/share/nginx/html \
  nginx:1.27-alpine

or with docker-compose:

services:
  nginx:
    image: nginx:1.27-alpine
    container_name: nginx-server
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
      - ./public:/usr/share/nginx/html
    ports:
      - "8000:80"

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