Skip to content

Commit 84ec514

Browse files
authored
chore: Improve nginx / docker config (#14)
1 parent a9dd302 commit 84ec514

6 files changed

Lines changed: 78 additions & 16 deletions

File tree

Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ WORKDIR /app
44

55
RUN apk add --no-cache git
66

7-
COPY . .
7+
COPY --exclude=node_modules . .
88
RUN npm ci
99

1010
RUN npm run build
1111

12-
FROM nginx:alpine
12+
FROM nginx:1-alpine
1313

1414
COPY --from=builder /app/dist/client /usr/share/nginx/html
1515

16-
COPY nginx.conf /etc/nginx/conf.d/default.conf
16+
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
17+
COPY ./docker/default.conf /etc/nginx/conf.d/default.conf
1718

18-
EXPOSE 80
19+
EXPOSE 8080
1920

2021
CMD ["nginx", "-g", "daemon off;"]

docker-compose.dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ services:
55
dockerfile: Dockerfile
66
container_name: orca-docs
77
ports:
8-
- "127.0.0.1:8080:80"
8+
- "127.0.0.1:8080:8080"
99
restart: unless-stopped

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ services:
33
image: orcacd/docs:latest
44
container_name: orca-docs
55
ports:
6-
- "127.0.0.1:8080:80"
6+
- "127.0.0.1:8080:8080"
77
restart: unless-stopped

docker/default.conf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
server {
2+
listen 8080;
3+
server_name localhost;
4+
root /usr/share/nginx/html;
5+
index index.html;
6+
7+
location / {
8+
9+
# Prevent duplicate routes with and without .html extension
10+
# Handle subdirectory index.html (e.g., /about/index.html -> /about)
11+
if ($request_uri ~ ^/(.+)/index(\.html)?(\?|$)) {
12+
return 301 /$1;
13+
}
14+
15+
# Handle root index.html (/index.html -> /)
16+
if ($request_uri ~ ^/index(\.html)?(\?|$)) {
17+
return 301 /;
18+
}
19+
20+
#Handle other .html files (e.g., /about.html -> /about)
21+
if ($request_uri ~ ^/(.*)\.html(\?|$)) {
22+
return 301 /$1;
23+
}
24+
25+
try_files $uri $uri/ /index.html;
26+
}
27+
28+
# assets, media
29+
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)$ {
30+
expires 7d;
31+
}
32+
33+
# svg, fonts
34+
location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
35+
expires 7d;
36+
}
37+
}

docker/nginx.conf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
user nginx;
2+
worker_processes auto;
3+
4+
error_log /var/log/nginx/error.log notice;
5+
pid /run/nginx.pid;
6+
7+
8+
events {
9+
multi_accept on;
10+
worker_connections 1024;
11+
}
12+
13+
14+
http {
15+
charset utf-8;
16+
sendfile on;
17+
tcp_nopush on;
18+
tcp_nodelay on;
19+
keepalive_timeout 65;
20+
21+
server_tokens off;
22+
log_not_found off;
23+
access_log off;
24+
25+
client_max_body_size 16M;
26+
27+
include /etc/nginx/mime.types;
28+
default_type application/octet-stream;
29+
30+
absolute_redirect off;
31+
port_in_redirect off;
32+
33+
include /etc/nginx/conf.d/*.conf;
34+
}

nginx.conf

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)