は、私は私のAPIコントローラの使用SSLを持つようにしたいので、私は別の問題なくnginxののconftestを渡し、私のnginx.confRailsアプリケーションでforce_sslを使用して無限リダイレクトループを取得するのはなぜですか?
upstream unicorn {
server unix:/tmp/unicorn.foo.sock fail_timeout=0;
}
server {
listen 80 default deferred;
listen 443 ssl default;
ssl_certificate /etc/ssl/certs/foo.crt;
ssl_certificate_key /etc/ssl/private/foo.key;
server_name foo;
root /var/apps/foo/current/public;
try_files $uri/system/maintenance.html $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;
}
error_page 502 503 /maintenance.html;
error_page 500 504 /500.html;
keepalive_timeout 5;
}
にディレクティブを聞く追加しました。私も自分のApiControllerにforce_ssl
ディレクティブを追加しました私はSSLを使用していませんでしたが、今私はcurl --LI http://foo/api/auth.json
しようとすると、私はきちんとhttps
にリダイレクトが、その後、私はリダイレクト取得し続けたときにうまく働いた
class ApiController < ApplicationController
force_ssl if Rails.env.production?
def auth
user = User.authenticate(params[:username], params[:password])
respond_to do |format|
format.json do
if user
user.generate_api_key! unless user.api_key.present?
render json: { key: user.api_key }
else
render json: { error: 401 }, status: 401
end
end
end
end
def check
user = User.find_by_api_key(params[:api_key])
respond_to do |format|
format.json do
if user
render json: { status: 'ok' }
else
render json: { status: 'failure' }, status: 401
end
end
end
end
end
無限のリダイレクトループで終了するhttp://foo/api/auth
になります。
私のルートは、単にRubyの上で、私はRailsの3.2.1を使用してい
get "api/auth"
get "api/check"
を持っているがnginxの0.7.65
純粋な魔法。 :) 私の場合は、RailsサイトをVarnishを使用して移動していました。このサイトは純粋なHTTPSであり、VarnishはSSLをサポートしておらず、Passengerはポートではなくソケットを公開しているため、Narnxサーバーの2つの設定が必要でした。ポート443のHTTPS設定からPassengerソケット接続を離すと、リダイレクトループが発生しました。これで解決しました。ありがとうございました! –