Skip to content

Commit 2332971

Browse files
committed
Add custom nginx.conf for serving single page application
1 parent c5cbc4a commit 2332971

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# syntax=docker.io/docker/dockerfile:1.7-labs
2+
# ^this line above must be the first line - it enables the --exclude flag for COPY
3+
14
# Use Node.js runtime as builder base image.
25
# Since the built app is platform-agnostic, we use the host architecture
36
# even if we are cross-building the image.
@@ -10,9 +13,9 @@ COPY package*.json ./
1013
RUN npm install
1114

1215
# Build LUNA for production
13-
COPY . .
16+
COPY --exclude=nginx.conf . .
1417

15-
ARG DEPLOYMENT_ENVIRONMENT=prod
18+
ARG DEPLOYMENT_ENVIRONMENT=production
1619
ENV DEPLOYMENT_ENVIRONMENT ${DEPLOYMENT_ENVIRONMENT}
1720

1821
RUN npm run build:$DEPLOYMENT_ENVIRONMENT
@@ -22,6 +25,7 @@ FROM nginx:alpine
2225

2326
# Copy bundled app to Nginx' default directory
2427
COPY --from=builder /opt/luna/build /usr/share/nginx/html
28+
COPY nginx.conf /etc/nginx/nginx.conf
2529

2630
EXPOSE 80
2731

nginx.conf

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
user nginx;
2+
worker_processes auto;
3+
4+
error_log /var/log/nginx/error.log notice;
5+
pid /var/run/nginx.pid;
6+
7+
events {
8+
worker_connections 1024;
9+
}
10+
11+
http {
12+
include /etc/nginx/mime.types;
13+
# default_type application/octet-stream;
14+
15+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
16+
'$status $body_bytes_sent "$http_referer" '
17+
'"$http_user_agent" "$http_x_forwarded_for"';
18+
19+
access_log /var/log/nginx/access.log main;
20+
21+
sendfile on;
22+
#tcp_nopush on;
23+
24+
keepalive_timeout 65;
25+
26+
server {
27+
listen 80;
28+
listen [::]:80;
29+
server_name localhost;
30+
31+
access_log /var/log/nginx/access.log main;
32+
33+
# gzip on;
34+
# gzip_types text/html application/javascript application/json text/css;
35+
36+
root /usr/share/nginx/html;
37+
index index.html;
38+
39+
location / {
40+
default_type text/html;
41+
try_files $uri $uri/ $uri.html /index.html;
42+
}
43+
44+
# In case we want to cache js, css and images for longer:
45+
# location ~* \.(?:css|js|jpg|svg)$ {
46+
# expires 30d;
47+
# add_header Cache-Control "public";
48+
# }
49+
50+
#error_page 404 /404.html;
51+
52+
# redirect server error pages to the static page /50x.html
53+
#
54+
error_page 500 502 503 504 /50x.html;
55+
location = /50x.html {
56+
root /usr/share/nginx/html;
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)