Apache httpd 中的 Let's Encrypt (ACME)
This repository is now archived and no longer maintained. The module lives on as part of the Apache httpd project and is maintained there. The current LLM craziness does not allow me the time and mental resources to keep on providing a separate and for many people more convenient place here.
My thanks to all the contributors over the last decade who helped out.
mod_md does two things:
Both functions work well together, but you can use one without the other. If you do not want the ACME/Let's Encrypt parts, there is "Just the Stapling, Mam!"
The following people directly contributed to mod_md:
Alvaro Octal, Andreas Ulm, Bernard Spil, Daniel Caminada, Dominik Stillhard,
Fraser Tweedale, Giovanni Bechis, Jacob Hoffman-Andrews, Joe Orton,
Josh Soref, Lubos Uhliarik, Max-Milan Stoyanov, Michael Kaufmann,
Michael Köller, Michal Karm Babacek, Mina Galić, Moritz Schlarb,
Stefan Eissing, Timothe Litt, @frasertweedale.
Many thanks!
This README always describes the current version of the module. This might not actually be what you use. You can look
into your Apache server log where mod_md logs its version at startup.
v2.4.x releases are stable. They can be used in production and new versions will be backward
compatible with existing configurations.
Among other improvements v2.4.0 brings support for multiple certificates with different key types.
The large feature added in v2.2.0 is OCSP stapling. This release line shipped in Apache httpd 2.4.46.
Apache releases will always get the latest, stable version from here. Advanced:
Stapling
This is a list of recipes on how you can use ACME in your Apache configuration. This assumes that you are somewhat familiar with Apache's configuration directives Listen, VirtualHost, SSLEngine and friends. It also assumes that your Apache is running, has the basic modules loaded. You can see a document in your browser (maybe only on http: for now).
Your Apache is working and listens on port 80. It runs on a machine you can connect to. You want it to serve https:. And it should be real https: with a certificate from Let's Encrypt and it should show a green lock (or whatever is the fashion nowadays) in browsers.
Well, there are some prerequisites for that:
mydomain.com for simplicity from now on.http://mydomain.com/ in a browser and get something back from your server?This sounds good. You have a running setup for http:. In case you're not aware, http: runs on port 80. Somewhere in your Apache configuration there is a line like
Listen 80https: listens on port 443. So, either this is already the case, or you need to add another Listen line for this. If you cannot immediately find it: some installations have it in another file that gets included. If it is not there, add it.
To use mod_md you need it loaded into your server. This varies a bit, depending on what installation you use. In debian/ubuntu, for example, there is a command to activate it:
> a2enmod md
Enabling module md.
To activate the new configuration, you need to run:
service apache2 restartThere is no harm in doing this again:
> a2enmod md
Module md already enabledAlso make sure that mod_ssl and mod_watchdog are enabled. watchdog is often directly part of the server and not an external module. Then there is no need to enable it.
One more thing. There is usually an email address in your Apache configuration, configured with the ServerAdmin directive. Sometimes, it has a meaningless default. It has been mainly used in error responses as "Contact [email protected]..." so far and people do not really lose sleep about it being an invalid address. Not so any more!
mod_md will use that email address when registering your domains at Let's Encrypt. And they will try to contact you with important news, should the need arise. So, make sure this is a real address that you monitor!
If you want to be registered and contacted different email address, specify it with the MDContactEmail directive, which is preferred.
As the last thing, add the following line somewhere in your configuration:
MDCertificateAgreement acceptedWith this you state that you accept the Terms of Service by Let's Encrypt.
Scenario: you have checked the prerequisites and would like to add a new host that should be reachable via https:.
As in all How To chapters, we use mydomain.com as the domain name. Exchange this with the name you actually have. In the Apache config (or one file included from it), you add now:
MDomain mydomain.com
ServerName mydomain.com
SSLEngine on
DocumentRoot ...path-you-serve-here...
...
and then you restart your server.
What did we do here? We made a host that answers on port 443 and we told mod_ssl that it should be active here. But we did not specify any certificates! If you look at examples for ssl in Apache on the web, there are always SSLCertificateFile and SSLCertificateKEyFile used. This is no longer necessary.
And while we left out parts of the SSL configurations that used to be necessary, we added one line of mod_md configuration: MDomain . This is how you declare that a domain should be manged by mod_md.
The module will use this name to find all hosts that belong to it and take care of those. When mod_ssl does not find any certificates, because you did not configure any, it will ask mod_md: "Hey, do you know anything about mydomain.com?" And it will answer: "Sure, use these files here for the certificates!"
During start up, the module will see that there are no certificates yet for mydomain.com. It could contact Let's Encrypt right away and request one - but who knows how long that might take. In the meantime, your server will not become active and request will just time out. No good. Instead it creates a temporary certificate itself for mydomain.com and pass that on to mod_ssl. Everything starts up and your server is responsive.
Now, when you open https://mydomain.com/ in your browser now, it will complain because this temporary certificate cannot be trusted. If you tell it to ignore these security considerations (well, you should not), your server will answer every request to mydomain.com with a "503 Service Unavailable" message.
In the meantime, right after the Apache has started, mod_md will contact Let's Encrypt and request a certificate for your. This usually takes less than a minute. There are several ways to check the progress of this (see Monitoring for more), but for this first time you should maybe look into the server's error log.
If you find an entry there like:
[Date] [md:notice] [pid nnn] AH10059: The Managed Domain mydomain.com has been setup
and changes will be activated on next (graceful) server restart.If this does not happen, something is not right and you should read here on how to analyze and fix problems. But assuming this worked, you now simply do a reload of the server and https://mydomain.com/ should work nicely and with a green lock in your browser. ("reload" is just a short name for a "graceful" restart, one that does not interrupt ongoing requests.)
Congratulations!
Scenario: you have a Host responding to http: requests, you have checked the prerequisites and would like to have that host reachable via https: as well.
As in all How To chapters, we use mydomain.com as the domain name. Exchange this with the name you actually have. In the Apache config you will have something like this already:
ServerName mydomain.com
DocumentRoot ...path-you-serve-here...
...
This is the host that you already have. Now, make a copy of that, change the port and switch SSL on:
MDomain mydomain.com
ServerName mydomain.com
DocumentRoot ...path-you-serve-here...
...
ServerName mydomain.com
SSLEngine on
DocumentRoot ...path-you-serve-here...
...
Then you reload your Apache server. It will start up right away, as before, and your http://mydomain.com/ links will work as they used to. If you open https://mydomain.com/ in your browser, you will get a security warning. If you tell it to ignore that you will get a 503 Service Unavailable response.
What is happening? At start up, mod_md generated a self-signed certificate for the new https host to use and switch that host to 503 responses. This made sure that your server started without delay and that your other hosts could start working.
When Apache is done with start up, mod_md spins up a background thread that contacts LetsEncrypt and negotiates a certificate for mydomain.com. This usually takes a few seconds, but there are several things that may delay this: bad internet connectivity, maintenance at LetsEncrypt, problems with DNS resolutions somewhere, etc.
There are several ways to check the progress of this (see Monitoring for more), but for this first time you should maybe look into the server's error log.
If you fin
暂无开放 Issues,或尚未同步最近议题。