{"componentChunkName":"component---src-templates-page-js","path":"/letsencrypt-apache","result":{"data":{"markdownRemark":{"frontmatter":{"title":"Building a simple HTTPS webpage using Let's Encrypt on Apache HTTPD ","date":"26 April 2017","path":"/letsencrypt-apache","author":null,"excerpt":"I have been hearing about [Let's Encrypt](https://letsencrypt.org/) for a while, and luckily enough I have the opportunity to get my hands on it (virtually, of course)...","tags":["web"],"coverImage":null},"id":"f13d6f5f-f2f3-5331-9cd7-dd20632af854","html":"<p>I have been hearing about <a href=\"https://letsencrypt.org/\">Let's Encrypt</a> for a while, and luckily enough I have the opportunity to get my hands on it (virtually, of course).</p>\n<p>In this post, I will talk about my experience setting up a simple demo <a href=\"https://demo-apache.chriswang.tech/\">website</a> over HTTPS using Let's Encrypt on an Apache HTTP Server. The entire process takes less than &#x3C;30 mins if you get the following right before you start:</p>\n<ul>\n<li>You have an AWS account and are familiar with basic concepts like EC2, VPC, Security Group etc.</li>\n<li>You are familar with Bash/Shell</li>\n<li>You controls an active top-level domain and are familiar with the configuration</li>\n</ul>\n<p>An import note before we start: The website is purely for demonstration purpose and not suitable for production use.</p>\n<h2>Here are the steps to do it</h2>\n<h3>Create EC2 instance</h3>\n<p>An AWS EC2 <code class=\"language-text\">t2.micro</code> instance is setup. And an elastic IPv4 address (<code class=\"language-text\">34.202.12.128</code>) is assigned and attached to the EC2 instance's network interface.</p>\n<h3>Update Name Server</h3>\n<p>A DNS <code class=\"language-text\">A</code> record is added to my Name Server for chriswang.tech and pointing to <code class=\"language-text\">34.202.12.128</code>. In my case, Cloudflare's DNS is used.</p>\n<p> The configuration is shown below.</p>\n<p><img src=\"%7B%7B%20site.url%20%7D%7D/images/dns.png\" alt=\"dns\"></p>\n<p>The <code class=\"language-text\">dig</code> command is used to verify that the DNS record has taken effect in my local DNS resolver.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ <span class=\"token function\">dig</span> demo-apache.chriswang.tech</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">; &lt;&lt;&gt;&gt; DiG 9.8.3-P1 &lt;&lt;&gt;&gt; demo-apache.chriswang.tech\n;; global options: +cmd\n;; Got answer:\n;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 24626\n;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 4\n\n;; QUESTION SECTION:\n;demo-apache.chriswang.tech.\tIN\tA\n\n;; ANSWER SECTION:\ndemo-apache.chriswang.tech. 300\tIN\tA\t34.202.12.128\n\n;; AUTHORITY SECTION:\nchriswang.tech.\t\t2811\tIN\tNS\tart.ns.cloudflare.com.\nchriswang.tech.\t\t2811\tIN\tNS\talice.ns.cloudflare.com.\n\n;; ADDITIONAL SECTION:\nart.ns.cloudflare.com.\t47841\tIN\tA\t173.245.59.102\nalice.ns.cloudflare.com. 43742\tIN\tA\t173.245.58.60\nart.ns.cloudflare.com.\t47841\tIN\tAAAA\t2400:cb00:2049:1::adf5:3b66\nalice.ns.cloudflare.com. 43742\tIN\tAAAA\t2400:cb00:2049:1::adf5:3a3c\n\n;; Query time: 72 msec\n;; SERVER: 192.35.82.50#53(192.35.82.50)\n;; WHEN: Wed Apr 26 18:32:27 2017\n;; MSG SIZE  rcvd: 203</code></pre></div>\n<h3>Test HTTP</h3>\n<p>To verify the Apache HTTP service works, visit in the browser<code class=\"language-text\">http://demo-apache.chriswang.tech</code>.</p>\n<p>An Apache Default Page below is expected.</p>\n<p><img src=\"%7B%7B%20site.url%20%7D%7D/images/default_apache.png\" alt=\"default_apache\"></p>\n<h3>Update <code class=\"language-text\">index.html</code></h3>\n<p>To update the default page, a custom <code class=\"language-text\">index.html</code> is created and symlinked to the default Apache directory at <code class=\"language-text\">/var/www/html/</code> using the following command:</p>\n<p><code class=\"language-text\">$ sudo ln -s ~/demo-apache/index.html /var/www/html/index.html</code></p>\n<p>The following webpage should be shown after refreshing the same URL in browser.</p>\n<p><img src=\"%7B%7B%20site.url%20%7D%7D/images/index_html.png\" alt=\"index_html\"></p>\n<h3>Generate Private Key</h3>\n<p>The RSA private key and certificate signing request (CSR) are generated using <code class=\"language-text\">openssl</code> using the following command:</p>\n<p><code class=\"language-text\">$ openssl req -newkey rsa:2048 -nodes -keyout domain.key -out domain.csr</code></p>\n<p>The generated CSR will be used for the TLS public certificate generation in the next step.</p>\n<h3>Configure Let's Encrypt/CertBot</h3>\n<p>In order to use Let's Encrypt, the CertBot is installed to automate this process using the following commands:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token variable\">$sudo</span> add-apt-repository ppa:certbot/certbot\n<span class=\"token variable\">$sudo</span> <span class=\"token function\">apt-get</span> update\n<span class=\"token variable\">$sudo</span> <span class=\"token function\">apt-get</span> <span class=\"token function\">install</span> python-certbot-apache</code></pre></div>\n<p>The TLS certificate generation and Apache HTTP Server are executed automatically by running the following command:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ certbot --apache </code></pre></div>\n<p>If successful, an output similar to the following is expected:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Saving debug log to /var/log/letsencrypt/letsencrypt.log\nNo names were found in your configuration files. Please enter in your domain\nname(s) (comma and/or space separated)  (Enter &#39;c&#39; to cancel):demo-apache.chriswang.tech\nStarting new HTTPS connection (1): acme-v01.api.letsencrypt.org\nObtaining a new certificate\nPerforming the following challenges:\ntls-sni-01 challenge for demo-apache.chriswang.tech\nEnabled Apache socache_shmcb module\nEnabled Apache ssl module\nWaiting for verification...\nCleaning up challenges\nGenerating key (2048 bits): /etc/letsencrypt/keys/0000_key-certbot.pem\nCreating CSR: /etc/letsencrypt/csr/0000_csr-certbot.pem\nCreated an SSL vhost at /etc/apache2/sites-available/000-default-le-ssl.conf\nEnabled Apache socache_shmcb module\nEnabled Apache ssl module\nDeploying Certificate to VirtualHost /etc/apache2/sites-available/000-default-le-ssl.conf\nEnabling available site: /etc/apache2/sites-available/000-default-le-ssl.conf\n\nPlease choose whether HTTPS access is required or optional.\n-------------------------------------------------------------------------------\n1: Easy - Allow both HTTP and HTTPS access to these sites\n2: Secure - Make all requests redirect to secure HTTPS access\n-------------------------------------------------------------------------------\n\nSelect the appropriate number [1-2] then [enter] (press &#39;c&#39; to cancel): 2\nEnabled Apache rewrite module\nRedirecting vhost in /etc/apache2/sites-available/000-default.conf to ssl vhost in /etc/apache2/sites-available/000-default-le-ssl.conf\n\n-------------------------------------------------------------------------------\nCongratulations! You have successfully enabled\nhttps://demo-apache.chriswang.tech\n\nYou should test your configuration at:\nhttps://www.ssllabs.com/ssltest/analyze.html?d=demo-apache.chriswang.tech\n-------------------------------------------------------------------------------\n\nIMPORTANT NOTES:\n - Congratulations! Your certificate and chain have been saved at\n   /etc/letsencrypt/live/demo-apache.chriswang.tech/fullchain.pem.\n   Your cert will expire on 2017-07-25. To obtain a new or tweaked\n   version of this certificate in the future, simply run certbot again\n   with the &quot;certonly&quot; option. To non-interactively renew *all* of\n   your certificates, run &quot;certbot renew&quot;\n - If you like Certbot, please consider supporting our work by:\n\n   Donating to ISRG / Let&#39;s Encrypt:   https://letsencrypt.org/donate\n   Donating to EFF:                    https://eff.org/donate-le</code></pre></div>\n<h3>Run Qualys SSL Server Test</h3>\n<p>To verify that the the HTTPS/TLS service is configured correctly, the <a href=\"https://www.ssllabs.com/ssltest/analyze.html?d=demo-apache.chriswang.tech\">Qualys SSL Server Test</a> is run. </p>\n<p>The test report is shown below with a big green <strong>A</strong>. It means the HTTPS/TLS is working as expected! 😀</p>\n<p><img src=\"%7B%7B%20site.url%20%7D%7D/images/ssl_report.png\" alt=\"ssl_report\"></p>\n<h2>The experience is great: straight-forward and FREE</h2>\n<p>Kudos and thanks to the Internet Security Research Group (ISRG), Linux Foundation, Apache Foundation and many other non-profit and commercial organizations for making HTTPS/TLS accessible for everyone.</p>\n<p>We look forward to more projects like this!</p>\n<p>/Chris</p>\n<h2>References</h2>\n<h3>Apache Web Server</h3>\n<ul>\n<li>Basic Setup: <a href=\"https://www.digitalocean.com/community/tutorials/how-to-configure-the-apache-web-server-on-an-ubuntu-or-debian-vps\">https://www.digitalocean.com/community/tutorials/how-to-configure-the-apache-web-server-on-an-ubuntu-or-debian-vps</a></li>\n<li>Get Started Guide:\n<a href=\"http://httpd.apache.org/docs/2.4/getting-started.html\">http://httpd.apache.org/docs/2.4/getting-started.html</a></li>\n</ul>\n<h3>Let's Encrypt and Certbot</h3>\n<ul>\n<li>Get started: <a href=\"https://certbot.eff.org/#ubuntuxenial-apache\">https://certbot.eff.org/#ubuntuxenial-apache</a></li>\n</ul>","excerpt":"I have been hearing about Let's Encrypt for a while, and luckily enough I have the opportunity to get my hands on it (virtually, of course…"}},"pageContext":{"type":"posts","next":{"frontmatter":{"path":"/self-managed-gh","title":"Building a Self-managed Alternative to GitHub Pages","tags":["web","jekyll","aws","travis-ci","cloudflare","nginx","letsencrypt"]},"fileAbsolutePath":"/opt/build/repo/src/posts/2017-06-16-building-github-pages-alternative.md"},"previous":{"frontmatter":{"path":"/cornell-tech","title":"Release Notes: My Graduation from Cornell Tech CS v3","tags":["cornell-tech","cornell","master","mba","cs","nyc"]},"fileAbsolutePath":"/opt/build/repo/src/posts/2017-06-15-graduation_from_cornell_tech_cs_v3.md"}}},"staticQueryHashes":["1425477374","3128451518"]}