56 lines
2.3 KiB
Nginx Configuration File
56 lines
2.3 KiB
Nginx Configuration File
# на IP: не более 5 новых /ws соединений в секунду, всплеск до 10 без задержки
|
|
limit_req_zone $binary_remote_addr zone=ws_connect:10m rate=5r/s;
|
|
# на IP: не более 20 одновременных /ws соединений — не даёт одному клиенту
|
|
# открыть тысячи сокетов и завалить lobby.create_room комнатами до OOM
|
|
limit_conn_zone $binary_remote_addr zone=ws_conn:10m;
|
|
|
|
server {
|
|
listen 80;
|
|
server_name cactoz.su www.cactoz.su;
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# не светим точную версию nginx в заголовке Server и в error-страницах
|
|
server_tokens off;
|
|
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_min_length 256;
|
|
gzip_comp_level 5;
|
|
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
|
|
|
|
add_header X-Content-Type-Options nosniff always;
|
|
add_header X-Frame-Options DENY always;
|
|
add_header Referrer-Policy strict-origin-when-cross-origin always;
|
|
add_header Content-Security-Policy "default-src 'self'; connect-src 'self' wss://cactoz.su wss://www.cactoz.su; img-src 'self' data:; style-src 'self' 'unsafe-inline'; font-src 'self'; base-uri 'none'; frame-ancestors 'none'" always;
|
|
|
|
location / {
|
|
try_files $uri $uri.html $uri/ =404;
|
|
}
|
|
|
|
# без хешей в именах файлов — просим браузер всегда переспрашивать свежесть
|
|
location ~* \.(js|css)$ {
|
|
add_header Cache-Control "no-cache";
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# статичные ассеты меняются редко (лого, og-картинка, CV) — час кэша
|
|
# компромисс между скоростью и актуальностью без хешей в именах
|
|
location /assets/ {
|
|
add_header Cache-Control "public, max-age=3600";
|
|
try_files $uri =404;
|
|
}
|
|
|
|
location /ws {
|
|
limit_req zone=ws_connect burst=10 nodelay;
|
|
limit_conn ws_conn 20;
|
|
|
|
proxy_pass http://gameserver:9001;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_set_header Host $host;
|
|
proxy_read_timeout 3600s;
|
|
}
|
|
}
|