【问题标题】:Redirection loop with NGinx on a rails application with ssl在带有 ssl 的 rails 应用程序上使用 NGinx 进行重定向循环
【发布时间】:2014-06-17 17:21:33
【问题描述】:

我知道有很多关于类似问题的问题,但我可以找到适合我的案例的解决方案。我有这个 nginx 配置:

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

server {
  listen 80 default deferred;
  # server_name example.com;
  root /home/deployer/apps/lescollectionneurs/current/public;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control 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;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

server {
  listen 443 default ssl;
  # server_name example.com;
  root /home/deployer/apps/lescollectionneurs/current/public;

  ssl on;
  ssl_certificate /etc/ssl/certs/myssl.crt;
  ssl_certificate_key /etc/ssl/private/myssl.key;

  ssl_session_timeout 5m;

  ssl_protocols sslv3 tlsv1 tlsv1.1 tlsv1.2;
  ssl_ciphers HIGH:!aNULL:!MD5;
  ssl_prefer_server_ciphers on;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control 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;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

在我的 rails 应用程序中,我有 config.force_ssl = true。当我登录 nginx 的日志时,我有一个重定向循环,它在浏览器中失败。我的生产日志中没有任何内容。

我能做什么?

【问题讨论】:

    标签: ruby-on-rails ssl nginx


    【解决方案1】:

    解决方案只是在 ssl 部分的location 块中添加proxy_set_header X-Forwarded-Proto $scheme;

    【讨论】:

      猜你喜欢
      • 2014-06-01
      • 1970-01-01
      • 2015-04-19
      • 2015-02-26
      • 2019-09-20
      • 2015-02-15
      • 1970-01-01
      • 2016-01-31
      • 1970-01-01
      相关资源
      最近更新 更多