簡體   English   中英

為什么SSL重定向不能與force_ssl和Nginx一起使用?

[英]Why is SSL redirect not working with force_ssl and Nginx?

我有一個Rails 3.2.13應用程序,我試圖為Nginx和Unicorn配置SSL。 我希望能夠將一些控制器和一些控制器操作告訴'force_ssl'並正確地重定向。 我已經能夠使這個工作,所以我可以用' https://foo.com '手動點擊應用程序,並且工作正常。 當我將'force_ssl'放入控制器動作時,讓我們說用戶#index:

class UsersController < ApplicationController
  force_ssl

  def index
    # do some stuff
  end

end

我希望如果我導航到'http://foo.com/users' ,它會重定向到'https://foo.com/users'. 它不是。

相反,它重定向到: 'https://unicorn_foo/users' 我錯過了什么?

nginx.conf:

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

server {
    listen 80 default;
    server_name foo.com;
    root /home/webuser/apps/foo/current/public;

    location ^~ /assets/ {
        gzip_static on;
        expires max;
        add_header Cache-Control public;
    }

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

    location @unicorn_foo {
        proxy_set_header X-Forwarded-Proto http;
        proxy_pass http://unicorn_foo;
    }
    error_page 500 502 503 504 /500.html;
    client_max_body_size 5G;
    keepalive_timeout 10;
    send_timeout 240;
    sendfile_max_chunk 5m;
}

server {
    listen 443;
    server_name foo.com;
    root /home/webuser/apps/foo/current/public;

    location ^~ /assets/ {
        gzip_static on;
        expires max;
        add_header Cache-Control public;
    }

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

    location @unicorn_foo {
        proxy_set_header  X-Real-IP       $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header  X-Forwarded-Proto https;
        proxy_set_header  Host $http_host;
        proxy_redirect    off;
        proxy_pass http://unicorn_foo;
    }
    error_page 500 502 503 504 /500.html;
    client_max_body_size 5G;
    keepalive_timeout 10;

    ssl on;
    ssl_certificate         /etc/nginx/ssl/server.crt;
    ssl_certificate_key     /etc/nginx/ssl/server.key;
    ssl_protocols           SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers             ALL:-ADH:+HIGH:+MEDIUM:-LOW:-SSLv2:-EXP;
    ssl_session_cache       shared:SSL:10m;

    send_timeout 240;
    sendfile_max_chunk 5m;
}

首先猜測...端口80服務器塊沒有通過主機,也許就是這樣嗎?

proxy_set_header  Host $http_host;

SSL塊可以,但是如果你非SSL端開始並且Rails選擇它,那么它可能沒有完整的頭?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM