2011-11-17 57 views
7

我已經建立起來在nginx和獨角獸上運行,如Railscasts第293集中所述。Rails重定向在nginx和獨角獸設置上失敗

當我嘗試重定向,如

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

我重定向到http://unicorn/posts代替http://mydomain.com/posts

這裏是我的應用程序

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; 
} 
+0

我有一個類似的設置,但不是'位置@ unicorn'我'位置/'。你嘗試過嗎? – Frost

+0

@MartinFrost是的,沒有幫助。在我看來,它使用proxy_pass URL作爲基本URL,而不是域名。 –

+0

你也可以發佈你的'./config/unicorn.rb'內容嗎?例如「listen」指令的行。 – Tilo

回答

5

這對我的作品nginx.conf :

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 
相關問題