From bfe5dc6ff872cdb4911e834e56e53530a33a6fe4 Mon Sep 17 00:00:00 2001 From: Hubert Van De Walle Date: Thu, 30 Apr 2020 14:50:37 +0200 Subject: [PATCH] Add nginx container --- docker-compose.yml | 17 +++++++++++++++++ frontend/plugins/axios.js | 2 +- nginx/nginx.conf | 33 +++++++++++++++++++++++++++++++++ nginx/server.conf | 28 ++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 nginx/nginx.conf create mode 100644 nginx/server.conf diff --git a/docker-compose.yml b/docker-compose.yml index 6a21885..6aabbda 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,22 @@ version: '2.2' services: + nginx: + image: nginx:latest + container_name: notes-nginx + environment: + - PUID=1000 + - PGID=1000 + - TZ=Europe/Brussels + volumes: + - ./frontend/dist:/usr/share/nginx/html + - ./nginx/nginx.conf:/etc/nginx/nginx.conf + - ./nginx/server.conf:/etc/nginx/server.conf + ports: + - 80:80 + - 443:443 + + db: image: mariadb container_name: notes-mariadb @@ -24,6 +40,7 @@ services: build: ./api container_name: notes-api ports: + # This is only for testing - 8081:8081 env_file: - .env diff --git a/frontend/plugins/axios.js b/frontend/plugins/axios.js index c8c4384..661a171 100644 --- a/frontend/plugins/axios.js +++ b/frontend/plugins/axios.js @@ -3,5 +3,5 @@ export default function ({ $axios }) { console.log('Making request to ' + config.url) }) - $axios.setBaseURL('http://localhost:8081') + $axios.setBaseURL(process.env.API_URL) } diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..22e53f6 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,33 @@ + +user nginx; +worker_processes 1; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + #gzip on; + + include /etc/nginx/server.conf; +} + diff --git a/nginx/server.conf b/nginx/server.conf new file mode 100644 index 0000000..c5a171f --- /dev/null +++ b/nginx/server.conf @@ -0,0 +1,28 @@ +server { + listen 80; + server_name localhost; + + #charset koi8-r; + #access_log /var/log/nginx/host.access.log main; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + location /api/ { + rewrite ^/api/(.*) /$1 break; + proxy_pass http://api:8081/; + } + +} +