Redirect port to subdir

1. Caddy version (caddy version):

2.4.6

2. How I run Caddy:

Docker

a. System environment:

Raspberrypi 4 + Debian 64bit

3. The problem I’m having:

Actually I have the following configuration


Router - server - port 1
                - port 2
                - port 3

On every port I have different service running on my server.

I would like to know how it is possible to configure caddy in order to access the different services with a different subdirectory something like

http://myserver/subdir instead of http://myserver:theportoftheservice

myserver:443 {
        root * /var/www/html/
        file_server
        reverse_proxy /subdir/* 192.168.1.10:theportoftheservice
        tls /etc/caddy/SSL/cert1.pem /etc/caddy/SSL/privkey1.pem
}

it seems it is not working :frowning:

4. Error messages and/or full log output:

If I try to connect to https://myserver/subdir

I get the following page

This is not the page you are looking for

The file /zigbee/ couldn’t be found.

5. What I already tried:

See the Caddyfile part I’ve posted

6. Links to relevant resources:

What you’re asking about is not redirects, but proxying. Very different concepts.

A redirect in the context of web/HTTP is a specific kind of HTTP response which contains a Location header which tells the client to try again but at a different URL.

That said, there’s often issues with proxying to upstream services that aren’t designed to work under subpaths. It’s generally much easier to use subdomains for each service instead, like sub.example.com instead of example.com/sub.

See this article which explains in detail:

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