ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem;

upstream puma {
  server unix:///home/deploy/apps/chatwoot/shared/tmp/sockets/chatwoot-puma.sock;
}

server {
    listen          80;
    server_name     api.chatwoot.com;
    return          301 https://api.chatwoot.com$request_uri;
}


server {
  listen          443 ssl;
  server_name api.chatwoot.com;

  root /home/deploy/apps/chatwoot/current/public;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
  ssl_prefer_server_ciphers on;
  ssl_stapling on;
  ssl_stapling_verify on;
  ssl_session_cache shared:SSL:128m;
  ssl_session_timeout 120m;

  access_log /home/deploy/apps/chatwoot/current/log/nginx.access.log;
  error_log /home/deploy/apps/chatwoot/current/log/nginx.error.log info;

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

  location ~ /.well-known {
    allow all;
    root /usr/share/nginx/html;
  } 

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