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

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

概述我开发了一个基于ajax的web应用程序,带有哈希爆炸网址. 我试图将请求搜索引擎重定向到另一个生成HTML快照并发送响应的服务器.我试图在nginx中使用location指令实现这一点,如下所述: location ~ ^(/?_escaped_fragment_=).*${ proxy_set_header Host $host; prox 我开发了一个基于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 ;    rewrite ^ /crawler$real_url;}

并定义一个“/ crawler”位置,可以将其重定向到HTML生成服务器.

总结

以上是内存溢出为你收集整理的web-applications – 如何使用位置正则表达式通过nginx重定向/处理来自搜索引擎的请求全部内容,希望文章能够帮你解决web-applications – 如何使用位置正则表达式通过nginx重定向/处理来自搜索引擎的请求所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1078650.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存