Install with apt-get
$ sudo apt-get update
$ sudo apt-get install letsencrypt
$ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
Generate the templates to customize
$ bundle exec rails g capistrano:unicorn_nginx:config
Copy the contents of nginx.conf.erb into the template file generated by capistrano-unicorn-nginx. Now run a setup to have the well-known directory already linked, so letsencrypt can be started:
$ bundle exec cap production setup
On the server, start letsencrypt. Webroot must be pointed to /usr/share/nginx/html.
$ sudo letsencrypt certonly -a webroot --webroot-path=/usr/share/nginx/html -d myhost.com
And follow the steps for the authentication. After the cert is generated, the certfiles will be in /etc/letsencrypt/live/myhost.com. Capistrano-unicorn-nginx is looking for cert files in /etc/ssl, so we want to just symlink.
$ sudo ln -s /etc/letsencrypt/live/myhost.com /etc/ssl/certs
$ sudo ln -s /etc/letsencrypt/live/myhost.com /etc/ssl/private
In deploy/production.rb add the configuration for the ssl cert:
set :nginx_use_ssl, true
set :nginx_upload_local_cert, false
set :nginx_ssl_cert, "#{fetch(:nginx_server_name)}/fullchain.pem"
set :nginx_ssl_cert_key, "#{fetch(:nginx_server_name)}/privkey.pem"
Now once again, run setup through capistrano
$ bundle exec cap production setup
If needed, restart unicorn and nginx.
$ sudo crontab -e
add the following lines:
30 2 * * 1 /usr/bin/letsencrypt renew >> /var/log/le-renew.log
35 2 * * 1 /bin/systemctl reload nginx
Done!
Great =)!!