Hosting tutorial


I want to host some basic html, css and jsfiles on my droplet (server on digital ocean) using caddy, but I am not sure how to get there. I have a domain name aswell. I have been able to host an index file doing this before with help from a friend, but after that trying on my own evrything is chaos and I do not know where to go next and which tutorial I should use since I have done different small thing for some months trying to get this done.

I have tried thousands thing, but never made one thing to a finish. Including, nginx, heroku, hosting with and the list goes on and on. Since I have tryed everything, I have completely lost overview over everything.

I started with this tutorial now:
but I wonder if that maybe is one step in the wrong direction since I have already been able to host with caddy?

My main question is, does anyone have a tutorial I can follow slavishly that let me upload three files to my server?

Hi @andymoose, welcome to the Caddy community.

I don’t know about a fully fledged tutorial - if you’ve got an index file up once already, you’ve got what you need!

Serving other assets with Caddy is exactly the same as serving an index - the only difference is that you request a different file.

Lets assume you’ve put three files next to each other in the directory /var/www/html

  • index.html
  • example.css
  • example.js

and the following Caddyfile:
root /var/www/html

And you’ve got Caddy running.

Now you browse to to download the index file, for the stylesheet, and to get the javascript.

Unless you wanna do something more complicated with your website, that’s all there is to it. Give it a shot, and if you get hung up somewhere, let us know what’s going on and we can help you sort it out.

@Whitestrake thanks, but the index file is not up and running now. I do not remember how I removed it, but when I refresh I get error 404

Why is it called caddyfile?

Should I make a directory called /Var/Www/html and put my files in it? I see thats been used a lot.

You’ll need to get a new index file and save it to that directory as index.html.

That’s the name the developer chose to refer to the configuration file.

It follows a similar naming convention to a Vagrantfile or a Dockerfile.

This is a common convention in the Linux web hosting world. You don’t need to; another convention I’ve seen used a lot is /srv/ or maybe /var/www/html/ for servers hosting multiple websites.

Realistically, you can move it wherever you like, as long as you point Caddy’s root directive at the directory you pick.

Should I be rooted into my server with ssh@root ipadress before I do this or should it be done on my computer? I think I miss some basic knowledge about this theme.

Now I have directory on my computer with this path: C/var/www/html where I have my index.html, js.js and css.css and a Caddyfile.txt consisting of what you said should be in it.

All instructions are for the server (the Caddy host), not for your own PC (unless you’re using your own PC to serve your website).

The server on the left looks like there’s already a web server running. You’ll need to take it down before starting Caddy.

@Whitestrake How can I take it down?

Did you set the other web server up yourself, did someone else, or was the server in question a VPS pre-configured with a web server stack?

A combination of the two first. How can I find that out? I tried to use ngingx, but someone took that down for me so I could use caddy instead @Whitestrake

Actually, I think you’ve just run Caddy in the background and you’ve kept trying to run it again after it’s already in the background.

Just pkill caddy to terminate the background process.

While you’re testing to get things working, run it in the foreground instead so you can see the output, terminate it (with CTRL+C), make changes, and run it again if needs be.

Anyway, on the VPS, put your files in the directory you chose, put the address of the site you want to serve in the Caddyfile along with a root directive pointing to that directory, try it again and let us know what happens.

Tried some things now. Just a problem, not caddyrelated but commandos in the terminal. What commands do I use to upload files from my computer to my server?

Need to upload these like you said to the path var/www/html:

  • index.html
  • example.css
  • example.js
  • Caddyfile.txt

What does it mean that I have a hashtag after my directory in the cmdline? It now says var/www/html#.

Btw, what do you mean with running things in the foreground and background? Thanks for being patience, and sorry for learning like a five years old, I find this very hard.

A good CLI tool for this purpose is scp (Secure Copy). It works just like cp (Copy) you’re probably familiar with, except that you prepend either the source or destination with an SSH host.

If you’ve got myfile.txt in your home folder on your own computer, and want to place a copy in your web directory of your VPS, you’d use:

scp ~/myfile.txt

You can read more about it by typing man scp in your shell.

That’s your prompt. The hash is (probably) just there to indicate that you can type after this point.

A job or process running in the “foreground” means that it’s hooked up directly to your shell - its output goes to you as text, and anything you type goes straight to the program.

A background process is different because it’s not outputting to your shell, and it’s not receiving input from your shell. It does its work behind the scenes, out of view. Background processes are usually either daemons (started and maintained by the OS’ init system) or one-off jobs that you, the user, spin off into the background using job control.

Your bourne again shell (bash) has job control functionality built in - this is what & is a part of; it moves whatever command you just ran into the background, so you can keep working at your shell prompt, but it keeps the program’s output echoing to your shell so you can watch what it’s doing.

You can read more on that with man bash in your shell - search for “JOB CONTROL”.

What am I doing wrong now? The site adress just gives me “the connection was timed out”

Which site address are you using?

@Whitestrake can we talk about this in a chat? Things are going so slow when I am taking a small step every day

Whitestrake just spent two hours helping me getting this to a done. He is a true hero and deserves a christmas gift

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.