{"id":184,"date":"2017-12-17T11:44:41","date_gmt":"2017-12-17T11:44:41","guid":{"rendered":"https:\/\/learningcurve.xyz\/?p=184"},"modified":"2017-12-19T04:49:47","modified_gmt":"2017-12-19T04:49:47","slug":"alibaba-cloud-3-lets-encrypt-ssl","status":"publish","type":"post","link":"https:\/\/learningcurve.xyz\/?p=184","title":{"rendered":"Alibaba Cloud 3 &#8211; Let&#8217;s Encrypt SSL"},"content":{"rendered":"<p>Welcome to the third tutorial in this series about installing WordPress and a performant server stack on an Alibaba ECS Cloud Instance.<\/p>\n<p>In the previous two tutorials, we <a href=\"https:\/\/learningcurve.xyz\/2017\/10\/09\/alibaba-cloud-2-secure-an-ubuntu-server\/\" target=\"_blank\" rel=\"noopener\">provisioned and secured our Ubuntu 16.04 server <\/a> installation, then <a href=\"https:\/\/learningcurve.xyz\/2017\/10\/10\/alibaba-cloud-2-lemp-stack\/\" target=\"_blank\" rel=\"noopener\">completed the LEMP stack with NGINX, MariaDB and PHP7<\/a>. Today we are going to configure a Domain to work with our server, and secure everthing with an SSL certificate so our final WordPress site can only be accessed via HTTPS. In the next tutorial we will complete the series by <a href=\"https:\/\/learningcurve.xyz\/2017\/10\/12\/alibaba-cloud-4-install-wordpress\/\" target=\"_blank\" rel=\"noopener\">installing WordPress<\/a>, and configuring transactional emails.<\/p>\n<p>As with all of these tutorials, the instructions should generally stand for any of the main cloud providers. This tutorial has some steps specific to Alibaba Cloud, mainly regarding configuring the security group for inbound access to port 443, but they are minor and can be skipped over for other providers.<\/p>\n<div class=\"highlighted advice\">\n<h4>A few words about Domain Registration<\/h4>\n<p>Many people will register a domain through their hosting company, I recommend against that. I much prefer to keep my domain registration and hosting separate, this provides a more robust framework in case of unseen problems with your hosting providers infrastructure. That is to say, if your hosting goes down but your domain is registered elswhere, then it is very easy to just change your nameservers and get your site back online quickly.<\/p>\n<\/div>\n<p>I recommend <a href=\"https:\/\/www.namecheap.com\/\" target=\"_blank\" rel=\"noopener\">Namecheap<\/a> or <a href=\"https:\/\/iwantmyname.com\/\" target=\"_blank\" rel=\"noopener\">iwantmyname<\/a>\u00a0for domain registry, they are primarily domain registrars and resolve DNS and Nameserver changes quickly.<\/p>\n<p>It goes without saying that you&#8217;ll need to have a registered domain to use for this tutorial, in my case I have a domain registered with Namecheap specifically for testing purposes and tutorials, the aptly chosen <a href=\"http:\/\/an-example-domain.com\">an-example-domain.com<\/a><\/p>\n<h2>Part One &#8211; Configuring your Domain<\/h2>\n<h2>Step 1. Add a Domain to Alibaba Cloud DNS<\/h2>\n<p>Visit your Alibaba ECS console and make your way to the Alibaba Cloud DNS section. Then click the blue button in the top left to add a Domain Name:<\/p>\n<figure id=\"attachment_179\" aria-describedby=\"caption-attachment-179\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-179 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/add_3rd_party_domain_alibaba-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-179\" class=\"wp-caption-text\">Add a domain in Alibaba Cloud DNS<\/figcaption><\/figure>\n<p>A pop up box will appear with a text entry field, enter your domain name here and confirm:<\/p>\n<figure id=\"attachment_180\" aria-describedby=\"caption-attachment-180\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-180 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/enter_domain_name-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-180\" class=\"wp-caption-text\">Enter your domain and confirm<\/figcaption><\/figure>\n<p>Your domain will now appear in the list of Domain Names in the Alibaba Cloud DNS settings page.<\/p>\n<p>Now we need to configure some DNS records to get everything working properly. Click the configure link that is highlighted in the screenshot below:<\/p>\n<figure id=\"attachment_181\" aria-describedby=\"caption-attachment-181\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-181 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/configure_domain-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-181\" class=\"wp-caption-text\">Click the link to configure DNS records<\/figcaption><\/figure>\n<p>The link will take you to a configurations page where you can add your DNS records:<\/p>\n<figure id=\"attachment_182\" aria-describedby=\"caption-attachment-182\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-182 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/nameserver_error-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-182\" class=\"wp-caption-text\">Alibaba DNS gives you Nameserver redirection instructions<\/figcaption><\/figure>\n<p>In my case, as mentioned earlier, my domain is registered with a third party domain registrar, that means my domain is using my registrar&#8217;s domain name server. As you can see in the screenshot above, Alibaba cloud DNS immediately checks the records and throws a warning telling me that I need to change my domain&#8217;s nameservers.<\/p>\n<h2>Step 2. Change Nameservers at your domain registrar<\/h2>\n<p>To do that, go to your domain registrar and locate the setting for DNS. Somewhere in the settings there will be a button for &#8216;Change Nameservers&#8217; or &#8216;Use Custom Nameservers&#8217;, or something similar. With my domain at Namecheap it&#8217;s found in a dropdown called &#8216;Custom DNS&#8217; under the &#8216;Nameservers&#8217; setting, illustrated below:<\/p>\n<figure id=\"attachment_183\" aria-describedby=\"caption-attachment-183\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-183 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/change_your_domains_nameservers-600x120.png\" alt=\"\" width=\"600\" height=\"120\" \/><figcaption id=\"caption-attachment-183\" class=\"wp-caption-text\">Change your domain nameservers with your domain registrar<\/figcaption><\/figure>\n<p>Enter the nameservers provided by Alibaba and click save.<\/p>\n<h2>Step 3. Enter DNS records<\/h2>\n<p>Now return to the Alibaba Cloud DNS settings page, and add DNS records for your domain. For this tutorial we are only adding two <span class=\"grey-code\"> A<\/span> records. <span class=\"grey-code\"> A<\/span> records are for your server&#8217;s ipv4 address, if this were a production site you would also need to add matching <span class=\"grey-code\"> AAAA<\/span> records for ipv6 address, and several other records, such as an <span class=\"grey-code\"> MX<\/span> record for your email server etc.<\/p>\n<p>Add one type <span class=\"grey-code\"> A<\/span> record for the Host <span class=\"grey-code\"> @<\/span>, and another for the Host <span class=\"grey-code\"> www<\/span>. The shortest TTL (Time Till Live) setting allowed by Alibaba&#8217;s DNS system is 10 minutes, which means that these changes will take at least that long to take effect on their end, although for changes to propagate across the internet can take up to 24 hours or more.<\/p>\n<p>Your settings should look something like this:<\/p>\n<figure id=\"attachment_184\" aria-describedby=\"caption-attachment-184\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-184 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/configured_dns_records_www_@-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-184\" class=\"wp-caption-text\">Configure the domains A records<\/figcaption><\/figure>\n<p>Did I mention that I find that changes in DNS settings made with dedicated domain registrars tend to propagate faster than with hosting providers? I did, my apologies for belaboring a point.<\/p>\n<p>In any case, you can check to see if your DNS changes have propagated with a service like <a href=\"https:\/\/www.whatsmydns.net\/\" target=\"_blank\" rel=\"noopener\">whatsmydns.com<\/a> or by using the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dig_(command)\" target=\"_blank\" rel=\"noopener\">Domain Information Groper<\/a> <span class=\"grey-code\">dig<\/span> terminal command.<\/p>\n<h2>Step 4. Test your domain<\/h2>\n<p>Once these changes have propagated you should be able to visit your site by using the domain, with or without the www subdomain:<\/p>\n<figure id=\"attachment_185\" aria-describedby=\"caption-attachment-185\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-185 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/domain_being_served-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-185\" class=\"wp-caption-text\">http:\/\/an-example-domain.com<\/figcaption><\/figure>\n<figure id=\"attachment_186\" aria-describedby=\"caption-attachment-186\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-186 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/www_domain_being_served-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-186\" class=\"wp-caption-text\">http:\/\/www.an-example-domain.com<\/figcaption><\/figure>\n<p>Now we have our domains configured properly so we can visit our server with a url, we can begin to install our SSL certificates.<\/p>\n<h2>Part Two &#8211; Securing NGINX with Let&#8217;s Encrypt SSL certificates<\/h2>\n<p>The web is moving towards a more secure future. SSL certificates protect visitors of your site by enabling HTTPS encryption on web servers. In the past SSL certificates were a moderately expensive addition to your hosting deemed only necessary for eCommerce sites or other sites that transmitted sensitive information.<\/p>\n<p>Things have changed since those days, now it is considered best practice in web development to secure all sites with an SSL certificate. This has additional benefits to just increasing security, the latest generation of the HTTP protocol, HTTP\/2, requires an SSL certificate to be installed before it can be used. HTTP\/2 can dramatically increase the speed of a well configured site due to a range of improvements such as Single Connection Loads, Multiplexing, Header Compression, and more. You can <a href=\"https:\/\/http2.github.io\/faq\/\" target=\"_blank\" rel=\"noopener\">find out more about HTTP\/2 here<\/a>.<\/p>\n<p>There is also the not inconsequential matter that sites without SSL certificates are now being penalised by Google, with Chrome even throwing warnings for unsecured sites.<\/p>\n<p><a href=\"https:\/\/letsencrypt.org\/about\/\" target=\"_blank\" rel=\"noopener\">Let&#8217;s Encrypt<\/a>\u00a0is a free, automated, and open certificate authority (CA) provided by the <a href=\"https:\/\/letsencrypt.org\/isrg\/\" target=\"_blank\" rel=\"noopener\">Internet Security Research Group<\/a>, they have almost single-handedly accelerated the widespread adoption of SSL certificates in recent years, we should all be very grateful.<\/p>\n<p>We will be using the Let&#8217;s Encrypt Certbot to obtain a free SSL certificate, Certbot is an awesome package that will automatically make most of the necessary NGINX configuration changes.<\/p>\n<h2>Step 5. Configuring Ubuntu to enable access to external repositories<\/h2>\n<p>We will be installing the <span class=\"grey-code\"> certbot<\/span> software from Let&#8217;s Encrypt&#8217;s separate external repository. That means we will need to add a new repository to our <span class=\"grey-code\"> apt<\/span> package manager.<\/p>\n<p>Unfortunately our Instance&#8217;s Ubuntu installation doesn&#8217;t have the required package installed to allow us to add external repositories.<\/p>\n<p>Not to worry, that&#8217;s a quick fix, just enter the following command to install said package:<\/p>\n<pre>$ sudo apt-get install -y software-properties-common\r\n<\/pre>\n<h2>Step 6. Installing Certbot<\/h2>\n<p>With that additional package we can now install <span class=\"grey-code\"> certbot<\/span> with the following commands.<\/p>\n<p>To add the repository:<\/p>\n<pre>$ sudo add-apt-repository ppa:certbot\/certbot\r\n<\/pre>\n<p>Then update the package list to pick up the new repository&#8217;s package information:<\/p>\n<pre>$ sudo apt-get update\r\n<\/pre>\n<p>And finally, install <span class=\"grey-code\"> certbot<\/span> with <span class=\"grey-code\"> apt-get<\/span>:<\/p>\n<pre>$ sudo apt-get install python-certbot-nginx\r\n<\/pre>\n<p>Now Certbot is ready to use, but before we can use it, we need to configure NGINX some more.<\/p>\n<h2>Step 7. Setting up NGINX to serve domains<\/h2>\n<p>Yes I know, I did say Certbot can automatically configure the SSL for NGINX and add the necessary settings in the NGINX configuration file server block. But before it can do that NGINX needs to be configured for your domain name, at present it is only configured for an IP address.<\/p>\n<p>Let&#8217;s update the config file:<\/p>\n<pre>$ sudo nano \/etc\/nginx\/sites-available\/default\r\n<\/pre>\n<p>Now replace the servers ipv4 address on the <span class=\"grey-code\"> server_name<\/span> line with your domain name, remember to add both the domain with and without <span class=\"grey-code\"> www<\/span> :<\/p>\n<pre>server_name <span class=\"green\">an-example-domain.com<\/span> <span class=\"orange\">www.an-example-domain.com<\/span>;\r\n<\/pre>\n<p>Your NGINX default config file server block should look something like the following:<\/p>\n<figure id=\"attachment_189\" aria-describedby=\"caption-attachment-189\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-189 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/setup_nginx_for_domains-600x613.png\" alt=\"\" width=\"600\" height=\"613\" \/><figcaption id=\"caption-attachment-189\" class=\"wp-caption-text\">Configure NGINX for your domain<\/figcaption><\/figure>\n<p>Since the NGINX config file has been changed, it should be checked for syntax errors again:<\/p>\n<pre>$ sudo nginx -t\r\n<\/pre>\n<p>All being well, reload it to load in the new configuration:<\/p>\n<pre>$ sudo systemctl reload nginx\r\n<\/pre>\n<p>With these changes made, Certbot will now be able to locate the correct server block and update it automatically.<\/p>\n<p>Next we&#8217;ll update the UFW firewall to allow HTTPS traffic.<\/p>\n<h2>Step 8. Updating the UFW Firewall<\/h2>\n<p>The UFW firewall we configured previously in the series has only been configured for HTTP connections, this now needs adjusting to allow HTTPS traffic.<\/p>\n<p>To do this we will allow &#8216;Nginx Full&#8217; first:<\/p>\n<pre>$ sudo ufw allow 'Nginx Full'\r\n<\/pre>\n<p>And then delete the redundant &#8216;Nginx HTTP&#8217; profile that we previously allowed:<\/p>\n<pre>$ sudo ufw delete allow 'Nginx HTTP'\r\n<\/pre>\n<p>Finally, check the firewall status with:<\/p>\n<pre>$ sudo ufw status\r\n<\/pre>\n<p>Your terminal should output the following:<\/p>\n<figure id=\"attachment_190\" aria-describedby=\"caption-attachment-190\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-190 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/set_ufw_for_nginx_https-600x468.png\" alt=\"\" width=\"600\" height=\"468\" \/><figcaption id=\"caption-attachment-190\" class=\"wp-caption-text\">Ubuntu UFW configured for Nginx HTTPS connections<\/figcaption><\/figure>\n<p>With our firewall configured properly, we would normally be ready to obtain our SSL certificate, but Alibaba Cloud Hosting is a little bit different however.<\/p>\n<h2>Step 9. Configure Alibaba Cloud Security Group for HTTPS connections<\/h2>\n<p>Remember all that time ago, when we first provisioned the ECS instance, we added it to a Security Group? That\u00a0is Alibaba Cloud nonmenclature for their firewall, so that&#8217;s where we need to go now.<\/p>\n<p>In the Alibaba Cloud Security Groups, you will see the default security group you attached, click the link to configure it&#8217;s rules:<\/p>\n<figure id=\"attachment_191\" aria-describedby=\"caption-attachment-191\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-191 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/security_groups_overview-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-191\" class=\"wp-caption-text\">Click the link to configure security group rules<\/figcaption><\/figure>\n<p>For HTTPS connections with an SSL, we need our server to be listening on Port 443. Currently the security group has no rule configured to allow inbound connections to the server on this port.<\/p>\n<p>Add a rule for Port 443 as follows:<\/p>\n<figure id=\"attachment_192\" aria-describedby=\"caption-attachment-192\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-192 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/add_443_security_group_rule-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-192\" class=\"wp-caption-text\">Add an inbound security rule to open Port 443<\/figcaption><\/figure>\n<figure id=\"attachment_193\" aria-describedby=\"caption-attachment-193\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"aligncenter wp-image-214 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/security_group_with_443_ready_for_ssl-1-600x375.png\" alt=\"\" width=\"600\" height=\"375\" srcset=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/security_group_with_443_ready_for_ssl-1-600x375.png 600w, https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/security_group_with_443_ready_for_ssl-1-300x188.png 300w, https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/security_group_with_443_ready_for_ssl-1-768x480.png 768w, https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/security_group_with_443_ready_for_ssl-1.png 1024w, https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/security_group_with_443_ready_for_ssl-1-720x450.png 720w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><figcaption id=\"caption-attachment-193\" class=\"wp-caption-text\">Security group with connections via Port 443 enabled<\/figcaption><\/figure>\n<p><em>Now<\/em> we&#8217;re ready to run Certbot to obtain and configure our SSL certificates, and configure server settings.<\/p>\n<h2>Step 10. Obtaining a Let&#8217;s Encrypt SSL Certificate<\/h2>\n<p>We will use Certbot&#8217;s NGINX plugin to obtain an SSL certificate for our domain, it will automagically take care of configuring NGINX and reloading the config when necessary. Enter the following command, using your own domain name:<\/p>\n<pre>$ sudo certbot --nginx -d <span class=\"orange\">domain.com<\/span> -d <span class=\"green\">www.domain.com<\/span>\r\n<\/pre>\n<p>This command runs <span class=\"grey-code\"> certbot<\/span> with the aforementioned <span class=\"grey-code\"> &#8211;nginx<\/span> plugin, and uses <span class=\"grey-code\"> -d<\/span> to specify the domain names for which the certificate will be valid.<\/p>\n<p>If everything was succesful <span class=\"grey-code\"> certbot<\/span> will check to verify you control your domain, and upon verification will issue your certificate and ask you how you would like to configure your HTTPS settings:<\/p>\n<figure id=\"attachment_194\" aria-describedby=\"caption-attachment-194\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-194 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/configure_htst-600x175.png\" alt=\"\" width=\"600\" height=\"175\" \/><figcaption id=\"caption-attachment-194\" class=\"wp-caption-text\">Configure HTTPS redirects<\/figcaption><\/figure>\n<p>I recommend to configure the redirects so that all traffic is served via HTTPS.<\/p>\n<p>At this point you will be able to access your site using <span class=\"grey-code\"> https:\/\/<\/span>, and you will get the reassuring green lock and security indicator.<\/p>\n<h2>Step. 11 Increase SSL security &#8211; Update Diffie-Hellman Parameters<\/h2>\n<p>Even though your site is secured with an SSL, it is using weak Diffie-Hellman parameters which means that the initial key exchange is still more vulnerable than we may wish.<\/p>\n<p>To fix this create a new <span class=\"grey-code\"> dhparam.pem<\/span> file and add it to the <span class=\"grey-code\"> server<\/span> block.<\/p>\n<p>Create the file using <span class=\"grey-code\"> openssl<\/span>:<\/p>\n<pre>$ sudo openssl dhparam -out \/etc\/ssl\/certs\/dhparam.pem 2048\r\n<\/pre>\n<p>This may take some time, and will look like this:<\/p>\n<figure id=\"attachment_195\" aria-describedby=\"caption-attachment-195\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-195 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/update_diffie_hellman-600x612.png\" alt=\"\" width=\"600\" height=\"612\" \/><figcaption id=\"caption-attachment-195\" class=\"wp-caption-text\">Update Diffie-Hellman parameters<\/figcaption><\/figure>\n<p>When this process is complete, open up the default sites NGINX config file again:<\/p>\n<pre>$ sudo nano \/etc\/nginx\/sites-available\/default\r\n<\/pre>\n<p>And paste in the following code, this can be anywhere inside the <span class=\"grey-code\"> server<\/span> block:<\/p>\n<pre>ssl_dhparam \/etc\/ssl\/certs\/dhparam.pem;\r\n<\/pre>\n<p>The entire server block should look like the following, notice the SSL configuration settings that have also been added by <span class=\"grey-code\"> certbot:<\/span><\/p>\n<figure id=\"attachment_196\" aria-describedby=\"caption-attachment-196\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-196 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/add_ssl_dhparam_complete_default_config-600x685.png\" alt=\"\" width=\"600\" height=\"685\" \/><figcaption id=\"caption-attachment-196\" class=\"wp-caption-text\">Fully configured server block<\/figcaption><\/figure>\n<p>Save the file and close the editor. And since we have altered the NGINX configuration again, we will need to check the syntax again:<\/p>\n<pre>$ sudo nginx -t\r\n<\/pre>\n<p>If there are no errors, reload NGINX:<\/p>\n<pre>$ sudo systemctl reload nginx\r\n<\/pre>\n<p>The site is now a lot more secure. You can test it using the\u00a0<a href=\"https:\/\/www.ssllabs.com\/ssltest\/\" target=\"_blank\" rel=\"noopener\">SSL Labs Server Test,<\/a>\u00a0and it should get an <strong>A<\/strong>\u00a0rating.<\/p>\n<h2>Step 12. Setting up Certificate Auot Renewal with a Cron job<\/h2>\n<p>Let&#8217;s encrypt certificates are currently only valid for 90 days to encourage users to automate their certificate renewal process, which is exactly what we are going to do.<\/p>\n<p>To do this we will use a <span class=\"grey-code\"> cron<\/span> job. This is the system Linux uses for running periodic system jobs. To add a <span class=\"grey-code\"> cron<\/span> job we must edit a file called a <span class=\"grey-code\"> crontab<\/span>:<\/p>\n<pre>$ sudo crontab -e\r\n<\/pre>\n<p>The text editor will open the default <span class=\"grey-code\"> crontab<\/span>, paste the following code at the end of the file, then save it and close it:<\/p>\n<pre>0 0 * * * \/usr\/bin\/certbot renew --quiet\r\n<\/pre>\n<p>This means run this <span class=\"grey-code\"> \/usr\/bin\/certbot renew &#8211;quiet<\/span> command at this <span class=\"grey-code\"> 0 0 * * * <\/span> time.<\/p>\n<p><span class=\"grey-code\"> 0 0 * * *<\/span> translates to every day at midnight. To find out more about cron timings you can visit <a href=\"https:\/\/crontab.guru\/\" target=\"_blank\" rel=\"noopener\">CronTab.Guru<\/a>.<\/p>\n<p>The <span class=\"grey-code\"> renew<\/span> command for Certbot will check all certificates installed on the system and update any that are set to expire in less than thirty days.<\/p>\n<p>The <span class=\"grey-code\"> &#8211;quiet<\/span> command tells Certbot not to wait for user input, or output any information.<\/p>\n<p>Your SSL certificate is now installed, has an <strong>A<\/strong> rating, and is configured to renew automatically. Time to test things out.<\/p>\n<h2>Step 13. Test your server for HTTPS connection<\/h2>\n<p>You should now be able to visit your website by visiting your domain using https:<\/p>\n<pre>https:\/\/<span class=\"green\">an-example-domain.com<\/span>\r\n<\/pre>\n<p>or<\/p>\n<pre>https:\/\/<span class=\"green\">www.an-example-domain.com<\/span>\r\n<\/pre>\n<figure id=\"attachment_198\" aria-describedby=\"caption-attachment-198\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"tutorial-float wp-image-198 size-medium-large-soft-crop\" src=\"https:\/\/learningcurve.xyz\/wp-content\/uploads\/2017\/10\/https_www_domain_working-600x375.png\" alt=\"\" width=\"600\" height=\"375\" \/><figcaption id=\"caption-attachment-198\" class=\"wp-caption-text\">Visit your site using https:\/\/<\/figcaption><\/figure>\n<p>And we&#8217;re done.<\/p>\n<p>Your ECS instance should now have a fully installed LEMP stack, with a domain configured, and a secure SSL certificate installed.<\/p>\n<p>Next up&#8230; The final tutorial in this series, let&#8217;s get us some WordPress going on.<\/p>\n<p>See you then<\/p>\n<p>Jeff<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to the third tutorial in this series about installing WordPress and a performant server stack on an Alibaba ECS Cloud Instance. In the previous two tutorials, we provisioned and secured our Ubuntu 16.04 server installation, then completed the LEMP stack with NGINX, MariaDB and PHP7. Today we are going to configure a Domain to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":175,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=\/wp\/v2\/posts\/184"}],"collection":[{"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=184"}],"version-history":[{"count":5,"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions"}],"predecessor-version":[{"id":216,"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions\/216"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=\/wp\/v2\/media\/175"}],"wp:attachment":[{"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learningcurve.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}