nginx — Forward AI traffic
Config
In your http {} block (or a snippet included from it):
map $http_user_agent $is_ai_bot {
default 0;
"~*ChatGPT-User" 1;
"~*PerplexityBot" 1;
"~*Perplexity-User" 1;
"~*GPTBot" 1;
"~*OAI-SearchBot" 1;
"~*anthropic-ai" 1;
"~*Claude-Web" 1;
"~*ClaudeBot" 1;
"~*Claude-User" 1;
"~*Google-Extended" 1;
"~*Gemini" 1;
"~*Applebot-Extended" 1;
"~*meta-externalagent" 1;
"~*meta-externalfetcher" 1;
"~*CCBot" 1;
"~*cohere-ai" 1;
"~*YouBot" 1;
"~*Diffbot" 1;
"~*Timpibot" 1;
"~*Amazonbot" 1;
"~*Bytespider" 1;
}In your server {} block:
if ($is_ai_bot) {
return 302 https://oasy.<your-domain>;
}Replace <your-domain>. Reload:
sudo nginx -t && sudo systemctl reload nginxVerify
Back on the MCP page, click Check forwarding.
Test yourself
curl -I -A "ClaudeBot/1.0" https://your-domain.com/
# → HTTP/2 302
# → location: https://oasy.your-domain.comNotes
ifinsideserver {}has nginx caveats but is safe for a simple
return— see nginx's "if is evil" doc; the listed exceptions cover this.- For OpenResty / Lua-aware setups, prefer doing the match in Lua to avoid
theifblock entirely. - The
mapruns once per request and is cheap.