Skip to content

Generating Let's Encrypt certificates - HTTP challenge

Certificates generated by Certbot are stored on the host in the folder:

./certificats/certbot

This folder is mounted in the Nginx container at:

/etc/letsencrypt

How it works

A Certbot container runs permanently alongside NGX Ops. Its role is only to handle renewal of existing certificates.

When a new certificate must be generated, NGX Ops starts an ephemeral Certbot container dedicated to this request.

The generated certificate is then kept in the shared directory:

./certificats/certbot

Certbot configuration

1 - Go to the ADMINISTRATION / Configuration page, on the tab: Certbot - HTTP challenge.

2 - In the input area, enter the configuration and click Save.

enable: true
email: [email protected]
staging: false
container_image: certbot/certbot:latest
webroot_host_path: /containers/nginx/nginx/webroot
certs_host_path: /containers/nginx/certificats/certbot

If you use a private ACME service:

enable: true
email: [email protected]
staging: false
server: https://acme.domain.tld:9000/acme/acme/directory
ca_bundle_host_path: /path/file/ca-local-root.crt
container_image: certbot/certbot:latest
webroot_host_path: /containers/nginx/nginx/webroot
certs_host_path: /containers/nginx/certificats/certbot

💡 Tip: The paths shown are absolute paths on the host.

3 - Go to the SSL / Certbot page and start the renewal container.

Request a certificate with the HTTP challenge and configure the virtual host

Unlike what you may know from other tools, with NGX Ops it is not enough to create a virtual host on port 80, request a certificate, then let NGX Ops configure the virtual host automatically.

This is deliberate. NGX Ops is designed to be used with a GitOps approach and must not have write access to the repository holding the configuration.

Generating a certificate and creating the virtual host are therefore two separate operations. You need to go through several steps to generate the certificate, get the necessary information, then integrate its configuration into the Git repository.

This approach keeps Git as the source of truth and prevents a change made from the NGX Ops interface from directly modifying the versioned configuration.

We start from the example used at the beginning of this documentation:

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://192.168.1.1;
    }
}

Warning: each time you change a virtual host configuration file, you must reload Nginx to apply the changes.

  1. Prepare the HTTP challenge

Before we can request the certificate, we must let Let's Encrypt reach our server to perform the HTTP challenge.

To do so, we include the snippets/letsencrypt-webroot.conf snippet:

location /.well-known/acme-challenge/ {
    root /var/www;
}

This snippet lets Certbot drop the files needed to validate the domain in /var/www. Nginx can then serve them directly when Let's Encrypt makes its request.

Our virtual host therefore becomes:

server {
    listen 80;
    server_name example.com;

    include snippets/letsencrypt-webroot.conf;

    location / {
        proxy_pass http://192.168.1.1;
    }
}

Then reload Nginx to apply this configuration.

  1. Generate the certificate

In SSL / Certbot, in the HTTP section, enter the domain name in the field provided.

Then click Add, then Generate.

Wait a few seconds while Certbot performs the HTTP challenge and generates the certificate.

Once the certificate is generated, it will be available in the /etc/letsencrypt tree.

  1. Switch the virtual host to HTTPS

Once the certificate is generated, we can change the virtual host so it listens on HTTPS:

server {
    listen 443 ssl;
    http2 on;
    server_name example.com;

    include snippets/letsencrypt-webroot.conf;

    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    location / {
        proxy_pass http://192.168.1.1;
    }
}

You must also keep a virtual host on port 80 to redirect visitors to HTTPS:

server {
    listen 80;
    server_name example.com;

    include snippets/letsencrypt-webroot.conf;

    return 301 https://$host$request_uri;
}

The letsencrypt-webroot.conf snippet is deliberately kept in the HTTP block. It notably lets you keep answering Let's Encrypt HTTP challenge requests when the certificate is renewed.

After saving the changes, reload Nginx to apply the new configuration.