2011-11-17 10 views
7

Railscasts#293で説明されているように、nginxとunicornで実行するようにセットアップしました。このようnginxとunicornの設定でRailsのリダイレクトが失敗する

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

として

私はリダイレクトしようと、私が代わりにhttp://mydomain.com/posts

http://unicorn/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うん、助けてくれなかった。それは、ドメイン名ではなく、ベースURLとしてproxy_pass 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 
関連する問題