mobile background

NGINX Community


NGINX 및 Modern App등 IT와 관련된 다양한 이야기를 편하게 나눌 수 있는 장소 입니다.

USECASE CONTEST-2024nginx 를 활용한 눈치싸움 게임을 만들어보았습니다

문성****
2025-01-08

요약

Nginx 를 이용해서 눈치싸움 게임의 일종인 NIM 게임을 만들어보았습니다 (우리나라엔 베스킨라빈스 써리원 으로 많이 알려져있습니다).


작동 원리

nginx 가 기동된 서버에 curl 요청을 보내면 counter 가 1씩 적립되는데, 정확히 100번째 counter 를 적립하는 유저가 승리하는 방식입니다.

한 유저가 여러번 요청을 보내서 counter 를 계속 적립할 수도 있지만, rate limiter 가 세팅되어있기 때문에 (1 req/sec), 운이 따라줘야 하는 게임입니다.


사용한 모듈

- ngx_http_realip_module (https://nginx.org/en/docs/http/ngx_http_realip_module.html)

- ngx_http_limit_req_module (https://nginx.org/en/docs/http/ngx_http_realip_module.html)

- ngx_http_perl_module (https://nginx.org/en/docs/http/ngx_http_perl_module.html)

(Ubuntu 24.04 에 nginx-extras 패키지가 있어서, 모듈들은 쉽게 사용할 수 있었습니다)


소스코드

https://github.com/roeniss/nim-game-with-nginx

4 0