Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Nginx SSL正在工作,但以http方式发送请求_Ruby On Rails_Ssl_Nginx_Https_Digital Ocean - Fatal编程技术网

Ruby on rails Nginx SSL正在工作,但以http方式发送请求

Ruby on rails Nginx SSL正在工作,但以http方式发送请求,ruby-on-rails,ssl,nginx,https,digital-ocean,Ruby On Rails,Ssl,Nginx,Https,Digital Ocean,我随后将Rails应用程序部署到Digital Ocean 它建议将nginx.conf(/etc/nginx/sites enabled/medical app)保持为 然后我添加了域,然后使用让我们加密安装了SSL 将nginx.conf(/etc/nginx/sites enabled/medical app)更改如下 upstream puma { server unix:///home/myappuser/apps/medical-app/shared/tmp/sockets/me

我随后将Rails应用程序部署到Digital Ocean

它建议将nginx.conf(/etc/nginx/sites enabled/medical app)保持为

然后我添加了域,然后使用让我们加密安装了SSL 将nginx.conf(/etc/nginx/sites enabled/medical app)更改如下

upstream puma {
  server unix:///home/myappuser/apps/medical-app/shared/tmp/sockets/medical-app-puma.sock;
}

server {
  listen 80 default_server deferred;
  # server_name example.com;

  root /home/myappuser/apps/medical-app/current/public;
  access_log /home/myappuser/apps/medical-app/current/log/nginx.access.log;
  error_log /home/myappuser/apps/medical-app/current/log/nginx.error.log info;

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

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

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

server {
  # server_name example.com;
  root /home/myappuser/apps/medical-app/current/public;
  access_log /home/myappuser/apps/medical-app/current/log/nginx.access.log;
  error_log /home/myappuser/apps/medical-app/current/log/nginx.error.log info;

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

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;

    server_name www.medtib.com medtib.com; # managed by Certbot

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.medtib.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.medtib.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = medtib.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = www.medtib.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

  listen 80  ;
    server_name www.medtib.com medtib.com;
    return 404; # managed by Certbot
}
现在https工作正常但是如果我通过Rails配置启用强制SSL

config.force_ssl=true

然后,它会导致错误页面无法处理多次重定向的消息

如果我尝试使用需要https的Facebook登录,则会出现以下错误


我不知道nginx等等。

您应该将X-Forwarded-Proto头转发给您的应用程序,以告知您的应用程序使用了哪种协议。(https,http)

提出以下建议:

proxy_set_header X-Forwarded-Proto $scheme;
之前:

proxy_pass http://puma;

它应该可以做到这一点。

它尝试了添加,但facefook说了同样的话“不安全登录被阻止:您无法从不安全的页面获取访问令牌或登录到此应用。请尝试以https://”的形式重新加载页面:“我的错,在这些更改之后,我不得不执行“sudo service nginx restart”。
proxy_pass http://puma;