Introduction

This tutorial will show you how to set up a TLS/SSL certificate from Let’s Encrypt on an Ubuntu 14.04 server running Apache as a web server. We will also cover how to automate the certificate renewal process using a cron job.

SSL certificates are used within web servers to encrypt the traffic between the server and client, providing extra security for users accessing your application. Let’s Encrypt provides an easy way to obtain and install trusted certificates for free.

Prerequisites

In order to complete this guide, you will need:

When you are ready to move on, log into your server using your sudo account.

Step 1 — Install the Server Dependencies

The first thing we need to do is to update the package manager cache with:


  • sudo apt-get update

We will need git in order to download the Let’s Encrypt client. To install git, run:


  • sudo apt-get install git

Step 2 — Download the Let’s Encrypt Client

Next, we will download the Let’s Encrypt client from its official repository, placing its files in a special location on the server. We will do this to facilitate the process of updating the repository files when a new release is available. Because the Let’s Encrypt client is still in beta, frequent updates might be necessary to correct bugs and implement new functionality.

We will clone the Let’s Encrypt repository under /opt, which is a standard directory for placing third-party software on Unix systems:


  • sudo git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt

This will create a local copy of the official Let’s Encrypt repository under /opt/letsencrypt.

Step 3 — Set Up the SSL Certificate

Generating the SSL Certificate for Apache using the Let’s Encrypt client is quite straightforward. The client will automatically obtain and install a new SSL certificate that is valid for the domains provided as parameters.

Access the letsencrypt directory:


  • cd /opt/letsencrypt

To execute the interactive installation and obtain a certificate that covers only a single domain, run theletsencrypt-auto command with:


  • ./letsencrypt-auto --apache -d example.com

If you want to install a single certificate that is valid for multiple domains or subdomains, you can pass them as additional parameters to the command. The first domain name in the list of parameters will be thebase domain used by Let’s Encrypt to create the certificate, and for that reason we recommend that you pass the bare top-level domain name as first in the list, followed by any additional subdomains or aliases:


  • ./letsencrypt-auto --apache -d example.com -d www.example.com

For this example, the base domain will be example.com.

Don't forget to allow 443 port on your firewall.

After the dependencies are installed, you will be presented with a step-by-step guide to customize your certificate options. You will be asked to provide an email address for lost key recovery and notices, and you will be able to choose between enabling both http and https access or force all requests to redirect to https.

When the installation is finished, you should be able to find the generated certificate files at/etc/letsencrypt/live. You can verify the status of your SSL certificate with the following link (don’t forget to replace example.com with your base domain):

https://www.ssllabs.com/ssltest/analyze.html?d=example.com&latest

You should now be able to access your website using a https prefix.

Step 4 — Set Up Auto Renewal

Let’s Encrypt certificates are valid for 90 days, but it’s recommended that you renew the certificates every 60 days to allow a margin of error. The Let's Encrypt client has a renew command that automatically checks the currently installed certificates and tries to renew them if they are less than 30 days away from the expiration date.

To trigger the renewal process for all installed domains, you should run:

./letsencrypt-auto renew

Because we recently installed the certificate, the command will only check for the expiration date and print a message informing that the certificate is not due to renewal yet. The output should look similar to this:

Checking for new version...
Requesting root privileges to run letsencrypt...
/root/.local/share/letsencrypt/bin/letsencrypt renew
Processing /etc/letsencrypt/renewal/example.com.conf The following certs are not due for renewal yet:
/etc/letsencrypt/live/example.com/fullchain.pem (skipped)
No renewals were attempted.

Notice that if you created a bundled certificate with multiple domains, only the base domain name will be shown in the output, but the renewal should be valid for all domains included in this certificate.

A practical way to ensure your certificates won’t get outdated is to create a cron job that will periodically execute the automatic renewal command for you. Since the renewal first checks for the expiration date and only executes the renewal if the certificate is less than 30 days away from expiration, it is safe to create a cron job that runs every week or even every day, for instance.

Let's edit the crontab to create a new job that will run the renewal command every week. To edit the crontab for the root user, run:


  • sudo crontab -e

Include the following content, all in one line:


crontab
30 2 * * 1 /opt/letsencrypt/letsencrypt-auto renew >> /var/log/le-renew.log

Save and exit. This will create a new cron job that will execute the letsencrypt-auto renew command every Monday at 2:30 am. The output produced by the command will be piped to a log file located at/var/log/le-renewal.log.

For more information on how to create and schedule cron jobs, you can check our How to Use Cron to Automate Tasks in a VPS guide.

Step 5 — Updating the Let’s Encrypt Client (optional)

Whenever new updates are available for the client, you can update your local copy by running a git pullfrom inside the Let’s Encrypt directory:


  • cd /opt/letsencrypt
  • sudo git pull

This will download all recent changes to the repository, updating your client.

Conclusion

