Closed 30350n closed 7 months ago
Hi! Thanks for your interest in this plugin and for taking the time to report the issue 😁.
I was able to reproduce the error and managed to find the cause. I'll publish a fix in a couple hours.
The problem is that, as you pointed out, the host is not being passed correctly.
I tested from a terminal with a dummy Django api, and this worked fine:
curl http://localhost:9080/hello-world/
{"message":"Hello World"}
If the request is done directly to the IP and the host is passed in the header (which should also work), it fails:
curl http://127.0.0.1:9080/hello-world/ -H 'Host: localhost'
Throws the same error as you reported django.security.DisallowedHost Invalid HTTP_HOST header: ':'. The domain name provided is not valid according to RFC 1034/1035.
Should be fixed in 6012179. If you have time, please test it using the following command to build from main branch:
CGO_ENABLED=1 xcaddy build --with github.com/mliezun/caddy-snake@main
Let me know if the error persists 😅
Thanks a lot for the quick fix!
It appears to be working, but something weird is happening:
So I have been having some issues with 301 redirects from Django lately (which is more or less what made me to try to switch from nginx to caddy in the first place) and with this now I'm getting redirects to inventree.<redacted>.de:8005/index/
for example. So the port I use for internal communication on the shared host somehow ends up in the response for 301 redirects.
Looks like https://github.com/mliezun/caddy-snake/blob/60121794395596bf5ac72fa4fd431bdcd8ed1016/caddysnake.go#L160-L163 could cause that.
In this case Im not able to reproduce the issue. I did this:
$ curl -i http://127.0.0.1:9080/redirection/ -H 'Host: localhost'
HTTP/1.1 301 Moved Permanently
Allow: GET, HEAD, OPTIONS
Content-Length: 0
Content-Type: text/html; charset=utf-8
Location: /hello-world/
Referrer-Policy: same-origin
Server: Caddy
Vary: Accept, Cookie
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
Date: Sat, 24 Feb 2024 12:15:38 GMT
$ curl -i http://localhost:9080/redirection/
HTTP/1.1 301 Moved Permanently
Allow: GET, HEAD, OPTIONS
Content-Length: 0
Content-Type: text/html; charset=utf-8
Location: /hello-world/
Referrer-Policy: same-origin
Server: Caddy
Vary: Accept, Cookie
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
Date: Sat, 24 Feb 2024 12:16:00 GMT
In both cases Location: /hello-world/
would redirect correctly regardless of the base host.
These are the Django views that I used for testing:
class HelloWorldView(APIView):
def get(self, request, format=None):
return Response({"message": "Hello World"}, status=status.HTTP_200_OK)
class RedirectionView(APIView):
def get(self, request, format=None):
return redirect("hello_world", permanent=True)
Can you share a minimal example that I can use to reproduce the error?
Oh yeah sorry, seems like that was a local cache thing. Firefox seems to cache 301s really aggressively. I've cleared the cache and now everything seems to be working. Thanks again!
Awesome! Let me know if you encounter other difficulties while using the plugin.
Thanks again for reporting the issue and for your help debugging.
Im closing this issue as the problem has been resolved.
Hey!
I'm currently trying to get this working with a django project, but I'm getting a
django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: ':'. The domain name provided is not valid according to RFC 1034/1035.
error. Thehost
appears to be correct in the caddy access log, though it's not part of theheaders
directive (I don't know enough about http to tell if that's normal):I'm deploying on a shared host, so everythings going through another
nginx
server (which I can't really configure) before being forwarded to caddy.Before I was using another
nginx
server to serve static/media files which further forwarded to a uwsgi server running the django project. So if this works out, it'd simplify the whole setup quite a lot, thanks to your project 😃