I’m going to be dual-booting this blog post to talk about SSL certificates! We have a variety of Windows and Linux servers hosting websites here at liquidfish. One of the things that comes up fairly often is SSL certificates for these sites. I thought it would make for an interesting contrast if I went through the process of installing an SSL certificate in both Windows and Linux. In this case we are using Windows running IIS and Linux running nginx.
This would also have the added benefit of documenting this process for internal use. I’m talking to you developers!
Generate your certificate signing request (CSR)
- Open Internet Information Services (IIS) Manager
- Click the server name in the left pane and double click "Server Certificates" in the middle pane
- Click "Create Certificate Request…" in the right pane
- Fill out the fields on this screen as described below
- Common name: URL of the website
- Organization: Organization registering the site
- Organizational unit: Department within the organization registering the site
- City/locality: Site of organization
- State/province: State of organization
- Country/region: Country of organization
- Choose your cryptographic service provider and bit length.
- *At this point in time, you should be using a bit length of 2048. A coworker sent me a great post that explains why that is among other things here.
- Choose a location to save your CSR file
- Run "sudo openssl req -new -newkey rsa:2048 -nodes -keyout ~/example-url.com.key -out ~/example-url.com.csr"
- "-newkey rsa:2048" - indicates that this will be using RSA encryption at a 2048 bit length
- "-keyout ~/example-url.com.key -out ~/example-url.com.csr" - specifies a destination path and name for the key and csr files
- Fill out the fields on screen as described below
- Country Name (2 letter code) [XX]: Country of the registering organization
- State or Province Name (full name) : State of the registering organization
- Locality Name (eg, city) [Default City]: City of the registering organization
- Organization Name (eg, company) [Default Company Ltd]: Name of the registering organization
- Organizational Unit Name (eg, section) : Department within the organization registering the site
- Common Name (eg, your name or your server's hostname) : URL of the website
- Email Address : Not required
- A challenge password : Not required, but can be used to verify the authenticity of the certificate sent by the Certificate Authority issuing the SSL certificate.
- An optional company name : Not required
At this point, you have a CSR file and the next steps can vary depending on the company from whom you are buying your SSL certificate. In general you will upload or paste the contents of your CSR file to the website where you are purchasing the SSL. You will be required to verify your ownership of the domain through various methods, after which you will be able to download your certificate.
When it comes to domain verification, I personally prefer html verification. This means you download a file and upload it to your website’s root directory on the server. This file should then be accessible to the public from http://example-url.com/verification-file.html. This comes in handy when you do not actually own the domain or control DNS for the domain for which you are purchasing the SSL.
Apply your SSL certificate
- Open Internet Information Services (IIS) Manager.
- Click the server name in the left pane and double click "Server Certificates" in the middle pane.
- Click "Complete Certificate Request…" in the right pane.
- Use the file navigator or type out the full path to the certificate file provided by your CA earlier and give a simple name for the certificate.
- In the left pane, right click the website that will be using the certificate and click "Edit Bindings".
- In the "Site Bindings" window click "Add".
- In the new window change the "Type" to "https" and select the certificate you added earlier from the "SSL certificate" drop down.
- You’re done!
- Upload the certificate file to the server.
- Move the certificate file and the key file (created earlier when you generated the CSR request) into your central repository (commonly /etc/nginx/ssl for nginx).
- Modify the site’s nginx config. The boldface lines below were added in this step.
- The first "server" block is redirecting all http requests to https.
- The second server block is listening for https requests.
- You can see that "ssl_certificate" and "ssl_certificate_key" are pointed at the certificate and key files we moved in step 2.
- If you are more interested in what the other lines in bold do then I suggest you check out this article.
return 301 https://example-url.com$request_uri;
listen 443 ssl;
server_name example-url.com www.example-url.com;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
index index.html index.php;
That’s it when it comes to installing certificates in Windows running IIS and Linux running nginx! It wasn’t until I reread this post that I noticed how many more steps there are to installing SSLs in Windows. It gave me the idea to try generating a CSR and installing an SSL certificate purely using Powershell on Windows to simplify the process. I might have to write a blog post about that!