From d9c9952230d6f0566b4a54be0f1e2494835a76de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=84=B1=EA=B2=BD?= Date: Thu, 8 Oct 2026 11:31:57 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20nginx,docs:=20=EB=B0=9C=ED=96=89=20?= =?UTF-8?q?=EC=82=AC=EC=9D=B4=ED=8A=B8=C2=B7robots=C2=B7sitemap=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=EC=9D=84=20=ED=81=AC=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EA=B8=B0=EB=A1=9D=EC=9C=BC=EB=A1=9C=20mirror=20=E2=80=94=20?= =?UTF-8?q?=EC=82=AC=EC=A7=84=C2=B7=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8?= =?UTF-8?q?=EB=8A=94=20nginx=20=EC=97=90=EC=84=9C=20=EB=81=8A=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /s/·/robots.txt·/sitemap.xml 에 mirror /_track_hit 를 건다. 응답 본문·헤더는 그대로다 - /s/ 아래 확장자 붙은 요청(사진·JS·JSON)은 map $track_skip 으로 nginx 에서 204 — 백엔드까지 안 간다. $uri 가 아니라 $request_uri 를 본다(mirror 하위 요청 안에서 $uri 는 /_track_hit 이 된다) - X-Forwarded-For 는 앞단 Apache 가 붙인 값을 그대로 넘긴다($remote_addr 는 늘 Apache) ★ nginx/site.conf 는 레포에 없고 예제만 추적한다 — 서버 파일에 손으로 옮겨야 한다. 절차를 docs/SERVERS.md 에 적었다. --- docs/SERVERS.md | 12 ++++++++++++ nginx/site.conf.example | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/docs/SERVERS.md b/docs/SERVERS.md index f63a3d0..dea5c19 100644 --- a/docs/SERVERS.md +++ b/docs/SERVERS.md @@ -142,6 +142,18 @@ cd ~/data2/o2o-site-AEO ★ 새 클론(`o2o-site-AEO`)은 gitea 자격증명이 통해서 `./deploy.sh` 를 서버에서 그대로 쓴다. 옛 `o2o-web4ai` 는 안 됐다 — fetch 가 죽으면 deploy.sh 가 리셋을 건너뛰고 디스크 코드로 간다. +### 크롤러 기록 — nginx mirror (2026-10-07) + +`nginx/site.conf` 의 `/s/`·`/robots.txt`·`/sitemap.xml` 이 요청 복사본을 `/_track_hit` → +백엔드 `/internal/track/hit` 로 보낸다. 봇만 `site_crawler_hits` 에 쌓인다(사이트관리 → 전체 통계). + +★ **`nginx/site.conf` 는 레포에 없다**(예제만 추적). 서버의 파일에 `site.conf.example` 의 +`map $request_uri $track_skip`·`mirror` 줄·`location = /_track_hit` 를 **손으로 옮긴다.** +옮긴 뒤 `docker compose exec solution-site nginx -t` → `docker compose exec solution-site nginx -s reload`. +설정 파일은 마운트라 이미지 재빌드는 필요 없다. + +★ 표가 비어 있으면 순서대로 본다: 마이그레이션 `0024` 적용 여부 → `nginx -t` → 백엔드 로그의 `[track]` 경고. + ## DB 호스트에 PostgreSQL 15(pgvecto)가 `king_postgres_container` 로 떠 있고 `5432` 가 호스트에 열려 있다. diff --git a/nginx/site.conf.example b/nginx/site.conf.example index b1d959a..1c030e1 100644 --- a/nginx/site.conf.example +++ b/nginx/site.conf.example @@ -13,6 +13,14 @@ # ★ 산출물은 named volume(site-out)으로 들어온다. 프리렌더가 쓰고 여기서 읽기만 한다 — # 호스트 경로가 등장하지 않으므로 재배포로 코드를 갈아엎어도 사이트가 죽지 않는다. +# 크롤러 기록에서 뺄 요청 — /s/ 아래의 사진·스크립트·JSON 같은 파일. +# ★ $uri 가 아니라 $request_uri 를 본다. mirror 하위 요청 안에서 $uri 는 `/_track_hit` 이 된다. +# ★ 정규식에 `{n}` 수량자를 쓰지 않는다 — nginx 가 `{` 를 블록 구분자로 먼저 읽는다. +map $request_uri $track_skip { + default 0; + "~^/s/[^?]*\.[A-Za-z0-9]+(\?.*)?$" 1; +} + server { listen 80; listen [::]:80; @@ -82,6 +90,9 @@ server { # ^~ 로 잡아 아래 정규식 location 들이 끼어들지 못하게 한다. location ^~ /s/ { + # 봇 요청을 백엔드에 한 부 복사한다(크롤러 통계). 응답은 기다리지 않고 나간다. + mirror /_track_hit; + mirror_request_body off; # ★ `/s//`(끝 슬래시) 를 위해 필요하다. try_files 의 첫 인자 `$uri` 가 끝 # 슬래시면 nginx 는 **디렉토리 검사**로 읽고, 디렉토리가 있으면 거기서 멈춘다 — # index 지시자가 없으면 그 순간 403 이다(=404 로도 안 떨어진다). @@ -128,15 +139,41 @@ server { # 발행하면 곧바로 반영되어야 한다. 길게 캐시하면 새 사업장이 사이트맵에 들어가도 # 크롤러가 옛 파일을 계속 본다. location = /robots.txt { + mirror /_track_hit; + mirror_request_body off; add_header Cache-Control "public, max-age=300, must-revalidate"; try_files $uri =404; } location = /sitemap.xml { + mirror /_track_hit; + mirror_request_body off; add_header Cache-Control "public, max-age=300, must-revalidate"; try_files $uri =404; } + # ── 크롤러 기록 (mirror 수신) ────────────────────────────── + # 크롤러는 JS 를 실행하지 않아 브라우저 트래커로는 안 잡힌다. 요청 시점에 복사본을 백엔드로 + # 넘기고 UA 판별·저장은 백엔드가 한다(services/track_service.py). + # ★ /internal 은 아래 API location(^/(v1/|…))에 안 걸리므로 밖에서 직접 부를 길이 없다. + # ★ nginx 는 같은 연결의 다음 요청 전에 mirror 가 끝나길 기다린다 — 타임아웃을 짧게 둔다. + location = /_track_hit { + internal; + access_log off; + if ($track_skip) { + return 204; + } + proxy_pass $api/internal/track/hit; + proxy_pass_request_body off; + proxy_set_header Content-Length ""; + proxy_set_header X-Original-URI $request_uri; + proxy_set_header User-Agent $http_user_agent; + # 앞단 Apache 가 붙인 값을 그대로 넘긴다 — $remote_addr 는 늘 Apache 다. + proxy_set_header X-Forwarded-For $http_x_forwarded_for; + proxy_connect_timeout 1s; + proxy_read_timeout 2s; + } + # ── API ──────────────────────────────────────────────────── # 앱과 같은 오리진이라 프리플라이트가 아예 발생하지 않는다. location ^~ /v1/social/ {