【问题标题】:How to configure SSL termination on Nginx with a Rails application如何使用 Rails 应用程序在 Nginx 上配置 SSL 终止
【发布时间】:2013-05-02 17:14:04
【问题描述】:

我通过负载均衡器获取 SSL 请求,该负载均衡器正在执行 SSL 终止并将解密的流量发送到端口 81 上的服务器。

我正在运行 Nginx,并设置了一个监听端口 81,我想告诉我的 Rails 应用这是一个 SSL 请求。

这是我的 Nginx 配置的样子:

  server {
    listen 81;

    server_name SERVER;

    root /var/www/app/current/public;
    error_log /var/log/nginx/app-error.log;
    access_log /var/log/nginx/app-access.log;

    passenger_enabled on;

    client_max_body_size 100M;

      location / {

        passenger_enabled on;

        proxy_set_header X-FORWARDED-PROTO https;

      }

  }

它通过了,但 Ruby on Rails 没有检测到请求头 request.headers['X-Forwarded-Proto'],因此它将请求视为非 https。 我应该添加什么才能让 Rails 认为这是一个 SSL 请求?

【问题讨论】:

    标签: ruby-on-rails ssl nginx passenger


    【解决方案1】:

    所以proxy_set_header没有被passenger使用,你需要使用passenger_set_cgi_param来代替:

    passenger_set_cgi_param HTTP_X_FORWARDED_PROTO https;
    

    【讨论】:

      【解决方案2】:

      nginx 指令passenger_set_cgi_param 已被passenger_set_env 取代。 https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#PassengerEnvVar

      对于较新的 nginx,该指令应该是

      passenger_set_cgi_param HTTP_X_FORWARDED_PROTO https;
      

      【讨论】:

        猜你喜欢
        • 2020-07-19
        • 2014-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-08
        • 1970-01-01
        • 2012-08-04
        • 2016-03-17
        相关资源
        最近更新 更多