Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.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
Ruby on rails 使用Rails的X-Accel-Redirect创建POST请求?_Ruby On Rails_Nginx_Proxy - Fatal编程技术网

Ruby on rails 使用Rails的X-Accel-Redirect创建POST请求?

Ruby on rails 使用Rails的X-Accel-Redirect创建POST请求?,ruby-on-rails,nginx,proxy,Ruby On Rails,Nginx,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;

我正在使用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数据传递


我如何代理此帖子数据我需要像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;
  }

哇,谢谢你我会很快尝试并报告!正在等待您的报告@Hackeron;-)事实上,我能够在nginx1.4.6中的所有方法中使用X-Accel进行代理,但是这不再适用于1.10.1。试图找出这是一个修复还是一个选项。它在Nginx 1.10.3中不起作用。ngx.header[“X-Accel-Post-Body”]返回零。因此,我担心RoR的头不会传递到内部重定向?在较旧版本的nginx中,X-Accel实际上更加灵活,允许POST请求等。我认为大约1.9.x是“固定的”。我一直在寻找一种方法来为最新版本做到这一点,但现在我一直坚持旧版本,它的工作良好。