Jus*_*wis 5 reverse-proxy redirect
对我来说,这似乎是一个简单的场景:
X
( http://proxy.example.com
)发出反向代理请求X
将请求转发到后端服务器Y
( http://internal1.example.com:8000
)Y
响应3xx
重定向到另一个后端服务器Z
( http://internal2.example.com:8000
)X
拦截3xx 重定向并再次向后端服务器发出请求Z
。它不会将 3xx 重定向返回给客户端。X
用来自后端服务器的重定向请求的结果响应客户端Z
。我需要这个,因为有些客户端似乎不处理重定向(尤其是在执行 PUT 时),所以我希望重定向在代理服务器上以不可见的方式在内部发生。(我实际上在后端运行 WebDAV 服务器,所以我的客户端是 Cyberduck、Nautilus、OSX Finder 等)。
我已经搜索了大量的现有答案,但没有运气(这个问题基本上是我想要的,但没有令人满意的答案,并且它已经一年不活动了。希望从那时起事情就发生了变化)。
如果可能,我想为此使用现有的解决方案。Apache/Nginx 有可能吗?
因此,经过更多的谷歌搜索,并与 IRC 上的 apache 人员聊天后,apache 似乎是不可能的。因此,我查看了 nginx,并设法找到了一个使用X-Accel-Redirect
类似于本答案末尾的配置的解决方案。
查看相关博文:
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;
}
}
Run Code Online (Sandbox Code Playgroud) 归档时间: |
|
查看次数: |
2879 次 |
最近记录: |