Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you configure Bailador to serve content via TLS (HTTPS)?

I have enjoyed experimenting with Bailador for some time now. It is easy to set up and use for plain HTTP requests, but I would like to serve content over HTTPS.

Some of the Request methods seem to hint that HTTPS requests are possible:

method scheme      { $.env<p6w.url-scheme> || 'http' }
method secure      { so self.scheme eq 'https' }

And the headers method:

method headers () {
    return %!headers if %!headers;
    for $.env.keys.grep(rx:i/^[HTTP||CONTENT]/) -> $key {
        my $field = S:i/HTTPS?_// given $key;
        %!headers{$field.uc} = $.env{$key};
    }
    return %!headers;
}

Plus the cookies have force-https related stuff in them as well.

I have scoured for documentation and examples that indicate how/if HTTPS is supported, but with no success yet.

So, can I serve content over HTTPS in Bailador? If so, how?

like image 680
S. Albano Avatar asked Jul 18 '17 23:07

S. Albano


1 Answers

I hate to be "that guy who doesn't answer your question but sends you somewhere else", but I never do SSL in the app. Make Bailador listen to, say, port 5284 on the localhost only. Then set up a reverse proxy in nginx (includes some letsencrypt stuff):

server {
    listen *:443;
    server_name example.com;

    ssl on;
    ssl_certificate     /etc/letsencrypt/certs/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/certs/example.com/privkey.pem;

    # Optional: only uncomment once you are sure your SSL works!
    #add_header Strict-Transport-Security "max-age=15768000";

    location /.well-known/acme-challenge/ { alias /var/www/letsencrypt/; }
    location / {
        proxy_pass http://127.0.0.1:5284/;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Port 443;
        proxy_set_header X-Forwarded-Host $host;

        # re-write redirects to http as to https
        proxy_redirect http:// https://;
    }
}

For bonus points, redirect all http access to https:

server {
    listen *:80;
    server_name example.com;

    location /.well-known/acme-challenge/ { alias /var/www/letsencrypt/; }
    location / {
        return 301 https://$server_name$request_uri;
    }
}
like image 185
Dean Serenevy Avatar answered Oct 27 '22 23:10

Dean Serenevy