HTTPS Support via Let’s Encrypt

From Biowikifarm Metawiki
Jump to: navigation, search
  • Installed client: (the installation of the default client certbot failed due to some python incompatibilites)

How Let's Encrypt works

"Let's Encrypt" is an initiative by the Mozilla Foundation and the Electronic Frontier Foundation that provides free SSL certificates for websites. The general idea is that if you control the content in the root directory of a domain, you are eligible to request the certificate for that domain. No paperwork or authentication required.

The certificate is issued automatically by running one of many supported clients on the target machine. It proves to the lets-encrypt server that the server is eligible, by placing a requested token at a requested path (that could look like /.well-known/acme-challenge/iDdCv0Vs1ksYyuNRYfGaV79M0VmeQrzt6Ydgj8HP7EQ).

The certificates are only valid for 90 days but can be automatically renewed via a cron job. Renewal is possible within 30 days of the certificate expiring. The cron job should run more often, as it will just ignore the renewal attempt if the certificate is too recent.

For the biowikifarm the certificate has to include the 50 different domains currently supported by the server. Therefore the certificate issuing and renewal take quite a while.

Further Information:

Updating the certificates for newly added wikis

  • add new domains to /root/ and specify the root directory the domain points to
 sudo /root/ --issue \
 -d -w /var/www \
 -d -w /var/www \
 -d -w /var/www/v-abcd \
important side note: the first domain should always be, as the first domain will determine the name of the certificate which is already referenced in the nginx config. After, all other domains and subdomains are sorted alphabetically. Please add a new domain at the correct position.
  • run sudo /root/ (takes around 10 minutes)
  • if you get a response like Skip, Next renewal time is: ..., add the option --force to the first line of /root/ and run it again
 sudo /root/ --issue --force \
  • the final keys and certificates are located at /root/ and are already referenced in /etc/nginx/nginx.conf
  • (not sure if necessary, but just to be sure) run sudo service nginx reload
  • remove the option --force if you have added it to /root/, otherwise the cron job will generate a new certificate every time, instead of just checking if it needs to be renewed.

Switching Wikis to HTTPS Only

It is relatively easy to adjust the nginx settings of the server, so that a particular domain only supports https and all http requests are forwarded accordingly. These changes must me made in the domain specific setting stored at /etc/nginx/sites-available. The settings so far should look something like this:

server {
	root /var/www/v-example;

	include /etc/nginx/biowikifarm_listen80_443.conf;
	include /etc/nginx/biowikifarm_generics.conf;
	include /etc/nginx/biowikifarm_generic_php.conf;
	location / { 

This section needs to be changed so that it looks like this:

server {
	# redirect requests via http to https
	listen 80; 
	return 301 https://$server_name$request_uri;

server {
	listen 443 ssl;
	root /var/www/v-example;

	include /etc/nginx/biowikifarm_generics.conf;
	include /etc/nginx/biowikifarm_generic_php.conf; 
	location / { 

Note that the line include /etc/nginx/biowikifarm_listen80_443.conf; was removed. This is important as it will result in a configuration error if it is still there. After this, check if the configuration is valid and reload nginx.

sudo nginx -t
sudo service nginx reload

The next step is to check the LocalSettings.php of the wiki, to see if the $wgServer variable is specified as http and adjust it accordingly.

$wgServer = "";

should be changed to

$wgServer = "";

If the variable is protocol independent

$wgServer = "//";

or uses a request to determine the current protocol

$wgProto = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
$wgServer = "$wgProto://";

it can be adjusted, but doesn't have to.

The next step is to check if any of the resources (most likely logo and thumbnail) are included using http links that will result in a mixed-content warning. Adjust those links to https as well. (see section Mixed Content Warning for details).

After this all old http links will automatically be forwarded to https. It might happen that the cookies for logged in users are now invalid and they have to log in again.

Trouble Shooting

Certificate Creation Fails

When generating a new certificate, either because a new domain was added or because the old certificate needs renewal, and a message like this appears

Verify error:Could not connect to http://(sub.domain.tld)/.well-known/acme-challenge/iDdCv0Vs1ksYyuNRYfGaV79M0VmeQrzt6Ydgj8HP7EQ

check if you have specified the correct directory document root for the corresponding domain.

Mixed Content Warning

Mixed Content Warning for the Test Wiki. The warning is shown in a German version of Firefox.

When a wiki is accessed via https, it can happen that the browser shows a warning that the site is not secure. This is usually the case when some resources (e.g. images or style sheets), are loaded using insecure (i.e. http) connections. In Firefox this mean that the lock icon next to the URL in the address bar shows a yellow triangle. In Chrome a grey 'i' in a circle is shown. (Internet Explorer doesn't show this warning).

To fix it, it is important to know which images are loaded using https. This can be easily done using Firefox's build in web console.

  1. open the web console in Firefox using the keyboard shortcut Ctrl+Shift+K.
  2. (re)load the desired page
  3. maybe deselect all of the other warnings and errors besides the one in the security category
  4. you can now see a list of all of the files that caused the Mixed Content Warning.
    Taking a look at the web console of the browser to see which images cause the mixed content warning. The console is shown in a German version of Firefox.
    • In this case, the logo and the thumbnail of the wiki as well as the creative commons graphic were loaded using http links.
  5. open the LocalSettings.php of the wiki and you should be able to find those links
    ##Logo in upper left corner:
    $wgFavicon=""; ## URL of the site favicon.
    $wgRightsIcon = "";
  6. adjust the links to https (or alternatively protocolless like //
  7. save the file
  8. reload the page in your browser
  9. And now the warning icon should be gone
    Mixed Content Warning is gone, instead the green lock icon appears in Firefox (similar green lock in Chrome).