How can I serve a different project on a <website>/<projectname> URL?

1. My Caddy version (caddy -version):

v1.0.3

2. How I run Caddy:

a. System environment:

Digitalocean VPS (Ubuntu).

b. Command:

nohup caddy &

c. Service/unit/compose file:

Sadly I have no idea what this means :frowning:

d. My complete Caddyfile:

jossecottenier.tech

proxy /captcha localhost:3001
proxy /contactform localhost:3001
proxy /test localhost:2020

3. The problem I’m having:

As you can see in my Caddyfile above, I’m trying to get a seperate React project to be served at /test.

The way I tried to do this is serving it via caddy on localhost:2020 and then adding a proxy in the Caddyfile, as you can see above.

4. Error messages and/or full log output:

No error messages, just 404 not found when I try to visit the URL.

5. What I already tried:

Restarting caddy services, trying to run with caddy instead of nohup caddy &.

6. Links to relevant resources:

(None)

Hi @Josse3, welcome to the Caddy community!

No worries if you don’t have one - these would be methods of having some kind of supervisor run Caddy for you, like systemd or Docker.

Would you mind posting Caddy’s output when you run nohup caddy &? It should go to a file nohup.out in the same directory you run it from.

Also, while Caddy is running, could you post the results of:

curl -IL localhost:2020
curl -IL localhost:2020/test
curl -ILH "Host:jossecottenier.tech" localhost/test

These will give us an idea of what Caddy is doing and what it’s seeing when proxying.

Hi @Whitestrake, thank you for your reply!

nohup.out of the main directory:

Serving HTTPS on port 443 
https://jossecottenier.tech


Serving HTTP on port 80 
http://jossecottenier.tech

WARNING: File descriptor limit 1024 is too low for production servers. At least 8192 is recommended. Fix with `ulimit -n 8192`.

nohup.out of test directory:

Activating privacy features... done.

Serving HTTP on port 2020 
http://localhost:2020

Activating privacy features... done.

Serving HTTP on port 2020 
http://localhost:2020

WARNING: File descriptor limit 1024 is too low for production servers. At least 8192 is recommended. Fix with `ulimit -n 8192`.

Output of curl -IL localhost:2020:

HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 2332
Content-Type: text/html; charset=utf-8
Etag: "pzl43o1ss"
Last-Modified: Fri, 18 Oct 2019 19:14:12 GMT
Server: Caddy
Date: Sat, 19 Oct 2019 13:54:56 GMT

Output of curl -IL localhost:2020/test (actually ‘/ilias’ because ‘test’ was just a placeholder name):

HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
Server: Caddy
X-Content-Type-Options: nosniff
Date: Sat, 19 Oct 2019 13:56:30 GMT
Content-Length: 14

Output of curl -ILH "Host:jossecottenier.tech" localhost/test (actually /ilias):

HTTP/1.1 301 Moved Permanently
Connection: close
Content-Type: text/html; charset=utf-8
Location: https://jossecottenier.tech/ilias
Server: Caddy
Date: Sat, 19 Oct 2019 13:58:21 GMT

HTTP/2 404
content-type: text/plain; charset=utf-8
date: Sat, 19 Oct 2019 13:58:21 GMT
server: Caddy
server: Caddy
x-content-type-options: nosniff
content-length: 14

Thanks in advance for your time!

Ahh, I see, you’ve got two Caddy servers and the backend Caddy at 2020 is just serving files?

By proxying /ilias to the secondary Caddy server, that server is seeing a request for /ilias - but it’s web root is ./ilias - so it’s trying to find a file in ./ilias/ilias relative to the main Caddy and finding nothing - make sense?

Ditch the backend Caddy server and remove the proxy. The “main” Caddy server can serve files out of the subdirectory automatically.

Hi @Whitestrake

Apparently I was doing things in a weird way.
Someone helped me out and I got it working.
Thanks a lot for your time anyways!

1 Like