diff --git a/Dockerfile b/Dockerfile index f9cdd8f..e4159be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,17 @@ -FROM alpine:latest +FROM nginx:1.23.3-alpine -# Install thttpd -RUN apk add --no-cache thttpd +# Remove the default Nginx configuration +RUN rm -rf /etc/nginx/conf.d/ -# Create a non-root user to own the files and run our server -RUN adduser -D static -USER static -WORKDIR /home/static +# Copy our Nginx configuration +COPY nginx.conf /etc/nginx/ # Copy the static website # Use the .dockerignore file to control what ends up inside the image! -COPY public . +COPY public /usr/share/nginx/html/ -# Run thttpd -CMD ["thttpd", "-D", "-h", "0.0.0.0", "-p", "3000", "-d", "/home/static", "-u", "static", "-l", "-", "-M", "60"] +# Expose port 80 +EXPOSE 3000 -EXPOSE 3000 \ No newline at end of file +# Start Nginx +CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx.conf b/nginx.conf index e69de29..f0f92c4 100644 --- a/nginx.conf +++ b/nginx.conf @@ -0,0 +1,46 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + access_log /var/log/nginx/access.log ; + error_log /var/log/nginx/error.log; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + server { + listen 3000; + listen [::]:3000; + + server_name localhost; + root /usr/share/nginx/html; + index index.html; + + # error_page + error_page 404 403 500 502 503 504 /assets/page/oops.htm; + + # Rename cheatsheet + rewrite ^/golang$ /go permanent; + + # remove .html extension + location / { + if ($request_uri ~ ^/(.*)\.html) { + return 302 /$1; + } + try_files $uri $uri.html $uri/ =404; + } + } +}