My first caddy server: 502 error

  • explain what you are trying to do,
    Trying to get my first caddy server setup but I keep getting a 502 error.

  • show what you have already tried,
    I’ve been working on it for 2 days and still have no idea.

  • include error messages and log output,

Nov 23 05:43:51 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: Stopped blockchain-class.com app.
Nov 23 05:43:51 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: lenslocked.com.service: Scheduled restart job, restart counter is at 322.
Nov 23 05:43:51 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: lenslocked.com.service: Service hold-off time over, scheduling restart.
Nov 23 05:43:21 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: lenslocked.com.service: Failed with result 'exit-code'.
Nov 23 05:43:21 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: lenslocked.com.service: Main process exited, code=exited, status=203/EXEC
Nov 23 05:43:21 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[2526]: lenslocked.com.service: Failed at step EXEC spawning /root/app/server: Permission denied
Nov 23 05:43:21 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[2526]: lenslocked.com.service: Failed to execute command: Permission denied
  • and link to any relevant resources.
    I can put file snippets here, if anyone wants to help please let me know what you want to see.

system: ubuntu 16.04, digital ocean droplet, Caddy 0.11.1 (non-commercial use only)

Hi @yshuman1, welcome to the Caddy community!

Here’s some information that would be helpful in determining the best way to troubleshoot the problem:

  • How did you install Caddy?
  • How do you run Caddy?
    (e.g. systemd unit file, CLI command, flags & parameters, etc)
  • What’s your Caddyfile?

I’m not sure that your systemd logs relate to Caddy itself; although I note that apparently you’re another customer of @joncalhoun’s excellent course! Are you planning to use Caddy to proxy your lenslocked app?

1 Like

hi @Whitestrake,

Yes! I am working on @joncalhoun’s lenslocked tutorial. Have you done it? I have been wrestling with caddy for two days, i legit don’t know what I’m missing.

I installed caddy using the curl command.
During the tutorial I created a couple files, related to caddy and i believe one of them is the one firing it up each time.

here is my Caddyfile

:80 {
        gzip
        proxy / localhost:3000 {
                transparent
        }
}

and here is my caddy.service

[Unit]
Description=caddy server for server for lenslocked.blockchain-class.com

[Service]
WorkingDirectory=/root/app
ExecStart=/usr/local/bin/caddy -agree=true -email email@yasin.io
Restart=always
RestartSec=120
LimitNOFILE=8192

[Install]
WantedBy=multi-user.target

I have indeed! Multiple times, actually - I found it, personally, to be a very efficient teaching tool. Each subsequent time I did it I deviated from the book in some significant way and built on the knowledge. It helped me learn Go very quickly and quite a few general web development skills, too. Bought his second course as well, looking forward to starting that at some point. But you’re not here for a testimonial, you’re here to get your site online :stuck_out_tongue:

Your configuration looks good to me. The problem I think might actually be with your lenslocked app. The fact that you’re seeing status 502 means Caddy received your request, tried to proxy it upstream, but didn’t get a response to give back to you, the client.

One quick way to test exactly what Caddy is seeing, when it proxies upstream for you, is to use curl. Try running this from a shell on the Caddy host:

curl -I http://localhost:3000/

1 Like

Like this?

Yep. Looks like your Go app isn’t starting properly for some reason so the issue isn’t actually caddy.

That is also why you see log lines like:

lenslocked.com.service: Main process exited, code=exited, status=203/EXEC

What happens if you just try to start the Go app on the server via command line? Any error messages?

2 Likes

Thanks jon & Mathew, I’ve narrowed down to realize its not a prob with caddy but something else in my setup.

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