加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

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

发布时间:2020-12-13 21:01:30 所属栏目:Nginx 来源:网络整理
导读:我按照Railscasts第293集中的描述设置了nginx和unicorn. 当我尝试重定向时,例如 class PostsController 我被重定向到http:// unicorn / posts而不是http://mydomain.com/posts 这是我的应用程序的nginx.conf upstream unicorn { server unix:/tmp/unicorn.s

我按照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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读