Skip to content

Commit 8b7fb52

Browse files
authored
Merge pull request #4 from ResEmCode/infra/docker-nginx
Infra/docker nginx
2 parents b46c852 + 8347e37 commit 8b7fb52

16 files changed

+200
-73
lines changed

infra/conf.d/default.conf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
upstream nest_api {
3+
server nest-api:3000;
4+
}
5+
6+
server {
7+
8+
listen 80;
9+
server_name localhost;
10+
11+
12+
root /usr/share/nginx/html;
13+
index index.html;
14+
15+
16+
location / {
17+
try_files $uri $uri/ /index.html;
18+
}
19+
20+
21+
location /assets/ {
22+
expires 1y;
23+
add_header Cache-Control "public, immutable";
24+
access_log off;
25+
}
26+
27+
28+
location /api/ {
29+
30+
proxy_pass http://nest_api;
31+
32+
33+
proxy_http_version 1.1;
34+
proxy_set_header Host $host;
35+
proxy_set_header X-Real-IP $remote_addr;
36+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
37+
proxy_set_header X-Forwarded-Proto $scheme;
38+
39+
40+
proxy_connect_timeout 60s;
41+
proxy_send_timeout 60s;
42+
proxy_read_timeout 60s;
43+
}
44+
45+
46+
error_page 500 502 503 504 /50x.html;
47+
location = /50x.html {
48+
root /usr/share/nginx/html;
49+
}
50+
}

infra/docker-compose.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11

22
services:
33
postgres:
4-
image: postgres:15
4+
image: postgres:15-alpine
55
container_name: postgres
66
restart: always
77
env_file:
88
- .env
99
volumes:
1010
- postgres:/var/lib/postgresql/data
11+
networks:
12+
- app-network
1113

12-
api:
14+
nest-api:
1315
build:
1416
context: ../server
1517
dockerfile: Dockerfile
@@ -20,6 +22,30 @@ services:
2022
- "3001:3000"
2123
depends_on:
2224
- postgres
25+
networks:
26+
- app-network
27+
28+
29+
30+
nginx:
31+
image: fholzer/nginx-brotli
32+
container_name: lango-nginx
33+
restart: always
34+
ports:
35+
- "8080:80"
36+
volumes:
37+
- ./nginx.conf:/etc/nginx/nginx.conf:ro
38+
- ./conf.d:/etc/nginx/conf.d:ro
39+
- ../client/dist:/usr/share/nginx/html:ro
40+
41+
depends_on:
42+
- nest-api
43+
networks:
44+
- app-network
45+
46+
networks:
47+
app-network:
48+
driver: bridge
2349

2450
volumes:
2551
postgres:

infra/nginx.conf

Lines changed: 37 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,48 @@
1-
server {
2-
listen 80;
3-
server_name _;
1+
user nginx;
2+
worker_processes auto;
3+
error_log /var/log/error.log warn;
4+
pid /var/run/nginx.pid;
45

5-
root /usr/share/nginx/html;
6-
index index.html;
7-
client_max_body_size 25m;
86

7+
events{
8+
worker_connections 1024; # 10240 prod
9+
multi_accept on;
10+
}
911

10-
location / {
11-
try_files $uri $uri/ /index.html;
12-
}
12+
http {
1313

14-
location /assets/ {
15-
expires 1y;
16-
add_header Cache-Control "public, immutable";
17-
try_files $uri =404;
18-
}
14+
include /etc/nginx/mime.types;
15+
default_type application/octet-stream;
1916

20-
location = /index.html {
21-
add_header Cache-Control "no-cache";
22-
}
17+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
18+
'$status $body_bytes_sent "$http_referer" '
19+
'"$http_user_agent" "$http_x_forwarded_for"';
20+
access_log /var/log/nginx/access.log main;
2321

24-
location /api/ {
25-
proxy_pass http://backend:3000/;
26-
proxy_http_version 1.1;
22+
sendfile on;
23+
tcp_nopush on;
24+
tcp_nodelay on;
25+
keepalive_timeout 65;
26+
types_hash_max_size 2048;
2727

28-
proxy_set_header Host $host;
29-
proxy_set_header X-Real-IP $remote_addr;
30-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
31-
proxy_set_header X-Forwarded-Proto $scheme;
28+
server_tokens off;
3229

33-
proxy_connect_timeout 10s;
34-
proxy_send_timeout 60s;
35-
proxy_read_timeout 60s;
36-
}
30+
gzip on;
31+
gzip_comp_level 5;
32+
gzip_types text/plain text/css application/javascript application/json;
3733

38-
brotli on;
39-
brotli_comp_level 5;
40-
brotli_static on;
41-
brotli_types
42-
text/plain
43-
text/css
44-
application/javascript
45-
application/json
46-
application/xml
47-
image/svg+xml
48-
font/ttf
49-
font/otf
50-
font/woff
51-
font/woff2;
5234

53-
gzip on;
54-
gzip_static on;
55-
gzip_vary on;
56-
gzip_proxied any;
57-
gzip_comp_level 6;
58-
gzip_min_length 1024;
59-
gzip_types
60-
text/plain
61-
text/css
62-
application/javascript
63-
application/json
64-
application/xml
65-
image/svg+xml
66-
font/ttf
67-
font/otf
68-
font/woff
69-
font/woff2;
35+
brotli on;
36+
brotli_comp_level 5;
37+
brotli_static on;
38+
brotli_types
39+
text/plain
40+
text/css
41+
application/javascript
42+
application/json
43+
image/svg+xml
44+
font/ttf
45+
font/otf;
7046

71-
server_tokens off;
72-
}
47+
include /etc/nginx/conf.d/*.conf;
48+
}

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/Dockerfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
FROM node:20-alpine as builder
21

3-
#Create app dir
2+
FROM node:20-alpine as builder
43

54
WORKDIR /app
65

76
COPY package*.json ./
87
COPY prisma ./prisma/
98

10-
RUN npm ci && npm cache clean --force
9+
10+
RUN npm ci && npx prisma generate
1111

1212
COPY . .
1313

14-
RUN npm run build
14+
15+
RUN npm run build && npm cache clean --force
1516

1617
FROM node:20-alpine
1718

@@ -20,8 +21,10 @@ WORKDIR /app
2021
COPY --from=builder --chown=node:node /app/node_modules ./node_modules
2122
COPY --from=builder --chown=node:node /app/package*.json ./
2223
COPY --from=builder --chown=node:node /app/dist ./dist
24+
COPY --from=builder --chown=node:node /app/prisma ./prisma
2325

2426
USER node
2527

2628
EXPOSE 3000
27-
CMD ["npm", "run","start:prod"]
29+
30+
CMD ["node", "dist/src/main"]

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"start": "nest start",
1212
"start:dev": "nest start --watch",
1313
"start:debug": "nest start --debug --watch",
14-
"start:prod": "node dist/main",
14+
"start:prod": "node dist/src/main",
1515
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
1616
"test": "jest",
1717
"test:watch": "jest --watch",

server/prisma/generated/prisma/browser.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/prisma/generated/prisma/client.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/prisma/prisma.service.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { PrismaClient } from './generated/prisma/client';
2+
export declare class PrismaService extends PrismaClient {
3+
constructor();
4+
}

server/prisma/prisma.service.js

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)