connection upgrade with nginx

This commit is contained in:
batche
2022-12-14 11:18:02 +01:00
parent fd8435b632
commit 0877cd284f
4 changed files with 48 additions and 10 deletions

View File

@@ -54,6 +54,7 @@ services:
restart: unless-stopped
volumes:
- ./requirements/nginx/conf/default.conf:/etc/nginx/conf.d/default.conf:ro
- ./requirements/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro
command: [nginx-debug, "-g", "daemon off;"]
ports:
- "8080:8080"

View File

@@ -1,6 +1,5 @@
server {
listen 8080 default_server;
listen 8042;
listen [::]:8080 default_server;
server_name transcendance;
@@ -11,6 +10,15 @@ server {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://backend_dev:3000;
}
location /pong {
proxy_pass http://game_server:8042/pong;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@@ -18,13 +26,6 @@ server {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://frontend_dev:8080;
}
location /pong {
http://game_server:8042/pong;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
}
}
server {

View File

@@ -0,0 +1,37 @@
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
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;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
#gzip on;
include /etc/nginx/conf.d/*.conf;
}

View File

@@ -25,8 +25,7 @@ class ClientInfoSpectator {
playerRightNextPos: VectorInteger;
}
const wsPort = 8042;
const wsUrl = "ws://transcendance:" + wsPort + "/pong";
const wsUrl = "ws://transcendance:8080/pong";
export let socket: WebSocket; /* TODO: A way to still use "const" not "let" ? */
export const clientInfo = new ClientInfo();
export const clientInfoSpectator = new ClientInfoSpectator(); // WIP, could refactor this