gpt4 book ai didi

web-applications - 如何使用位置正则表达式通过 nginx 重定向/处理来自搜索引擎的请求

转载 作者:行者123 更新时间:2023-12-04 08:35:13 25 4
gpt4 key购买 nike

我开发了一个带有 hash bang url 的基于 ajax 的 web 应用程序。

我正在尝试将来自搜索引擎的请求重定向到另一台生成 HTML 快照并发送响应的服务器。我试图在 nginx 中使用 location 指令实现这一点,如下所述:

      location ~ ^(/?_escaped_fragment_=).*$ {
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;

client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 60s;
proxy_send_timeout 90s;
proxy_read_timeout 90s;
proxy_buffering off;
proxy_temp_file_write_size 64k;
proxy_pass http://x1.x2.x3.x4:8080;
proxy_redirect off;
}

但我无法让这个工作。有人可以更正我正在使用的正则表达式(或)为我提供替代解决方案来实现这一目标。

提前致谢。

最佳答案

您无法检查位置名称 ( nginx docs ) 中的参数:

Note that locations of all types test only a URI part of request line without arguments. This is done because arguments in the query string may be given in several ways, for example:

/index.php?user=john&page=1
/index.php?page=1&user=john


您可以在服务器部分设置重写规则(找到 here ):
if ($args ~ “_escaped_fragment_=(.+)”) {
set $real_url $1;
rewrite ^ /crawler$real_url;
}
并定义一个“/crawler”位置,该位置可以重定向到您的 HTML 生成服务器。

关于web-applications - 如何使用位置正则表达式通过 nginx 重定向/处理来自搜索引擎的请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10306373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com