Caddy in a shared hosting environment?

I’m wondering if there’s any documentation or good resources available which describes the process of deploying Caddy in a shared hosting environment, where there are a heap of users and each user needs to spawn Caddy as their own user.
That’s what is puzzling me. As far as I understand, there is no such functionality available out of the box. The closest thing I can think of would be to write some type of hacky shell script which spawns a Caddy process as the user. But even that would likely not work, on closer thought; it would require change to the core of Caddy in order to accomplish this.

Surely there must be a lot of people out there wanting to replace whatever web server they are currently running and use Caddy in their shared hosting environment. I’m not thinking cPanel/WHM users, but mostly people who run custom installations without any type of control panel. Although replacing Apache with Caddy in a cPanel/WHM scenario would undoubtedly be neat, too. But that is not my concern right now. I would like to use Caddy for a smaller production scale situation which involves perhaps 50 users/accounts per server, but as it stands I don’t feel its a very good idea to simply chown my users HTML directories to www-data and call it a day :sweat_smile:

Do any of you know of a viable solution? I’d love to hear it.

Best wishes,
-k0nsl

PS:
If this has already been brought up previously…“mea culpa”! :innocent:

This was discussed in some GitHub issue previously, but basically it comes down to this: Caddy wasn’t designed for direct use by multiple users with different permissions and resource allocations, etc.

So if you want to use Caddy on a shared hosting environment, you’d need a layer on top of it (say, a plugin, or a separate process entirely – I dunno) that manages users and checks that their Caddyfiles don’t try to do anything they aren’t allowed to do, I guess.

You can only have one Caddy process per machine unless you want every user to run on a different port. In that case you could probably do some crazy kind of reverse proxying but, well, I don’t recommend that, since proxying introduces another level of indirection on the network which often turns out to be more of a problem than a solution in the long run.

Anyway, as “necessary” as shared hosting is, I don’t really endorse it because of the many, many problems and awful software out there that accomplish it. But I do love the idea of Caddy reaching more users…

Thank you Mr. Holt for your response. Well, I suppose in that case, at least for now, I’ll have to just bite the bullet and make the owner www-data and then manage everything on my own, like you typically would on a server where just a few sites, or just one site, is hosted.

Another thing: my vision with Caddy in a shared hosting environment did not necessarily require each user to have their own Caddyfile or have the ability to touch anything having to do with Caddy. There could be just one file with all the virtual hosts, since I wasn’t going to let any of the users have any access or be able to make changes to their Caddyfile anyway. I would do all such changes myself. The only thing required in my scenario was to have Caddy being able to run as $user in some way; creating some “separation” so to speak.

Well, in any case, thanks again for answering. At least now I know this isn’t likely to be a thing for a moment or two :smiley:

Best wishes,
-k0nsl

I had a dream (really), on which I created a “Caddy Shared Hosting”. Basically, it was a pretty panel, and for every customer it spawned an OpenVZ container with Caddy inside. It was not a VPS in the sense you could SSH into it, but you could click the button to manage the Caddy binaries and configurations by yourself, or let the panel automatically perform upgrades and such. Like a Software-as-a-Service!

Oh, and the OpenVZ containers would have an internal IP address binded to it. The host node proxied the requests to the respective containers. Fun stuff :stuck_out_tongue_closed_eyes:

1 Like

A docker solution would be neat (because lets double down on the unproven-in-production software :smiley:)

  • One container with the main Caddy proxy
  • One container with jwilder’s docker-gen to template Caddyfiles and reload Caddy automatically
  • Write scripts to launch Caddy containers to host on a per-site, per-client basis

You could conceivably write a WHMCS module for it, it wouldn’t even be hard. As long as you don’t have 500+ clients signing up every three hours…

1 Like

I think we could fork this, update it to use PHP 7, and swap nginx with Caddy:
http://www.sebdangerfield.me.uk/2012/05/nginx-and-php-fpm-bash-script-for-creating-new-vhosts-under-separate-fpm-pools/

My idea is to setup a similar nginx structure (e.g.: /etc/nginx/sites-enabled → /etc/caddy/sites-enabled), so it would be easier to swap it.

I’m also considering installing Caddy following the instructions here, to keep things “maintainable”:
https://github.com/mholt/caddy/tree/master/dist/init/linux-systemd

Would anyone be interested?

Edit: I’ve started working on it, currently rewriting the template files into Caddy format :slight_smile:
Edit 2: Managed to get a prototype working, just need to test it a little bit more before making a Git repo. Any name suggestions?

That’s already doable, unless I’m completely misunderstanding you? Caddy can run as any user, www-data is the suggested user, but you can run it as any $user you want. It’s up to you and your operating system as to user id, and access to low ports (80/443).

Kind of interested in working on an actual cPanel like panel for Caddy. PM me if your interested.

This may be relevant to your interest, @NurdTurd:

I’m using Webfaction (semi-shared) hosting which uses Nginx (as reverse-proxy), but it is allowed to e.g. build one’s own server to work behind it - I did use Cherokee/Hiawatha in the past for serving my own Django/PHP-powered sites or to simply depend on the system-wise instance of Apache2 server…

Now, I’m moving fully to Hugo and wonder whether you would recommend to build and use Caddy to work behind reverse-proxy to serve Hugo site instead of depending on Apache2?

Considering that I also use Piwik, what do you think to re-configure my current setup and use Caddy to serve that PHP-powered site as well?

Main consideration of potential migration to Caddy is, of course, less memory used by Caddy in comparison with Apache2 and possible performance improvements?

I’m aware that running my own VPS would enable me to put Caddy at the front, but after having experience with VPSes (mostly Linode), I did revert back to Webfaction since its hosting does free me from the headaches of maintaining my own system consisting of several servers including one for email…

Edit: Forgot to mention that one of the main motives to use Caddy is to be able to use caddy-hugo - ability to allow not-so-savvy users to contribute content for non-profit web site by providing web interface for the Hugo-generated web site.