Skip to content

Commit

Permalink
Merge pull request #2321 from drgrice1/certbot-renewal-endpoints
Browse files Browse the repository at this point in the history
Add optional certbot renewal routes.
  • Loading branch information
pstaabp authored Feb 14, 2024
2 parents 4a78f81 + 2bd380a commit 0ef28a2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
26 changes: 26 additions & 0 deletions conf/webwork2.mojolicious.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,32 @@ server_group: www-data
# used when serving the webwork2 app directly.
redirect_http_to_https: 0

# Change enable_certbot_webroot_routes to 1 to enable routes in the webwork2 app
# used by certbot for certificate renewal with the webroot option. Note that
# this should only be used when serving the webwork2 app directly. You will also
# need to add "- http://*:80" as well as "- http://*:443" to the hypnotoad
# listen values below for this to work.
# Then execute
# sudo certbot certonly --webroot -w /opt/webwork/webwork2/tmp \
# -d your.domain.edu \
# --post-hook "chown -R www-data:www-data /etc/letsencrypt && systemctl reload webwork2"
# to renew certificates without needing to stop the webwork2 app. That command
# will renew the certificate for the first time, and also set up autorenewal in
# the future. Obviously your.domain.edu needs to be changed to your actual
# domain name. Note that /opt/webwork/webwork2/tmp is the default value of
# $webworkDirs{tmp}. If you customize $webworkDirs{tmp} in localOverrides.conf,
# then you will need to use what you have that variable set to instead. Be
# careful since the default value of $webworkDirs{tmp} depends on the value of
# $webworkDirs{root} (which is /opt/webwork/webwork2 by default). So if you
# customize $webworkDirs{root}, then you will need to adjust the path
# accordingly. Also, change www-data:www-data in the command to be
# server_user:server_group where server_user and server_group are the values of
# those settings above. The post hook in the command will run every time that
# certificates are automatically renewed, and will fix permissions on the new
# certificates so that the webwork2 app can read them, and will hot reload the
# webwork2 app to load the new certificates (with zero downtime).
enable_certbot_webroot_routes: 0

# hypnotoad server configuration
# See https://docs.mojolicious.org/Mojo/Server/Daemon
# Any of the attributes listed there can be set in this section.
Expand Down
11 changes: 11 additions & 0 deletions lib/Mojolicious/WeBWorK.pm
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,17 @@ sub startup ($app) {
}
}

# Letsencrypt renewal route.
if ($config->{enable_certbot_webroot_routes}) {
$r->any(
"/.well-known/*static" => sub ($c) {
my $file = "$ce->{webworkDirs}{tmp}/.well-known/" . $c->stash('static');
return $c->reply->file($file) if -r $file;
return $c->render(data => 'File not found', status => 404);
}
);
}

# Note that these routes must come last to support the case that $webwork_url is '/'.

my $cg_r = $r->under($webwork_url)->name('root');
Expand Down

0 comments on commit 0ef28a2

Please sign in to comment.