Nginx +乘客+rails:在发布请求时收到 405 错误
当我向 Rails 控制器操作调用发布请求时,出现 405 错误。 post 请求用于获取 json 文件,而 get 请求提供标准 html 页面。 问题是html被缓存了。
我在 http 上看到了此问题的解决方案: //millarian.com/programming/ruby-on-rails/nginx-405-not-allowed-error/
if ($request_method != GET) {
proxy_pass http://foobar;
break;
}
proxy_pass 中的 url 通常是 mongrel 服务器的 url。乘客有类似的解决方案吗?
我是一个完整的 nginx 新手,正在尝试从 apache 迁移。
I'm having a 405 error when I call a post request to a rails controller action.
The post request is used to get a json file wile the get request delivers a standard html page.
The problem is that the html is cached.
I've seen a solution for this problem on http://millarian.com/programming/ruby-on-rails/nginx-405-not-allowed-error/
if ($request_method != GET) {
proxy_pass http://foobar;
break;
}
the url in proxy_pass is the normally the url for the mongrel server. Is there similar solution for passenger ?
I'm a complete nginx newbie, trying to migrate from apache.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于找到了解决办法。
我有一组重写条件来处理我的 Rails 配置使用的缓存目录。
...
即使请求是 POST,也会应用这些重写,从而导致 405 错误。
仅当请求是 GET 时,我才设法应用重写。我不确定这是否是最有效的解决方案,但它似乎有效。学习如何在 Nginx 中处理多种情况是最棘手的部分。 (来源:http://wiki.nginx.org/RewriteMultiCondExample)
有更好的解决方案吗?
I finally found a way around.
I had a set of rewrite conditions to deal with the cache directory my configuration of Rails uses.
...
Those rewrites were applied even if the request was a POST, leading to the 405 error.
I managed to apply the rewrite only if the request is a GET. I'm not sure if it is the most efficient solution, but it seems to work. Learning how to deal with multiple conditions in Nginx was the trickiest part. (source : http://wiki.nginx.org/RewriteMultiCondExample)
Any better solution?