diff --git a/Transcendence/docker-compose.yml b/Transcendence/docker-compose.yml index 7445d2f..7c8f152 100644 --- a/Transcendence/docker-compose.yml +++ b/Transcendence/docker-compose.yml @@ -38,7 +38,8 @@ services: container_name: frontend build: ./srcs/frontend/ ports: - - "8080:80" + - "8080:8080" + - "8443:8443" depends_on: - backend networks: diff --git a/Transcendence/srcs/frontend/dockerfile b/Transcendence/srcs/frontend/dockerfile index 24ef78a..2b0c466 100644 --- a/Transcendence/srcs/frontend/dockerfile +++ b/Transcendence/srcs/frontend/dockerfile @@ -1,5 +1,12 @@ FROM nginx:alpine +RUN apk add --no-cache openssl && \ + mkdir -p /etc/nginx/ssl && \ + openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ + -keyout /etc/nginx/ssl/key.pem \ + -out /etc/nginx/ssl/cert.pem \ + -subj "/CN=localhost" \ + -addext "subjectAltName=DNS:localhost,IP:127.0.0.1" COPY src /usr/share/nginx/html COPY nginx.conf /etc/nginx/conf.d/default.conf -EXPOSE 80 +EXPOSE 8080 8443 CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/Transcendence/srcs/frontend/nginx.conf b/Transcendence/srcs/frontend/nginx.conf index 42edddc..3a8c0c1 100644 --- a/Transcendence/srcs/frontend/nginx.conf +++ b/Transcendence/srcs/frontend/nginx.conf @@ -1,5 +1,13 @@ server { - listen 80; + listen 8080; + return 301 https://$host:8443$request_uri; +} + +server { + listen 8443 ssl; + + ssl_certificate /etc/nginx/ssl/cert.pem; + ssl_certificate_key /etc/nginx/ssl/key.pem; root /usr/share/nginx/html; index index.html; @@ -14,6 +22,7 @@ server { proxy_pass http://backend:3001; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Proto https; } # Socket.IO WebSocket proxying @@ -25,7 +34,9 @@ server { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Proto https; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; } location /avatar/ { diff --git a/Transcendence/srcs/frontend/src/windows/game_room.js b/Transcendence/srcs/frontend/src/windows/game_room.js index 3fa09e9..c507960 100644 --- a/Transcendence/srcs/frontend/src/windows/game_room.js +++ b/Transcendence/srcs/frontend/src/windows/game_room.js @@ -718,7 +718,7 @@ export class GameRoomWindow extends Window { const altPort = window.GLOBAL_CHAT_ALT_PORT; if (altPort) { const host = location.hostname || 'localhost'; - this.socket = io(`http://${host}:${altPort}`, ioConfig); + this.socket = io(`${location.protocol}//${host}:${altPort}`, ioConfig); } else { this.socket = io(ioConfig); } diff --git a/Transcendence/srcs/frontend/src/windows/global_chat.js b/Transcendence/srcs/frontend/src/windows/global_chat.js index 3a15679..d5fc96f 100644 --- a/Transcendence/srcs/frontend/src/windows/global_chat.js +++ b/Transcendence/srcs/frontend/src/windows/global_chat.js @@ -222,7 +222,7 @@ export class GlobalChat extends Window { const altPort = window.GLOBAL_CHAT_ALT_PORT; if (altPort) { const host = location.hostname || 'localhost'; - this.socket = io(`http://${host}:${altPort}`, ioConfig); + this.socket = io(`${location.protocol}//${host}:${altPort}`, ioConfig); } else { this.socket = io(ioConfig); }