tomsquest / docker-radicale

Docker image for Radicale calendar and contact server :calendar: + security :closed_lock_with_key: + addons :rocket:
GNU General Public License v3.0
591 stars 82 forks source link

Problem with nginx reverse proxy because of trailing slash #134

Closed cyberius0 closed 1 year ago

cyberius0 commented 1 year ago

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;

     }
}
tomsquest commented 1 year ago

@cyberius0 you found the issue eventually?

cyberius0 commented 1 year ago

@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.

tomsquest commented 1 year ago

:+1: for the info @cyberius0

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

Neon-44 commented 9 months ago

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

tomsquest commented 9 months ago

@Neon-44 FYI I added my Caddyfile to the Readme https://github.com/tomsquest/docker-radicale/?tab=readme-ov-file#running-behind-caddy