Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Web applications 如何使用location regex通过nginx重定向/处理来自搜索引擎的请求_Web Applications_Nginx_Server Configuration - Fatal编程技术网

Web applications 如何使用location regex通过nginx重定向/处理来自搜索引擎的请求

Web applications 如何使用location regex通过nginx重定向/处理来自搜索引擎的请求,web-applications,nginx,server-configuration,Web Applications,Nginx,Server Configuration,我开发了一个基于ajax的web应用程序,其中包含hash-bang URL 我试图将搜索引擎的请求重定向到另一台服务器,该服务器生成HTML快照并发送响应。我正试图通过以下提到的location指令在nginx中实现这一点: location ~ ^(/?_escaped_fragment_=).*$ { proxy_set_header Host $host; proxy_set_header X-Real-IP

我开发了一个基于ajax的web应用程序,其中包含hash-bang URL

我试图将搜索引擎的请求重定向到另一台服务器,该服务器生成HTML快照并发送响应。我正试图通过以下提到的location指令在nginx中实现这一点:

      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;
      }
但我无法让它工作。有人可以纠正我正在使用的正则表达式(或)为我提供一个替代解决方案来实现这一点


提前感谢。

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

请注意,所有类型的位置只测试请求行的URI部分,而不测试参数。之所以这样做是因为查询字符串中的参数可以通过多种方式给出,例如:

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

您可以在服务器部分(找到)设置重写规则:


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

我通过以下方式解决了此问题:

if ( $arg__escaped_fragment_ ) {
    return 301 $uri$arg__escaped_fragment_;
}
if ( $arg__escaped_fragment_ ) {
    return 301 $uri$arg__escaped_fragment_;
}