URI rewrite needed

1. Caddy version (caddy version):

v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=

2. How I run Caddy:

systemd

a. System environment:

Ubuntu 18.04

b. Command:

n/a

c. Service/unit/compose file:

n/a

d. My complete Caddyfile or JSON config:

  route /hikvision/* {
    uri replace /hikvision/ /
    reverse_proxy * http://10.10.x.x:80 {
      import header_options
    }
  }

IP redacted…
The whole Caddyfile is not needed…just this route

3. The problem I’m having:

I don’t know much about rewrite URIs, but will explain the problem and see if anyone can help me:
I have a Hikvision camera that I have a reverse proxy to as above in the route snippet. When I go to the camera via the proxy it gets a lot of 404 errors.

When I go to localhost/hikvision is get taken to http://localhost/hikvision/doc/page/login.asp?_1597949745828
If I try to login, I get this message in the chrome dev tools: GET http://localhost/ISAPI/Security/userCheck 404 (Not Found)

This really should be trying to get: http://localhost/hikvision/ISAPI/Security/userCheck if I am correct, for things to work correctly with the reverse proxy.

4. Error messages and/or full log output:

error displayed above

5. What I already tried:

Trying to understand rewrite rules, but not even sure if I am on the right track… :frowning:

6. Links to relevant resources:

This article describes what you’re encountering:

Also FYI, you can replace that config with the following (handle_path does the stripping of the path prefix for you, and the * on reverse_proxy is unnecessary):

  handle_path /hikvision/* {
    reverse_proxy http://10.10.x.x:80 {
      import header_options
    }
  }

Thaks, @francislavoie. That is a good read, but I am no further ahead. I have several other IPs I proxy. One is a weather station, which has no issues. Others are to software I wrote, which has no issues (I had to write special code handle for it to work behind a NAT, so I assume that fix also solved the reverse_proxy bit).

However, any advice on the PTZ (Onvif compliant) camera? I also have several remote cameras, from different manufacturers, but they all exhibit this issue. And likely, with rewrite rules of some sorts, you’d have to know which PTZ is being connected too and provide the rewrite rule for that type of camera?

If they don’t behave well with a subpath proxy and you have no way to configure them, then I recommend trying with a subdomain. You can edit your /etc/hosts file and add some .local domains that map to 127.0.0.1 and use those as separate site blocks for those other services.

I am going to have my IT guy try and decipher what you just said. :slight_smile:

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