1
- user www;
2
- worker_processes auto; # it will be determined automatically by the number of cores
3
-
4
- error_log /var/log/nginx/error.log warn ;
5
- #pid /var/run/nginx/nginx.pid; # it permits you to use rc-service nginx reload|restart|stop|start
1
+ user www;
2
+ worker_processes auto;
6
3
4
+ error_log /var/log/nginx/error.log info;
7
5
events {
8
- worker_connections 1024 ;
6
+ worker_connections 1024 ;
9
7
}
10
8
11
9
http {
12
- include /etc/nginx/mime.types;
13
- default_type application/octet-stream;
14
- sendfile on ;
15
- access_log /var/log/nginx/access.log;
16
- keepalive_timeout 3000 ;
10
+ include /etc/nginx/mime.types;
11
+ default_type application/octet-stream;
12
+ sendfile on ;
13
+ access_log /var/log/nginx/access.log;
14
+ keepalive_timeout 3000 ;
17
15
16
+ # Define upstream servers
18
17
upstream token-service {
19
18
server token-service:8000;
20
19
}
@@ -27,47 +26,56 @@ http {
27
26
server game-history:8002;
28
27
}
29
28
29
+ upstream game-server {
30
+ server game-server:8010;
31
+ }
32
+
33
+ # Redirect HTTP to HTTPS
30
34
server {
31
- listen 80 ;
32
- server_name localhost;
35
+ listen 80 ;
36
+ server_name localhost;
33
37
34
- # Redirect all HTTP requests to HTTPS
35
38
location / {
36
39
return 301 https://$host$request_uri ;
37
40
}
38
41
}
39
42
43
+ # HTTPS server block
40
44
server {
41
- listen 443 ssl;
42
- ssl_certificate /etc/nginx/ssl/nginx-selfsigned.crt;
43
- ssl_certificate_key /etc/nginx/ssl/nginx-selfsigned.key;
44
- ssl_protocols TLSv1.2 TLSv1.3;
45
- root /www;
46
- index index.html index.htm;
47
- server_name localhost;
48
- client_max_body_size 32m ;
49
- error_page 500 502 503 504 /50x.html;
45
+ listen 443 ssl;
46
+ server_name localhost;
47
+ ssl_certificate /etc/nginx/ssl/nginx-selfsigned.crt;
48
+ ssl_certificate_key /etc/nginx/ssl/nginx-selfsigned.key;
49
+ ssl_protocols TLSv1.2 TLSv1.3;
50
+ ssl_prefer_server_ciphers on ;
51
+
52
+ root /www;
53
+ index index.html index.htm;
54
+ client_max_body_size 32m ;
55
+ error_page 500 502 503 504 /50x.html;
56
+
50
57
location = /50x.html {
51
- root /var/lib/nginx/html;
58
+ root /var/lib/nginx/html;
52
59
}
53
-
54
- # Serve JavaScript files
60
+
61
+ # Serve static files
55
62
location / {
56
63
try_files $uri $uri / /index.html;
57
64
}
58
65
66
+ # Serve media files
59
67
location /media/ {
60
68
alias /www/avatars/;
61
69
}
62
- # Proxy requests to the authentication service
70
+
71
+ # Proxy requests to the token service
63
72
location /auth/ {
64
- proxy_pass http://token-service;
65
- proxy_set_header Host $host ;
66
- proxy_set_header X-Real-IP $remote_addr ;
67
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
68
- proxy_set_header X-Forwarded-Proto $scheme ;
73
+ proxy_pass http://token-service;
74
+ proxy_set_header Host $host ;
75
+ proxy_set_header X-Real-IP $remote_addr ;
76
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
77
+ proxy_set_header X-Forwarded-Proto $scheme ;
69
78
70
- # Add CORS headers for /auth requests
71
79
add_header Access-Control-Allow-Origin *;
72
80
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS' ;
73
81
add_header Access-Control-Allow-Headers 'Authorization, Content-Type' ;
@@ -79,21 +87,35 @@ http {
79
87
}
80
88
}
81
89
90
+ # Proxy requests to the user service
82
91
location /user/ {
83
- proxy_pass http://user-service;
84
- proxy_set_header Host $host ;
85
- proxy_set_header X-Real-IP $remote_addr ;
86
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
87
- proxy_set_header X-Forwarded-Proto $scheme ;
92
+ proxy_pass http://user-service;
93
+ proxy_set_header Host $host ;
94
+ proxy_set_header X-Real-IP $remote_addr ;
95
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
96
+ proxy_set_header X-Forwarded-Proto $scheme ;
88
97
}
89
98
99
+ # Proxy requests to the game history service
90
100
location /game-history/ {
91
- proxy_pass http://game-history;
92
- proxy_set_header Host $host ;
93
- proxy_set_header X-Real-IP $remote_addr ;
94
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
95
- proxy_set_header X-Forwarded-Proto $scheme ;
101
+ proxy_pass http://game-history;
102
+ proxy_set_header Host $host ;
103
+ proxy_set_header X-Real-IP $remote_addr ;
104
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
105
+ proxy_set_header X-Forwarded-Proto $scheme ;
106
+ }
107
+
108
+ # Proxy WebSocket and HTTP requests to the game server
109
+ location /game-server/socket.io/ {
110
+ rewrite ^/game-server/socket.io/(.*) /socket.io/$1 break;
111
+ proxy_pass http://game-server;
112
+ proxy_set_header Host $host ;
113
+ proxy_set_header X-Real-IP $remote_addr ;
114
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
115
+ proxy_set_header X-Forwarded-Proto $scheme ;
116
+ proxy_http_version 1.1 ;
117
+ proxy_set_header Upgrade $http_upgrade ;
118
+ proxy_set_header Connection 'upgrade' ;
96
119
}
97
-
98
120
}
99
- }
121
+ }
0 commit comments