Skip to content

Commit 2c7236d

Browse files
committed
Add nginx configuration for serving static files with gzip and security headers, and copy config into Docker image
1 parent 4ad2230 commit 2c7236d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
FROM nginx:alpine
22

3+
COPY nginx.conf /etc/nginx/conf.d/default.conf
34
COPY dist /usr/share/nginx/html

nginx.conf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
root /usr/share/nginx/html;
5+
index index.html;
6+
7+
# Enable gzip compression
8+
gzip on;
9+
gzip_vary on;
10+
gzip_min_length 1024;
11+
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
12+
13+
# Security headers
14+
add_header X-Frame-Options "SAMEORIGIN" always;
15+
add_header X-Content-Type-Options "nosniff" always;
16+
add_header X-XSS-Protection "1; mode=block" always;
17+
18+
# Custom 404 page
19+
error_page 404 /404.html;
20+
21+
location / {
22+
try_files $uri $uri/ $uri.html =404;
23+
}
24+
25+
# Cache static assets
26+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
27+
expires 1y;
28+
add_header Cache-Control "public, immutable";
29+
}
30+
}

0 commit comments

Comments
 (0)