ruby-on-rails – 使用带有Rails的X-Accel-Redirect创建POST请求
发布时间:2020-12-17 02:06:17 所属栏目:百科 来源:网络整理
导读:我正在使用rails 4,我正在向另一台服务器代理GET请求,如下所示: def proxy_video(path) self.status = 200 response.headers["X-Accel-Redirect"] = "/proxy/#{path}" render text: 'ok'end 在我的nginx配置中,我有这个: location ~* ^/proxy/(.*?)/(.*) {
我正在使用rails 4,我正在向另一台服务器代理GET请求,如下所示:
def proxy_video(path) self.status = 200 response.headers["X-Accel-Redirect"] = "/proxy/#{path}" 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; # 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; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |