Exit Code 1 when trying to serve multiple subdomains (reverse proxy and static website)

1. Caddy version (caddy version):

v2.4.6 h1:HGkGICFGvyrodcqOOclHKfvJC0qTU7vny/7FhYp9hNw=

2. How I run Caddy:

Caddyfile
foundry.odragaoverde.com {
# PROXY ALL REQUEST TO PORT 30000
reverse_proxy localhost:30000
encode zstd gzip
}

link.odragaoverde.com {
root /home/ubuntu/www/link
gzip
}

a. System environment:

Ubuntu 20.04

b. Command:

$ sudo systemctl start caddy

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

# A CONFIG SECTION FOR YOUR HOSTNAME

foundry.odragaoverde.com {
    # PROXY ALL REQUEST TO PORT 30000
    reverse_proxy localhost:30000
    encode zstd gzip
}

link.odragaoverde.com {
    root /home/ubuntu/www/link
    gzip
}

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

3. The problem I’m having:

I am trying to host a website in a oracle cloud machine that I use as well with a reverse proxy.
The reverse proxy part was working as intended when I don’t include the second block (link.odragaoverde.com) I have been readying the documentation and I have no idea what might be wrong all I get is “Job for caddy.service failed because the control process exited with error code.
See “systemctl status caddy.service” and “journalctl -xe” for details.”

4. Error messages and/or full log output:

● caddy.service - Caddy
Loaded: loaded (/lib/systemd/system/caddy.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2022-02-11 12:58:45 UTC; 41s ago
Docs: Welcome — Caddy Documentation
Process: 80082 ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile (code=exited, status=1/FAILURE)
Main PID: 80082 (code=exited, status=1/FAILURE)

Feb 11 12:58:45 foundry caddy[80082]: HOME=/var/lib/caddy
Feb 11 12:58:45 foundry caddy[80082]: LOGNAME=caddy
Feb 11 12:58:45 foundry caddy[80082]: USER=caddy
Feb 11 12:58:45 foundry caddy[80082]: INVOCATION_ID=5ec29c94c5234342a0c35b8d7cd0307a
Feb 11 12:58:45 foundry caddy[80082]: JOURNAL_STREAM=8:1534563
Feb 11 12:58:45 foundry caddy[80082]: {“level”:“info”,“ts”:1644584325.4215896,“msg”:“using provided configuration”,“config_file”:"/etc/caddy/Caddyfile",“config_adapter”:""}
Feb 11 12:58:45 foundry caddy[80082]: run: adapting config using caddyfile: parsing caddyfile tokens for ‘root’: /etc/caddy/Caddyfile:12 - Error during parsing: Wrong argument count or unexpected line ending after ‘root’
Feb 11 12:58:45 foundry systemd[1]: caddy.service: Main process exited, code=exited, status=1/FAILURE
Feb 11 12:58:45 foundry systemd[1]: caddy.service: Failed with result ‘exit-code’.
Feb 11 12:58:45 foundry systemd[1]: Failed to start Caddy.

5. What I already tried:

I am still pretty new to all these, I tried reading the documentation, rewrote Caddyfile several times, checked the syntax.

6. Links to relevant resources:

As mentioned in the documentation of the root directive :

Note that the <path> argument could be confused by the parser as a matcher token if the it begins with /. To disambiguate, specify a wildcard matcher token (*).

Also it seems you want to serve files from this directory, so a file_server directive is needed.
Third, gzip is not a directive but a parameter to the encode directive.

So the second block should be:

link.odragaoverde.com {
    root * /home/ubuntu/www/link
    file_server
    encode gzip
}
3 Likes

Thank you so much!

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.