54 lines
2.1 KiB
Plaintext
54 lines
2.1 KiB
Plaintext
# Crawlery social media (Facebook, WhatsApp, Messenger, Twitter/X, LinkedIn...) nie wykonuja
|
|
# JavaScriptu, wiec meta tagi ustawiane w aplikacji React sa dla nich niewidoczne. Po User-Agent
|
|
# rozpoznajemy bota i dla adresu /oferta/{id} kierujemy go na serwerowy podglad z tagami Open Graph
|
|
# (backend), zamiast na aplikacje SPA. Zwykly uzytkownik dostaje niezmieniona aplikacje.
|
|
map $http_user_agent $pl_is_crawler {
|
|
default 0;
|
|
"~*facebookexternalhit|Facebot|Twitterbot|WhatsApp|Slackbot|LinkedInBot|TelegramBot|Discordbot|Pinterest|redditbot|Applebot|SkypeUriPreview|vkShare|Google-InspectionTool|Googlebot|bingbot|Embedly|Iframely|OpenGraph" 1;
|
|
}
|
|
|
|
server {
|
|
listen 80;
|
|
server_name _;
|
|
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# Wbudowany DNS Dockera - potrzebny, bo proxy_pass ze zmienna ($listing_id) rozwiazuje host
|
|
# "backend" dopiero przy zadaniu, a nie przy starcie nginx.
|
|
resolver 127.0.0.11 ipv6=off valid=30s;
|
|
|
|
location /api/ {
|
|
proxy_pass http://backend:8080/api/;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
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;
|
|
}
|
|
|
|
# Szczegoly ogloszenia: crawler dostaje serwerowy podglad Open Graph, czlowiek - aplikacje SPA.
|
|
location ~ ^/oferta/(?<listing_id>\d+) {
|
|
if ($pl_is_crawler) {
|
|
proxy_pass http://backend:8080/api/og/listing/$listing_id;
|
|
}
|
|
try_files $uri /index.html;
|
|
}
|
|
|
|
# Pliki z hashem w nazwie (assets/index-XXXX.js) sa niezmienne - mozna je trzymac dlugo.
|
|
location /assets/ {
|
|
try_files $uri =404;
|
|
add_header Cache-Control "public, max-age=31536000, immutable";
|
|
}
|
|
|
|
# index.html nigdy nie moze byc cache'owany - inaczej przegladarka po wdrozeniu
|
|
# nadal laduje stary bundle i uzytkownik pracuje na nieaktualnej wersji aplikacji.
|
|
location = /index.html {
|
|
add_header Cache-Control "no-store, must-revalidate";
|
|
}
|
|
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
}
|