ruby-on-rails - Rails 重定向在 nginx 和 gunicorn 设置上失败

标签 ruby-on-rails ruby redirect nginx unicorn

我已经按照 Railscasts 第 293 集中的描述设置了在 nginx 和 unicorn 上运行。

当我尝试重定向时,例如

class PostsController < ApplicationController
  def show
    redirect_to posts_path, :notice => "Test redirect"
  end
end

我被重定向到 http://unicorn/posts 而不是 http://mydomain.com/posts

这是我的应用程序的 nginx.conf

upstream unicorn {
  server unix:/tmp/unicorn.scvrush.sock fail_timeout=0;
}

server {
  listen 80 default deferred;
  # server_name example.com;
  root /var/apps/current/public;  

  try_files $uri/index.html $uri @unicorn;

  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

  keepalive_timeout 5;
}

最佳答案

这对我有用:

upstream unicorn {
  server unix:/tmp/unicorn.example.sock fail_timeout=0;
}

server {
  listen       80;
  listen       localhost;
  server_name  www.example.com;
  keepalive_timeout 5;

  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # this is required for HTTPS:                                                                                                                                                                                                                                             
    # proxy_set_header X-Forwarded-Proto https;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

}

在我的 ./config/unicorn.rb 文件中:

# Listen on a Unix data socket                                                                                                                                                                                                                                                                                  
listen "/tmp/unicorn.example.sock", :backlog => 64

关于ruby-on-rails - Rails 重定向在 nginx 和 gunicorn 设置上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8164554/

相关文章:

javascript - 将数据属性添加到 selectize.js 选项

ruby-on-rails - 如何在测试环境中干净地 stub REST 客户端

ruby - 将重试的 sidekiq 作业放在队列的开头

javascript - 元刷新重定向到顶部框架

ruby-on-rails - Rails act_as_taggable,标签在编辑时丢失逗号!?成为一

ruby-on-rails - gem 安装是如何工作的? gem 是如何获取安装文件的?

ruby - 我无法在 cygwin 上启动 Chef

javascript - 如何让页面重新加载RoR中指定的div?

apache - .htaccess 中用于 index.php 查询参数的 URL RewriteRule

ruby-on-rails - Devise-登录后自动从根URL重定向