Enabling SSL in Nginx

Last year I quickly commented how to enable SSL on Apache. Now I’ll do the same for Nginx, which has been my primary HTTP server choice since then, BTW.

First, create the certificates:
cd /etc/nginx/
sudo openssl genrsa -out localhost.key 1024
sudo openssl req -new -key localhost.key -x509 -out localhost.crt
sudo chmod 600 localhost.*

Then edit /etc/nginx/sites-available/default and put the important parts:
server {
listen 443 ssl default_server;
ssl_certificate /etc/nginx/ssl/localhost.crt;
ssl_certificate_key /etc/nginx/ssl/localhost.key;

Finally reload Nginx:
sudo service nginx reload

That’s it!

PS: These tips are for development pruposes. In production you’ll need a chained certificate (aka certificate bundle).