Althttpd

Running both HTTP and HTTPS in a single invocation
Login

Running both HTTP and HTTPS in a single invocation

(1) By Stephan Beal (stephan) on 2022-01-18 07:24:31 [link] [source]

It's clear that the althttpd infrastructure doesn't support running both HTTP and HTTPS in a single instance, but my suspicion is that this would be trivial to simulate by...

  • Starting up using one mode or the other.
  • forking and exec()'ing a second instance with CLI flags configured for the other mode.

The only(?) addition would be the need for 2 flags for specifying the port numbers separately, maybe --port and --sport, and if both are specified (0 to use the default) then launch in dual mode, else follow the current behavior.

Is that something worth doing?

Something like:

$ althttpd -root /blah -user foo -port 0 -sport 0 --cert /my/cert

would, assuming it's started as root, listen on ports 80 and 443.

Alternately, a syntax of --ports 0:0 or --ports 0,0 might be more intuitive, or possibly recycle --port for that purpose, entering dual mode if it has a colon or comma.

(2) By sodface on 2022-01-19 04:51:42 in reply to 1 [link] [source]

I don't really have a good answer to provide to support this feature, but I support it, even if I can't support my support for it.

A recent article here

resulted in the author continuing the http version of his website with an https version with a self signed cert.

Would this not also make redirecting from 80->443 easier?

(3) By Stephan Beal (stephan) on 2022-01-19 05:32:54 in reply to 2 [link] [source]

I don't really have a good answer to provide to support this feature

Here's one: "Apache can do it." ;)

A recent article here

Interestingly, ESR's website has long been HTTP-only and visiting the site in HTTPS results in an invalid cert error (that particular domain is not, as of this writing, listed in the cert the server is offering).

AFAIK, the only compelling argument for dogmatically insisting on HTTPS for even plain static sites is that it's otherwise possible for ISPs and proxies to manipulate the content and/or headers with no indication that they've done so.

Would this not also make redirecting from 80->443 easier?

i don't think so (but may be mistaken). A redirect always requires telling the client to go somewhere else and expecting them to actually do it. We don't have a way to redirect a user from HTTP to HTTPS without sending them an HTTP response saying "go visit this HTTPS URL instead." We can only show them the way, though. It's up to them to take it (or not).

(4.2) By sodface on 2022-01-19 16:03:00 edited from 4.1 in reply to 3 [link] [source]

We don't have a way to redirect a user from HTTP to HTTPS without sending them an HTTP response

Yes, sorry, that isn't what I meant though that is how my poorly worded comment reads. I don't really even know what I was getting at now that I think about it, other than it just seems more elegant to have a single instance of althttpd fielding both HTTP and HTTPS, whether that's to serve both or to return blanket redirects from one to the other.

But I haven't actually needed to do either of those things before. All of my previous web server experience is HTTP only. With that in mind, here are maybe some more stupid questions:

I assume the two most common scenarios would be:

  • Serve both HTTP and HTTPS versions of the same site(s)
  • Transition a previously HTTP only site to HTTPS by returning redirects for all HTTP requests

How does the new HTTPS --cert implementation affect using the virtual host directories? Doesn't each domain need a different cert? // edit, I guess not, looks like multiple domains in a single cert is supported with a Subject Alternative Names (SAN) cert.

If single invocation support for HTTP and HTTPS were implemented, could it support something like a --redirect argument to automatically listen on port 80 and respond with redirects? The homepage mentions using an "-auth" file in the context of HTTP->HTTPS redirects so maybe that is the answer, but as I said above, I haven't previously had a need to configure or test it so I'm not sure.

(5) By Stephan Beal (stephan) on 2022-01-19 16:08:42 in reply to 4.1 [source]

Serve both HTTP and HTTPS versions of the same site(s)

i think (without having any data to back that up) that's the most common approach for most sites currently. AFAIK, Apache still dominates the public web space (and it certainly does on shared hosters) and Apache can be told to listen to both protocols.

Transition a previously HTTP only site to HTTPS by returning redirects for all HTTP requests

That's increasingly common. It's also common for browsers to first try HTTPS when just given a domain name.

How does the new HTTPS --cert implementation affect using the virtual host directories?

It doesn't, but...

Doesn't each domain need a different cert?

Yes and no. For althttpd, unequivocally yes, but:

  1. That's trivial to do with letsencrypt/certbot. They can be told to create a single cert which spans any number of domains (no idea what the upper limit is). To go back to the example of ESR's site, if you hit it with HTTPS, Firefox will warn that that domain is not one of the ones listed for that cert, and it proceeds to list at least 10 or 15 different domains that cert is valid for.

  2. So-called wildcard certs can be used for a single domain and all of its subdomains, but the infrastructure for automating their renewal is (based solely on what i've read) trickier.

If, however, you are unable or unwilling to create a multi-domain or wildcard cert then althttpd is probably not going to be a good solution for HTTPS unless your domains all listen on different ports (and can therefore have different althttpd configs tied to them). That doesn't sound appealing, though.

If single invocation support for HTTP and HTTPS were implemented, could it support something like a --redirect argument to automatically listen on port 80 and respond with redirects?

i don't see why not, especially given...

The homepage mentions using an "-auth" file in the context of HTTP->HTTPS redirects so maybe that is the answer...

i believe that same approach could be used for the dual-mode case. The HTTP-running instance would simply need to be aware of what port the sibling instance is listening on so that it can redirect properly.