CloudFlare SSL 完整版 Nginx Puma Rails

CloudFlare SSL 完整版 Nginx Puma Rails

我有一个启用了 force_ssl 的 rails 应用。我生成了 DH 参数,我使用 Puma 作为 Web 服务器。对于此配置,我可以使用自分配的 SSL 证书,该证书与密钥一起生成并放置在 etc/ssl 中

我的域名是在 cloudflare 上设置的,并且我启用了“完整”SSL

我的 nginx 配置如下。我认为我的问题的解决方案可能在于此设置:

upstream puma {
  server unix:///home/user/app/production/shared/tmp/sockets/puma.sock;
}

server {
  server_name 123.123.12.123;
  add_header X-Frame-Options "SAMEORIGIN";
  return 301 https://awebsite.com$request_uri;
}
server {
  server_name awebsite.com www.awebsite.com;
  add_header X-Frame-Options "SAMEORIGIN";
  return 301 https://awebsite.com$request_uri;
}
server {
  listen 443;
  server_name www.awebsite.com;
  add_header X-Frame-Options "SAMEORIGIN";
  return 301 https://awebsite.com$request_uri;
}

# Server configuration
server {
  listen 80;
  listen 443 default ssl;
  server_name awebsite.com;

  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_dhparam /etc/ssl/dhparams.pem;
  ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
  ssl_prefer_server_ciphers on;
  ssl_session_cache shared:ssl_session_cache:10m;
  ssl_certificate /etc/ssl/server.crt;
  ssl_certificate_key /etc/ssl/server.key;

  root /home/user/app/production/current/public;
  access_log /home/user/app/production/current/log/nginx.access.log;
  error_log /home/user/app/production/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 X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

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

我收到此 nginx 错误:

2016/12/05 17:33:08 [info] 16279#16279: *1 epoll_wait() reported that client prematurely closed connection, so upstream connection is closed too while sending request to upstream, client: 123.123.12.123, server: awebsite.com, request: "GET / HTTP/1.1", upstream: "http://unix:///home/user/app/production/shared/tmp/sockets/puma.sock:/", host: "awebsite.com", referrer: "https://awebsite.com/"

答案1

日志显示您的上游是错误的 - 您说的是 http 和 unix。日志条目显示:

http://unix:///home/user/app/production/shared/tmp/sockets/puma.sock:/

这是由这些原因造成的

upstream puma {
  server unix:///home/user/app/production/shared/tmp/sockets/puma.sock;
}

proxy_pass http://puma;

弄清楚如何将请求发送给 puma 并适当地配置服务器。

相关内容