Wiki.js 가 robots.txt 를 제공하지 않으니 웹서버에서 만들어야 한다는 설명이 돌아다니지만 사실과 다르다. Wiki.js 2.x 는 /robots.txt 를 자체 라우트로 처리하며, 내용은 관리자 화면의 색인 설정에 따라 달라진다. 실제 응답을 보면 Wiki.js 가 text/plain 으로 응답하고 있음을 확인할 수 있다.
curl -s -D - -o /dev/null https://wiki.example.com/robots.txt
색인을 허용해 두면 본문이 비어 있다. 아무것도 금지하지 않는다는 뜻이므로 크롤러 입장에서는 전체 허용과 같다. 색인을 막아 두면 모든 경로를 거부하는 내용이 나온다.
설정 위치는 관리자 화면의 일반(General) 항목 아래 검색 엔진 색인(Search Engine Indexing)이다. 파일을 만들어 올리는 것이 아니라 이 설정을 바꾸는 것이 정석이다.
sitemap 줄을 넣거나 특정 경로만 막는 등 Wiki.js 가 만들어 주지 않는 내용이 필요하면 리버스 프록시에서 가로챈다. 정확히 일치하는 location 이 프록시 규칙보다 먼저 매칭되므로 그대로 덮어쓴다.
server {
listen 443 ssl;
server_name wiki.example.com;
location = /robots.txt {
alias /var/www/static/robots.txt;
default_type text/plain;
}
location = /ads.txt {
alias /var/www/static/ads.txt;
default_type text/plain;
}
location / {
proxy_pass http://127.0.0.1:3000;
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;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
파일 내용은 다음과 같이 둔다.
User-agent: *
Allow: /
Sitemap: https://wiki.example.com/sitemap.xml
ads.txt 는 Wiki.js 의 라우트가 아니다. 문서 경로로 해석되어 404 나 로그인 화면이 나가므로 광고 플랫폼의 검사를 통과하지 못한다. 위처럼 정확히 일치하는 location 을 두어 정적 파일로 내려주어야 한다.
Apache 라면 프록시 제외 규칙을 프록시 규칙보다 앞에 둔다.
Alias /robots.txt /var/www/static/robots.txt
Alias /ads.txt /var/www/static/ads.txt
ProxyPass /robots.txt !
ProxyPass /ads.txt !
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
curl -s https://wiki.example.com/robots.txt
curl -s -o /dev/null -w "%{http_code} %{content_type}\n" https://wiki.example.com/ads.txt
200 과 text/plain 이 나와야 한다. 비공개 위키라면 인증을 거치지 않고도 이 두 경로가 열리는지 함께 확인한다.