# don't send the nginx version number in error pages and Server header
server_tokens off;

# redirect all http traffic to https
server {
  listen 80;
  server_name transfer.example.com;
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl;
  server_name transfer.example.com;

  error_log  /var/log/nginx/transfer-error.log warn;
  access_log  /var/log/nginx/transfer-access.log main;
  
  ### SSL ###
  ssl_certificate /etc/nginx/certs/transfer.example.com/fullchain.pem;
  ssl_certificate_key /etc/nginx/certs/transfer.example.com/key.pem;

  # enable session resumption to improve https performance
  # http://vincent.bernat.im/en/blog/2011-ssl-session-reuse-rfc5077.html
  ssl_session_cache shared:SSL:50m;
  ssl_session_timeout 5m;

  # openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
  ssl_dhparam /etc/nginx/ssl/dhparams.pem;

  # enables server-side protection from BEAST attacks
  # http://blog.ivanristic.com/2013/09/is-beast-still-a-threat.html
  ssl_prefer_server_ciphers on;
  # disable SSLv3(enabled by default since nginx 0.8.19) since it's less secure then TLS http://en.wikipedia.org/wiki/Secure_Sockets_Layer#SSL_3.0
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  # ciphers chosen for forward secrecy and compatibility
  # http://blog.ivanristic.com/2013/08/configuring-apache-nginx-and-openssl-for-forward-secrecy.html
  ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";


  location / {
    # Bind PsiTransfer to localhost interface
    # ie with PSITRANSFER_IFACE=127.0.0.1
    proxy_pass "http://127.0.0.1:3000";

    proxy_http_version 1.1;
    proxy_buffering off;
    proxy_request_buffering off;      # needs nginx version >= 1.7.11
    proxy_set_header Host $http_host;
  }
}
