我有一个Javascript应用程序,对于社交分享,我想在facebook抓取工具访问该页面时将结果从另一台服务器返回。
基本上,如果我检测到社交机器人,我想这样做:
获取https://example.net/shared/route/123 - >获取https://rendered.example.net/robots/shared/route/123
我无法完成此操作,因为我无法在proxy_pass
声明中使用try_files
或if
。
我尝试过的事情:
location /shared/route/ {
if ($http_user_agent ~ (?!(facebookexternalhit|Facebot|Twitterbot|Pinterest|Google.*snippet))) {
try_files $uri $uri/ /index.html =404;
}
rewrite /shared/(.*) /robots/$1 break;
proxy_pass https://rendered.example.net/;
}
但我收到错误:
"try_files" directive is not allowed here in /etc/nginx/sites-enabled/webapp:22
我也试过
location /shared/route/ {
if ($http_user_agent ~ (?!(facebookexternalhit|Facebot|Twitterbot|Pinterest|Google.*snippet))) {
rewrite /shared(.*) /robots/$1 break;
proxy_pass https://rendered.example.net/;
}
}
但后来我收到了:
"proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/sites-enabled/app:24
我该如何解决这个问题?