File tree 11 files changed +47
-17
lines changed
game-service/Game.Application
11 files changed +47
-17
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ services:
7
7
REACT_APP_ENV : Production
8
8
REMOVE_CF_IPS : " false"
9
9
ports :
10
- - 80:80
10
+ - 443:443
11
11
depends_on :
12
12
- game-service
13
13
game-service :
@@ -16,9 +16,11 @@ services:
16
16
expose :
17
17
- 50051
18
18
environment :
19
- URL : ws ://0.0.0.0:50051
19
+ URL : wss ://0.0.0.0:50051
20
20
FLECK_LOG : Info
21
21
IM_LOG : Debug
22
22
GAME_LOG : Debug
23
23
CONFIG_SOURCE : v2.0
24
24
MAX_CONNECTIONS : 100
25
+ CERTIFICATE_NAME : " server.pfx"
26
+ CERTIFICATE_PASSWORD : " "
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ services:
10
10
REACT_APP_ENV : Development
11
11
REMOVE_CF_IPS : " true"
12
12
ports :
13
- - 80:80
13
+ - 443:443
14
14
depends_on :
15
15
- game-service
16
16
game-service :
@@ -21,9 +21,11 @@ services:
21
21
expose :
22
22
- 50051
23
23
environment :
24
- URL : ws ://0.0.0.0:50051
24
+ URL : wss ://0.0.0.0:50051
25
25
FLECK_LOG : Info
26
26
IM_LOG : Debug
27
27
GAME_LOG : Debug
28
28
CONFIG_SOURCE : v2.0
29
29
MAX_CONNECTIONS : 100
30
+ CERTIFICATE_NAME : " server.pfx"
31
+ CERTIFICATE_PASSWORD : " helloworld"
Original file line number Diff line number Diff line change 18
18
image : maplefighters/frontend:2.0.0
19
19
imagePullPolicy : Always
20
20
ports :
21
- - containerPort : 80
21
+ - containerPort : 443
22
22
env :
23
23
- name : REACT_APP_ENV
24
24
value : " Development"
@@ -45,8 +45,8 @@ metadata:
45
45
spec :
46
46
type : LoadBalancer
47
47
ports :
48
- - name : http
49
- port : 80
50
- targetPort : 80
48
+ - name : https
49
+ port : 443
50
+ targetPort : 443
51
51
selector :
52
52
app : frontend
Original file line number Diff line number Diff line change 20
20
ports :
21
21
- containerPort : 50051
22
22
env :
23
+ - name : CERTIFICATE_PASSWORD
24
+ value : " "
25
+ - name : CERTIFICATE_NAME
26
+ value : " server.pfx"
23
27
- name : MAX_CONNECTIONS
24
28
value : " 100"
25
29
- name : CONFIG_SOURCE
31
35
- name : IM_LOG
32
36
value : Debug
33
37
- name : URL
34
- value : ws ://0.0.0.0:50051
38
+ value : wss ://0.0.0.0:50051
35
39
resources :
36
40
requests :
37
41
cpu : 100m
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ RUN npm run build
7
7
8
8
FROM nginx:1.20.1-alpine
9
9
COPY --from=builder /app/nginx.conf /etc/nginx/nginx.conf
10
+ COPY --from=builder /app/server.crt /etc/nginx/ssl/server.crt
11
+ COPY --from=builder /app/server.key /etc/nginx/ssl/server.key
10
12
COPY --from=builder /app/cloudflare-ips.conf /var/www-allow/cloudflare-ips.conf
11
13
COPY --from=builder /app/build /usr/share/nginx/html
12
14
COPY --from=builder /app/entrypoint.sh /entrypoint.sh
Original file line number Diff line number Diff line change @@ -16,10 +16,24 @@ http {
16
16
server game-service:50051;
17
17
}
18
18
19
- server {
19
+ server {
20
20
listen 80 ;
21
21
server_name _;
22
22
23
+ # Redirect all HTTP requests to HTTPS
24
+ return 301 https://$host$request_uri ;
25
+ }
26
+
27
+ server {
28
+ listen 443 ssl;
29
+ server_name _;
30
+
31
+ # SSL configuration
32
+ ssl_certificate /etc/nginx/ssl/server.crt;
33
+ ssl_certificate_key /etc/nginx/ssl/server.key;
34
+ ssl_protocols TLSv1.2 TLSv1.3;
35
+ ssl_ciphers HIGH:!aNULL:!MD5;
36
+
23
37
limit_req zone=req burst=10 delay=5;
24
38
limit_req_status 444;
25
39
limit_rate 5m ;
31
45
}
32
46
33
47
location /game {
34
- # Source: https://github.com/nicokaiser/nginx-websocket-proxy/blob/master/simple-ws.conf
35
- # redirect all HTTP traffic to game-service
36
- proxy_pass http://game/;
48
+ # Upgrade to WebSocket protocol over HTTPS
49
+ proxy_pass https://game/;
37
50
proxy_set_header X-Real-IP $remote_addr ;
38
51
proxy_set_header Host $host ;
39
52
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
Original file line number Diff line number Diff line change 1
- URL = ws ://0.0.0.0:50051
1
+ URL = wss ://0.0.0.0:50051
2
2
FLECK_LOG = Info
3
3
IM_LOG = Debug
4
4
GAME_LOG = Debug
5
5
CONFIG_SOURCE = v2.0
6
- MAX_CONNECTIONS = 100
6
+ MAX_CONNECTIONS = 100
7
+ CERTIFICATE_NAME = server.pfx
8
+ CERTIFICATE_PASSWORD = helloworld
Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ RUN dotnet publish -c release -o /app --no-restore
8
8
FROM mcr.microsoft.com/dotnet/runtime:5.0
9
9
WORKDIR /app
10
10
COPY --from=builder /app .
11
+ COPY --from=builder /source/server.pfx .
11
12
ENTRYPOINT ["dotnet" , "Game.Application.dll" ]
Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using System . Security . Cryptography . X509Certificates ;
2
3
using DotNetEnv ;
3
4
using Fleck ;
4
5
using Game . Application ;
23
24
GameLog . Level = ( GameLogLevel ) Enum . Parse ( typeof ( GameLogLevel ) , gameLog ) ;
24
25
25
26
var url = Env . GetString ( "URL" ) ;
27
+ var certificateName = Env . GetString ( "CERTIFICATE_NAME" ) ;
28
+ var certificatePassword = Env . GetString ( "CERTIFICATE_PASSWORD" ) ;
26
29
var server = new WebSocketServer ( url ) ;
30
+ server . Certificate = new X509Certificate2 ( certificateName , certificatePassword ) ;
27
31
var serverComponents = new ComponentCollection ( new IComponent [ ]
28
32
{
29
33
new IdGenerator ( ) ,
Original file line number Diff line number Diff line change 2
2
docker build -t game-service .
3
3
4
4
run :
5
- docker run -p 50051:50051 game-service -e URL=ws ://0.0.0.0:50051 \
5
+ docker run -p 50051:50051 game-service -e URL=wss ://0.0.0.0:50051 \
6
6
FLECK_LOG=Info \
7
7
IM_LOG=Debug \
8
8
GAME_LOG=Debug
Original file line number Diff line number Diff line change @@ -43,4 +43,4 @@ make build
43
43
make run
44
44
```
45
45
46
- You should now be able to access it at ` ws ://localhost:50051` .
46
+ You should now be able to access it at ` wss ://localhost:50051` .
You can’t perform that action at this time.
0 commit comments