Files
PlaylistShared/PlaylistShared.Pwa/nginx.conf

110 lines
4.1 KiB
Nginx Configuration File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Не раскрывайть версию Nginx в ответах.
server_tokens off;
# Ограничение запросов от одного IPадреса, чтобы предотвратить DDoSатаки и злоупотребление ресурсами.
limit_req_zone $binary_remote_addr zone=one:10m rate=60r/s;
# Сжатие
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/wasm application/json;
# Бэкенд API (для OG-тегов)
upstream api_backend {
server playlistshared_api:80;
}
# Определяем, является ли запрос ботом-краулером
map $http_user_agent $is_crawler {
default 0;
~*Slackbot 1;
~*facebookexternalhit 1;
~*Twitterbot 1;
~*TelegramBot 1;
~*WhatsApp 1;
~*LinkedInBot 1;
~*vkShare 1;
~*Pinterest 1;
~*Googlebot 1;
~*YandexBot 1;
~*Discordbot 1;
~*Applebot 1;
~*DuckDuckBot 1;
}
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
# Для Service Worker запрещаем кэширование, чтобы он всегда был свежим
location = /service-worker.js {
etag off;
add_header Last-Modified "";
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
try_files $uri =404;
}
# Для файла манифеста Service Worker assets тоже не кэшируем
location = /service-worker-assets.js {
etag off;
add_header Last-Modified "";
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
try_files $uri =404;
}
# Для файла index.html тоже не кэшируем
location = /index.html {
etag off;
add_header Last-Modified "";
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
try_files $uri =404;
}
# OG-теги: краулеры получают HTML с meta-тегами от API
location ~ ^/shared/(.+)$ {
if ($is_crawler) {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_pass http://api_backend;
}
try_files $uri $uri/ /index.html?$args;
}
# Основной SPA fallback: все неизвестные пути отдаём через index.html
location / {
try_files $uri $uri/ /index.html?$args;
}
# Кэширование статических ресурсов (css, js, изображения, шрифты)
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# Для .wasm файлов правильный MIMEтип и кэширование
location ~* \.wasm$ {
default_type application/wasm;
expires 1y;
add_header Cache-Control "public, immutable";
}
}
}