How To Secure Apache with Let‘s Encrypt on Ubuntu (Free SSL)

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.

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

来自为知笔记(Wiz)

原文地址:https://www.cnblogs.com/jins-note/p/9513367.html

时间: 2024-10-10 18:13:25

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

使用Let's Encrypt客户端免费申请SSL证书

Mozilla.思科.Akamai.IdenTrust.EFF 和密歇根大学研究人员联合宣布了 Let's Encrypt CA 项 目,计划为网站提供免费的基本 SSL 证书,以加速互联网从 HTTP 向 HTTPS 过渡.Let's Encrypt CA 将由非赢利组织 Internet Security Research Group (ISRG) 运营,今天12月4日凌晨项目正式进入公测阶段,遂赶紧进行申请试用一下. 之前我申请证书都是用BS方式,这次是CS方式,感觉挺新鲜. 我的服务器环

How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu

About LAMP LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Since the virtual private server is already running Ubuntu, the linux part is taken care of. Here i

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

######################################################## Step One: Update the software package in your operation system. THE COMMAND YOU CAN TYPE INTO YOUR CONSOLE #apt-get update #apt-get dist-upgrade -y --force-yes #################################

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

重新创建apache目录中conf/extra/下的httpd-ssl.conf文件 Listen 443 <VirtualHost *.443> DocumentRoot "/var/www/site1" ServerName www.site1.com ServerAlias www.site1.com SSLEngine on SSLProtocol all -SSLv2 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 SSLCertif

Ubuntu 16.04——配置Nginx及Https服务

安装Cerbot sudo apt-get update sudo apt-get install software-properties-common sudo add-apt-repository ppa:certbot/certbot sudo apt-get update sudo apt-get install python-certbot-nginx 使用Cerbot中的Nginx插件(自动版,可能会不行) sudo certbot --nginx 此命令将自动获取证书并且Certb

Let&#39;s Encrypt+Apache+Tomcat实现免费HTTPS

Let's Encrypt是一个免费SSL证书发行项目,发行的证书已经获得主流浏览器的支持,亲测谷歌浏览器(桌面版).火狐浏览器(桌面版).UC浏览器(手机版).360浏览器(手机版)支持,其它的暂没测试: 本文讲解如何使用Let's Encrypt获得免费SSL证书,配置apache的SSL功能,并将请求转发到tomcat 大致思路如下: 1.使用Let's Encrypt获得SSL证书 2.开启apache的SSL功能,用户请求首先到apache,使用http协议或者https协议 3.ap

Java Secure Socket Extension (JSSE) Reference Guide

Skip to Content Oracle Technology Network Software Downloads Documentation Search Java Secure Socket Extension (JSSE) Reference Guide This guide covers the following topics: Skip Navigation Links Introduction Features and Benefits JSSE Standard API S

使用 Let&#39;s Encrypt 签发免费SSL 证书

Let's Encrypt 是新出现的证书颁发机构,他是开源并且自动化的. 官方首页:https://letsencrypt.org/ 项目代码:https://github.com/certbot/certbot 有关此项目的详细信息,请到官方了解.这里说说Let's Encrypt client 的事情. 安装: 可使用git 克隆项目,亦可wget 下载项目 下载 git clone https://github.com/letsencrypt/letsencrypt 安装,并显示帮助信息

CentOS 6.3下CHEF批量部署APACHE

之前的博文我介绍了如何搭建CHEF环境以及创建编写cookbook,resipes用来批量将cookbook下发到客户端执行相应的部署操作. NOW,本篇文档我们会详细介绍如何利用CHEF独有的框架语言来批量部署安装APACHE,并加载其HTTPS模块等功能. 相信如果你看了本篇文档,利用CHEF实现一个批量自动化部署将不是什么难事. CHEF环境部署详见: http://showerlee.blog.51cto.com/2047005/1408467 操作系统:CentOS-6.3-x86-6