
온라인 브라우저 게임을 위해 WebSockets 게임 서버에 연결하는 클라이언트가 있습니다. 게임 서버는 플레이어가 게임을 시작할 때 생성되고 파괴되므로 각 서버는 내가 제어할 수 없는 서로 다른 IP 주소를 가질 수 있습니다.
보안(WSS)을 위해서는 WebSocket이 필요하므로 SSL 인증서가 있는 nginx 프록시가 있습니다. 클라이언트는 게임 서버의 IP를 수신하지만 직접 연결(안전하지 않음)하는 대신 게임 서버 IP를 쿼리 매개변수로 사용하여 내 nginx 서버를 통해 이동합니다.
문제는 다음과 같습니다. 이제 누구나 내 nginx 서버를 사용하여 자신이 선택한 IP로 프록시를 사용할 수 있습니다. 나에게 필요한 것은 nginx가 프록시로만 작동하도록 하는 방법입니다.나의게임 서버.
외부 호스트이기 때문에 게임 서버 IP를 제어할 수는 없지만 게임 서버 코드는 소유하고 있습니다. 내 nginx 프록시는 내가 호스팅하지만 게임 서버는 공급자가 호스팅합니다.
내 계획은 게임 서버와 nginx에 공유 비밀 키를 두고 이를 통해 모든 트래픽을 암호화하는 것이었지만 이것이 어떻게 이루어질 수 있는지 알아내려고 애쓰고 있습니다.
지금까지 내가 한 일은 다음과 같습니다(기반)이 요지에):
자체 서명된 CA 인증서를 만들었습니다.
openssl genrsa -des3 -out rootCA.key 4096
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.crt
게임 서버용 인증서를 만들었습니다.
openssl genrsa -out gameserver.key 2048
openssl req -new -key gameserver.key -out gameserver.csr
openssl x509 -req -in gameserver.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out gameserver.crt -days 500 -sha256
nginx 서버에도 동일한 작업을 수행했습니다( 이것이 필요합니까? 참고: 필요하지 않음).
openssl genrsa -out nginx.key 2048
openssl req -new -key nginx.key -out nginx.csr
openssl x509 -req -in nginx.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out nginx.crt -days 500 -sha256
내 nginx 구성은 다음과 같습니다.
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 443 ssl;
# these are for game client
ssl_certificate /etc/letsencrypt/live/mywebsite.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mywebsite.com/privkey.pem;
location / {
if ( $arg_host != "" ) {
proxy_pass https://$arg_host:$arg_port;
}
proxy_ssl_certificate nginx.crt;
proxy_ssl_certificate_key nginx.key;
proxy_ssl_trusted_certificate rootCA.crt;
proxy_ssl_verify on;
proxy_ssl_verify_depth 2;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_read_timeout 86400;
}
}
}
gameserver.key
내 게임 서버는 및 를 사용하는 WebSockets 서버입니다 gameserver.csr
.
그러나 시도하면 nginx 오류 로그에 다음이 표시됩니다.
upstream SSL certificate verify error: (18:self signed certificate) while SSL handshaking to upstream
이것이 작동할 수 있는지 잘 모르겠습니다. 어디서 잘못되었습니까? 그만큼유일한 기사이 오류를 언급하면 게임 서버 인증서를 신뢰할 수 없다는 뜻이지만 그 이유를 알 수 없습니다.
Common Name
또한 인증서를 생성할 때(각 게임 서버가 자체 IP에 있기 때문에) 어떤 값을 입력해야 하는지, 그리고 이것이 문제인지 아닌지 도 잘 모르겠습니다 .
답변1
제가 제안하고 싶은 것은 백엔드에 대한 내부 인증 기관을 설정하고 해당 인증 기관을 통해 백엔드를 확인할 수 있도록 요구하는 것입니다. 이러한 인증서를 부트스트랩하여 해당 IP를 포함하거나 IP를 공통 호스트 이름으로 재정의할 수 있습니다. 충분하다).
- 내부 전용 CA를 만들고 "Gameserver Backend"라고 부릅니다.
- 내부 전용 서버 인증서를 생성하고 이름을 "gameserver.auth.backend"로 지정합니다.
- websocket 노드 프로그램에서 gameserver.auth.backend를 인증서로 사용하십시오.
- nginx에게 이에 대해 유효성을 검사하도록 지시하고 일반 이름을 (IP 대신) 지정한 이름으로 재정의합니다.
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 443 ssl;
# these are for game client
ssl_certificate /etc/letsencrypt/live/mywebsite.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mywebsite.com/privkey.pem;
location / {
if ( $arg_host != "" ) {
proxy_pass https://$arg_host:$arg_port;
}
proxy_ssl_verify on;
proxy_ssl_verify_depth 2;
proxy_ssl_name gameserver.auth.backend;
proxy_ssl_server_name on;
proxy_ssl_trusted_certificate GameserverCA.crt;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_read_timeout 86400;
}
}
}