tomsquest/docker-radicale

Problem with nginx reverse proxy because of trailing slash

cyberius0 opened this issue · 5 comments

edit: solved the problem by myself.

In case anybody wants to use nginx reverse-proxy with this container and is getting an error like

The requested resource could not be found.
or

This page isn’t working
<domain> redirected you too many times.
[Try clearing your cookies]
ERR_TOO_MANY_REDIRECTS

This is my working config file for nginx:

server {
     listen 443 ssl http2;
     listen [::]:443 ssl http2;

     server_name <domain>;
     include /config/nginx/ssl.conf;
         location / {
             proxy_set_header     X-Script-Name /radicale;
             proxy_set_header     X-Forwarded-For $proxy_add_x_forwarded_for;

             auth_basic           "Login required";
             auth_basic_user_file /config/nginx/htpasswd_radicale;

         include /config/nginx/proxy.conf;
         include /config/nginx/resolver.conf;

         set $upstream_app radicale;
         set $upstream_port 5232;
         set $upstream_proto http;
         proxy_pass $upstream_proto://$upstream_app:$upstream_port;

         }


       location ~ ^/radicale/(.*)$ {
        proxy_set_header     X-Script-Name /radicale;
         proxy_set_header     X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header     X-Remote-User $remote_user;
         auth_basic        "Login required";
         auth_basic_user_file /config/nginx/htpasswd_radicale;

                  include /config/nginx/proxy.conf;
                  include /config/nginx/resolver.conf;

                  set $upstream_app radicale;
                  set $upstream_port 5232;
                  set $upstream_proto http;

         proxy_pass $upstream_proto://$upstream_app:$upstream_port/$1$is_args$args;

     }
}

@cyberius0 you found the issue eventually?

@cyberius0 you found the issue eventually?

Within

	location /radicale/ {
	[...]

we need a trailing slash at the end of the destination.

	e.g. proxy_pass http://localhost:5232/;
	or  proxy_pass http://<docker-container ip>:5232/;

This is working fine if we enter the IP of the radicale docker-container..

BUT: As the IP of the docker-container ist not static and can change, normally we do it like this:

    set $upstream http://radicale:5232;
    proxy_pass $upstream/;

Now nginx gets the ip by resolving the hostname.

BUT: This only works without a trailing slash. (Why ?)

To make it work with the trailing slash, we have to do use the little "hack" above.

👍 for the info @cyberius0

I am glad to use Caddy as the reverse proxy :) much simpler :)

solved (see Edit)

hey there, sorry to bother, but could you share your Caddyfile-Config?

i can't seem to get mine to work.

i have a simple

radicale.domain.tld {
 reverse_proxy radicale:5232
}

I tried setting the Port to just

5232:5232

instead of

127.0.0.1:5232:5232

and proxy to

ipOfServer:5232

and i tried adding a

header_up X-Script-Name /radicale

from the Docs of the Upstream Project, but none of that worked.

Edit:
NVM, i'm stupid, it was a networking Issue.
I forgot to add Radicale to my Proxy Network. i'm an Idiot