feat: added nginx container

This commit is contained in:
Sergey Yarkov 2022-03-21 23:57:00 +03:00
parent 2a4197ab42
commit 1a66780399
3 changed files with 29 additions and 2 deletions

View File

@ -1,8 +1,18 @@
version: '3.8' version: '3.8'
services: services:
nginx:
container_name: nginx
restart: always
image: nginx:latest
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
ports:
- 80:80
depends_on:
- backend
backend: backend:
container_name: node-docker-example container_name: nodejs
restart: always restart: always
build: build:
context: . context: .

2
env.js
View File

@ -6,7 +6,7 @@ if (process.env.NODE_ENV !== 'production') {
const env = { const env = {
app: { app: {
port: parseInt(process.env.PORT, 10), port: parseInt(process.env.PORT, 10) || 4000,
}, },
db: { db: {
user: process.env.PG_USER.toString(), user: process.env.PG_USER.toString(),

17
nginx/default.conf Normal file
View File

@ -0,0 +1,17 @@
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://nodejs:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
}