Skip to content

Commit 552e00b

Browse files
authored
Fix nginx config (#240)
* Add custom Nginx configuration to Dockerfile * Add basic Nginx configuration with caching and security
1 parent 0b722bb commit 552e00b

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ RUN npm run build
1313
FROM nginx:stable-alpine
1414

1515
COPY --from=builder /app/build /usr/share/nginx/html
16+
COPY nginx.conf /etc/nginx/conf.d/default.conf
1617

1718
EXPOSE 80
1819

19-
CMD ["nginx", "-g", "daemon off;"]
20+
CMD ["nginx", "-g", "daemon off;"]

nginx.conf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
root /usr/share/nginx/html;
5+
index index.html;
6+
7+
location / {
8+
try_files $uri $uri/ /index.html;
9+
}
10+
11+
# 静态资源缓存
12+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
13+
expires 1y;
14+
add_header Cache-Control "public, immutable";
15+
}
16+
17+
# 安全 headers
18+
add_header X-Content-Type-Options "nosniff" always;
19+
add_header X-Frame-Options "SAMEORIGIN" always;
20+
add_header Referrer-Policy "origin-when-cross-origin" always;
21+
add_header Strict-Transport-Security "max-age=2592000" always;
22+
}

0 commit comments

Comments
 (0)