HTTP反向代理内部redirect

对我来说,这似乎是一个简单的情况:

  • 客户端请求在服务器X反向代理http://proxy.example.com
  • 服务器X将请求转发到后端服务器Yhttp://internal1.example.com:8000
  • 后端服务器Y响应3xxredirect到另一个后端服务器Zhttp://internal2.example.com:8000
  • 代理服务器X 拦截 3xxredirect,并再次将请求发送到服务器Z后端。 它不会将3xxredirect返回给客户端。
  • 代理服务器X以来自后端服务器Z的redirect请求的结果来响应客户端。

我需要这个,因为有些客户端似乎没有处理redirect(特别是当做PUT),所以我希望redirect发生在代理服务器上无形和内部。 (我实际上在后端运行WebDAV服务器,所以我的客户端是Cyber​​duck,Nautilus,OSX Finder等)。

我已经search了大量的现有答案,但没有运气( 这个问题基本上是我想要的,但没有令人满意的答案,一年以来一直没有任何效果,希望事情从那时起就改变了)。

如果可能的话,我想使用现有的解决scheme。 Apache / Nginx有可能吗?

所以经过更多的search,以及与IRC上的apache人聊天,这似乎是不可能的与Apache。 所以我看了一下nginx,并设法使用X-Accel-Redirect来find一个类似于这个答案结尾处的configuration的解决scheme。

查看相关的博客文章:

  • http://kovyrin.net/2010/07/24/nginx-fu-x-accel-redirect-remote/
  • http://kovyrin.net/2006/11/01/nginx-x-accel-redirect-php-rails/

     server { listen 80; server_name example.com; location / { proxy_pass http://localhost:8000/; proxy_redirect http://localhost:8001 http://$host:8001; 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 download location ~* ^/internal_redirect/(.*?)/(.*) { # Do not allow people to mess with this location directly # Only internal redirects are allowed internal; # Location-specific logging access_log internal_redirect.access.log main; error_log internal_redirect.error.log debug; # Extract download url from the request set $download_uri $2; set $download_host $1; # Compose download url set $download_url http://$download_host/$download_uri?$args; # Set download request headers proxy_set_header Host $download_host; proxy_set_header Authorization ''; # The next two lines could be used if your storage # backend does not support Content-Disposition # headers used to specify file name browsers use # when save content to the disk # proxy_hide_header Content-Disposition; # add_header Content-Disposition 'attachment; filename="$args"'; # Do not touch local disks when proxying # content to clients proxy_max_temp_file_size 0; # Download the file and send it to client # This is where the magic happens proxy_pass $download_url; } }