我正在使用rails 4,我正在向另一台服务器代理GET请求,如下所示:
def proxy_video(path)
self.status = 200
response.headers["x-accel-redirect"] = "/proxy/#{path}"
render text: 'ok'
end
location ~* ^/proxy/(.*?)/(.*) {
internal;
resolver 127.0.0.1;
# Compose download url
set $download_host $1;
set $download_url http://$download_host/$2;
# Set download request headers
proxy_set_header Host $download_host;
# Do not touch local disks when proxying content to clients
proxy_max_temp_file_size 0;
# Stream the file back send to the browser
proxy_pass $download_url?$args;
}
这适用于代理GET请求,例如:
proxy_image('http://10.10.0.7:80/download?path=/20140407_120500_to_120559.mp4')
但是,我想代理一个请求,该请求传递一个不适合GET请求的文件列表.所以我需要传递$args中当前的内容作为POST数据.
我如何代理这个POST数据? – 我需要做一些像response.method =:post或者其他什么的东西吗? – 我在哪里提供我正在发布的参数?
解决方法:
我很确定你不能用Nginx开箱即用.此功能实际上是为加速文件下载而设计的,因此它非常关注GET请求.
也就是说,你可以用lua模块做一些奇特的事情.在编译了包含模块的Nginx版本之后,这样的东西可能会起作用.
Ruby代码:
def proxy_video(path)
self.status = 200
response.headers["x-accel-redirect"] = "/proxy/#{path}"
response.headers["X-Accel-Post-Body"] = "var1=val1&var2=val2"
render text: 'ok'
end
Nginx配置:
location ~* ^/proxy/(.*?)/(.*) {
internal;
resolver 127.0.0.1;
# Compose download url
set $download_host $1;
set $download_url http://$download_host/$2;
rewrite_by_lua '
ngx.req.set_method(ngx.HTTP_POST)
ngx.req.set_body_data(ngx.header["X-Accel-Post-Body"])
';
# Set download request headers
proxy_set_header Host $download_host;
# Do not touch local disks when proxying content to clients
proxy_max_temp_file_size 0;
# Stream the file back send to the browser
proxy_pass $download_url?$args;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。