In this guide, we saw how to install a free SSL certificate from Let’s Encrypt in order to secure a website hosted with Apache. Because the Let’s Encrypt client is still in beta, we recommend that you check the official Let’s Encrypt blog for important updates from time to time.

How To Secure Apache with Let's Encrypt on Ubuntu (Free SSL)的更多相关文章

  1. How To Secure Nginx with Let's Encrypt on Ubuntu 14.04

    https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-14 ...

  2. 使用Let’s Encrypt生成免费的SSL证书

    SSL(安全套接层,Secure Sockets Layer),及其继任者 TLS (传输层安全,Transport Layer Security)是为网络通信提供安全及数据完整性的一种安全协议.TL ...

  3. 使用Let’s Encrypt创建nginx免费SSL证书

    资料参考: https://www.freehao123.com/top-8-free-ssl-cert/   八大免费SSL证书-给你的网站免费添加Https安全加密 https://www.fre ...

  4. 使用Let's Encrypt 生成免费的ssl证书的详细过程

    参考连接:https://github.com/diafygi/acme-tiny 中文:https://hacpai.com/article/1487899289204 目前我了解可以生成免费证书的 ...

  5. Establish the LAMP (Linux+Apache+MySQL+PHP) Development Environment on Ubuntu 14.04 Operating System

    ######################################################## Step One: Update the software package in yo ...

  6. 使用Let's Encrypt为网站加入SSL证书

    一直没有为网站配置过HTTPS,因为怕麻烦.不过这次工作要求,没有办法,只能硬着头皮上了. 老板提供了一个关键字,Let's Encrypt.其实最早看到这句话,我以为是一个动词,让我行动的意思.但是 ...

  7. Apache环境下配置多个站点的SSL证书

    重新创建apache目录中conf/extra/下的httpd-ssl.conf文件 NameVirtualHost *:443 Listen 443 <VirtualHost *:443> ...

  8. Django + Apache + wsgi配置和环境搭建(ubuntu)

    上一篇写了Django + nginx + uwsgi配置和环境搭建(ubuntu) 由于公司服务器环境问题,又配置了apache的环境.记录例如以下: 一. 安装环境: #apache sudo a ...

  9. Apache Doris ODBC Mysql外表在Ubuntu下使用方法及配置

    Apache Doris 社区 2022 年的总体规划,包括待开展或已开展.以及已完成但需要持续优化的功能.文档.社区建设等多方面,我们期待有更多的小伙伴参与进来讨论.同时也希望多多关注Doris,给 ...

随机推荐

  1. C++ class和struct的区别

    class和struct定义类唯一的区别就是默认的访问权限. 如果我们使用struct关键字,则定义在第一个访问说明符之前的成员是public的:相反,如果我们使用class关键字,组这些成员是pri ...

  2. JS正则表达式端口号,IP地址

    端口号:65535 正则:/^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6 ...

  3. Unity3D碰撞触发函数

    首先要给被碰撞物体添加Box Collider,并在Is Trigger打勾 在被碰撞物体的脚本里,添加碰撞检测函数 void OnTriggerEnter(Collider other) { if ...

  4. Visual Studio 跨平台開發實戰(5) - Xamarin Android 多頁面應用程式開發 (转帖)

    前言 大部份的Android 都具有實體或虛擬的Back鍵. 因此在處理多頁面應用程式時, 與先前所介紹的iOS Navigation controller 比較起來會簡單許多. 1. 開啟Visua ...

  5. 浏览器缓存如何控制? && 在url框中回车、F5 和 Ctrl + F5的区别是什么?

    第一部分: 浏览器缓存如何控制?   最近在做网站,但是不知道缓存是什么东西怎么能行! 如何实现HTTP缓存呢? 下面我们来一步一步的探寻实现机制把. 方案一: 无缓存   说明: 浏览器向服务器请求 ...

  6. 判断checkbox是否被选中

    jquery判断checked的三种方法: .attr('checked):   //看版本1.6+返回:”checked”或”undefined” ;1.5-返回:true或false .prop( ...

  7. Java学习之路(六):集合

    集合的由来 数组的长度是固定的,当添加的元素超过了数组的长度,就需要对数组重新定义 java内部给我们提供的集合类,能存储任意对象,长度是可以改变的.随着元素的增加而增加,随着元素的减少而减少 数组和 ...

  8. thumbnailator + webp-imageio-core实现java处理图片支持webp

    thumbnailator提供了便捷的图片处理api,webp-imageio-core屏蔽了不同平台webp本地库的差异. <dependency> <groupId>com ...

  9. Django的国际化

    Django的国际化 Django基于python的gettext来实现国际化.其过程为安装gettext工具,然后再代码中调用指定方法,然后用gettext提供的程序来把代码中需要翻译的部分找出来写 ...

  10. 深入理解java集合框架之---------Arraylist集合

    ArrayList简介 ArrayLIst是动态数组,用MSDN的说法就是Array的复杂版本,它提供了动态的增加和减少元素,实现了Collection和List接口,可以灵活的设置数组的大小,要注意 ...