diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index fba79e9..153008d 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -4,14 +4,19 @@ services: nginx: build: context: ./nginx + dockerfile: Dockerfile.dev ports: - "80:80" + - "443:443" depends_on: - backend - frontend + volumes: + - certbot-www:/var/www/certbot/:ro + - certbot-conf:/etc/nginx/ssl/:ro networks: - lesser-net - + backend: build: context: ./backend @@ -28,7 +33,7 @@ services: - db networks: - lesser-net - + frontend: build: context: ./frontend @@ -52,3 +57,7 @@ networks: volumes: mysql_data: {} + certbot-www: + external: true + certbot-conf: + external: true diff --git a/docker-compose.yml b/docker-compose.yml index 9611cbe..cbfd26c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,14 +4,19 @@ services: nginx: build: context: ./nginx + dockerfile: Dockerfile.prod ports: - "80:80" + - "443:443" depends_on: - backend - frontend + volumes: + - certbot-www:/var/www/certbot/:ro + - certbot-conf:/etc/nginx/ssl/:ro networks: - lesser-net - + backend: build: context: ./backend @@ -26,7 +31,7 @@ services: - JWT_SECRET=${JWT_SECRET} networks: - lesser-net - + frontend: build: context: ./frontend @@ -35,4 +40,10 @@ services: networks: lesser-net: - external: true \ No newline at end of file + external: true + +volumes: + certbot-www: + external: true + certbot-conf: + external: true diff --git a/nginx/Dockerfile b/nginx/Dockerfile deleted file mode 100644 index 23c29df..0000000 --- a/nginx/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM nginx - -RUN rm -rf /etc/nginx/conf.d - -COPY conf /etc/nginx - -EXPOSE 80 - -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx/Dockerfile.dev b/nginx/Dockerfile.dev new file mode 100644 index 0000000..cb70a4e --- /dev/null +++ b/nginx/Dockerfile.dev @@ -0,0 +1,5 @@ +FROM nginx + +COPY conf/conf.d/dev.conf /etc/nginx/conf.d + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx/Dockerfile.prod b/nginx/Dockerfile.prod new file mode 100644 index 0000000..a46db41 --- /dev/null +++ b/nginx/Dockerfile.prod @@ -0,0 +1,5 @@ +FROM nginx + +COPY conf/conf.d/prod.conf /etc/nginx/conf.d + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx/conf/conf.d/dev.conf b/nginx/conf/conf.d/dev.conf new file mode 100644 index 0000000..aa8fad5 --- /dev/null +++ b/nginx/conf/conf.d/dev.conf @@ -0,0 +1,43 @@ +server { + listen 80; + listen [::]:80; + + server_name dev.lesser-project.site; + server_tokens off; + + location /.well-known/acme-challenge/ { + root /var/www/certbot; + } + + location / { + return 301 https://dev.lesser-project.site$request_uri; + } +} + +server { + listen 443 ssl; + listen [::]:443 ssl; + + server_name dev.lesser-project.site; + + ssl_certificate /etc/nginx/ssl/live/dev.lesser-project.site/fullchain.pem; + ssl_certificate_key /etc/nginx/ssl/live/dev.lesser-project.site/privkey.pem; + + location / { + proxy_pass http://frontend:5000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + + location /api { + proxy_pass http://backend:3000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } +} \ No newline at end of file diff --git a/nginx/conf/conf.d/default.conf b/nginx/conf/conf.d/prod.conf similarity index 56% rename from nginx/conf/conf.d/default.conf rename to nginx/conf/conf.d/prod.conf index 61a7d0b..751d602 100644 --- a/nginx/conf/conf.d/default.conf +++ b/nginx/conf/conf.d/prod.conf @@ -1,6 +1,27 @@ server { - server_name lesser-project.site; listen 80; + listen [::]:80; + + server_name lesser-project.site; + server_tokens off; + + location /.well-known/acme-challenge/ { + root /var/www/certbot; + } + + location / { + return 301 https://lesser-project.site$request_uri; + } +} + +server { + listen 443 ssl; + listen [::]:443 ssl; + + server_name lesser-project.site; + + ssl_certificate /etc/nginx/ssl/live/lesser-project.site/fullchain.pem; + ssl_certificate_key /etc/nginx/ssl/live/lesser-project.site/privkey.pem; location / { proxy_pass http://frontend:5000;