diff --git a/Dockerfile b/Dockerfile index 5132021..df19821 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,17 +4,18 @@ WORKDIR /app RUN apk add --no-cache git -COPY . . +COPY --exclude=node_modules . . RUN npm ci RUN npm run build -FROM nginx:alpine +FROM nginx:1-alpine COPY --from=builder /app/dist/client /usr/share/nginx/html -COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY ./docker/nginx.conf /etc/nginx/nginx.conf +COPY ./docker/default.conf /etc/nginx/conf.d/default.conf -EXPOSE 80 +EXPOSE 8080 CMD ["nginx", "-g", "daemon off;"] diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 22dd1be..b1bd587 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -5,5 +5,5 @@ services: dockerfile: Dockerfile container_name: orca-docs ports: - - "127.0.0.1:8080:80" + - "127.0.0.1:8080:8080" restart: unless-stopped diff --git a/docker-compose.yml b/docker-compose.yml index 6fc321c..78a3318 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,5 +3,5 @@ services: image: orcacd/docs:latest container_name: orca-docs ports: - - "127.0.0.1:8080:80" + - "127.0.0.1:8080:8080" restart: unless-stopped diff --git a/docker/default.conf b/docker/default.conf new file mode 100644 index 0000000..938e477 --- /dev/null +++ b/docker/default.conf @@ -0,0 +1,37 @@ +server { + listen 8080; + server_name localhost; + root /usr/share/nginx/html; + index index.html; + + location / { + + # Prevent duplicate routes with and without .html extension + # Handle subdirectory index.html (e.g., /about/index.html -> /about) + if ($request_uri ~ ^/(.+)/index(\.html)?(\?|$)) { + return 301 /$1; + } + + # Handle root index.html (/index.html -> /) + if ($request_uri ~ ^/index(\.html)?(\?|$)) { + return 301 /; + } + + #Handle other .html files (e.g., /about.html -> /about) + if ($request_uri ~ ^/(.*)\.html(\?|$)) { + return 301 /$1; + } + + try_files $uri $uri/ /index.html; + } + + # assets, media + location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ { + expires 7d; + } + + # svg, fonts + location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ { + expires 7d; + } +} diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..73f2bac --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,34 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /run/nginx.pid; + + +events { + multi_accept on; + worker_connections 1024; +} + + +http { + charset utf-8; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + + server_tokens off; + log_not_found off; + access_log off; + + client_max_body_size 16M; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + absolute_redirect off; + port_in_redirect off; + + include /etc/nginx/conf.d/*.conf; +} \ No newline at end of file diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index 1a30e15..0000000 --- a/nginx.conf +++ /dev/null @@ -1,10 +0,0 @@ -server { - listen 80; - server_name localhost; - root /usr/share/nginx/html; - index index.html; - - location / { - try_files $uri $uri/ /index.html; - } -} \ No newline at end of file