-1

I have a rails app with force_ssl turned on. I generated DH params I'm using Puma as web server. For this configuration, I'm fine with a self-assigned ssl cert, which I generated together with a key and placed in etc/ssl

My domain is set up on cloudflare and I turned "Full" SSL

My nginx config is as follows. I think the solution to my problem is probably in this setting:

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;
}

I'm getting this nginx error:

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/"
Tim
  • 31,888
  • 7
  • 52
  • 78
Ben
  • 111
  • 3
  • You haven't said what problem you're trying to solve. Please edit your question to clarify. If logs are relevant please include them. – Tim Dec 05 '16 at 22:29
  • @Tim I added the error I get – Ben Dec 05 '16 at 22:36
  • and then I get: 2016/12/05 17:34:08 [error] 16279#16279: *3 upstream timed out (110: Connection timed out) while reading response header from 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" 2016/12/05 17:34:08 [info] 16279#16279: *3 client 162.158.59.123 closed keepalive connection – Ben Dec 05 '16 at 22:40
  • Anything in puma logs? – SYN Dec 05 '16 at 22:41

1 Answers1

0

Logs say your upstream is wrong - you've said both http and unix. Log entry says:

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

This is caused by these

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

proxy_pass http://puma;

Work out how you want to get the requests to puma and configure the server appropriately.

Tim
  • 31,888
  • 7
  • 52
  • 78
  • Time. I am not sure what this actually means. My issue was resolved because of a syntax error in rails that did not pick up on development. But I would really love to know if I'm doing something else wrong and how I should fix it. Do you mean I'm supposed to remove proxy_pass http://puma;? Anyhow, thank you both for your help. I really appreciate it! – Ben Dec 05 '16 at 22:58
  • You never actually said what problem you were having, you just gave log entries. My guess was that the URL at the top of my answer "http://unix:///" was probably incorrect, and could be causing a problem. URLs tend to be http:// or unix:// rather than both. – Tim Dec 05 '16 at 23:25