sabre-io / Baikal

Baïkal is a Calendar+Contacts server
https://sabre.io/baikal/
GNU General Public License v3.0
2.52k stars 291 forks source link

"Error 404" for baikal on subpage and nginx *reloaded* #361

Closed csandmann closed 8 years ago

csandmann commented 9 years ago

Hi there,

I am trying to set up my own calendar/contact server. After longer research and recommendations from friends I decided to use the Baikal regular package. Since I don't have a domain, I want to run baikal on a subpage, not a subdomain.

The problem I am encountering seems to lie in the combination of nginx / subpage: I can access the admin-area without problems, but for some reason I keep getting "Error 404" whenever I try to load the calendar into thunderbird.

I realize that this issue already came up on github, but for some reason the proposed solution did not work for me.

I am trying to run Baikal on the following configuration

The specific problems seem to be

<d:error>
     <s:exception>
          Sabre\DAV\Exception\Forbidden
     </s:exception>
     <s:message>
          Requested uri (/baikal/cal.php) is out of base uri (/groupdav/cal.php/)
     </s:message>
     <s:sabredav-version>
          1.8.7
     </s:sabredav-version>
</d:error>
<d:error>
     <s:exception>
          Sabre\DAV\Exception\NotImplemented
     </s:exception>
     <s:message>
          GET is only implemented on File objects
     </s:message>
     <s:sabredav-version>
            1.8.7
     </s:sabredav-version>
</d:error>

Does anyone see, where the problem might lie?

Best

Constantin

**this is my nginx-config file:**
server {
      listen 443 ssl;
      server_name some_name;
      root /var/www/;

      #SSL configuration
      ssl on;
      ssl_certificate         some_certificate;
      ssl_certificate_key  some_private_key;

      #Main Location
      location / {
            index /html/index.html;
            limit_req zone=one nodelay;
      }

      ########## START BAIKAL CONF
      location  /baikal {
            charset utf8;
            alias /var/www/baikal/html;
            index index.php;
            error_log /var/log/nginx/e.log debug;

            rewrite ^(/baikal)(/.?.php)(/.)?$ /...$document_root/...$1/...$2/...$3 last;
            rewrite ^/baikal/.well-known/caldav /cal.php redirect;
            rewrite ^/baikal/.well-known/carddav /card.php redirect;

            location ~ \.php$ {
                  fastcgi_split_path_info ^(.+?\.php)(/.*)?$;
                  fastcgi_pass unix:/var/run/php5-fpm.sock;
                  fastcgi_index index.php;
                  include fastcgi_params;
            }   

            location ~* /baikal/(.ht|Core|Specific) {
                  deny all;
                  return 404;
            }

      }

      #This part is copy-paste from the previous thread, I have no idea what's happening here.
      location /... {
            internal;
            autoindex off;
            location ~ ^/\.\.\.(?<p_doc_root>.*)/\.\.\.(?<p_prefix>.*)/\.\.\.(?<p_script>.*\.php)/\.\.\.(?<p_pathinfo>.*)$ {
                        fastcgi_pass unix:/var/run/php5-fpm.sock;
                        fastcgi_index index.php;
                        include fastcgi_params;
                        fastcgi_param SCRIPT_FILENAME $p_doc_root$p_script;
                        fastcgi_param SCRIPT_NAME     $p_prefix$p_script;
                        fastcgi_param REQUEST_URI     $p_prefix$p_script$p_pathinfo$is_args$query_string;
                        fastcgi_param DOCUMENT_URI    $p_prefix$p_script$p_pathinfo;
                        fastcgi_param DOCUMENT_ROOT   $p_doc_root;
                        fastcgi_param PATH_INFO       $p_pathinfo if_not_empty;
            }
      }
      ########## END BAIKAL CONF

}
fberke commented 9 years ago

Hello, I am also unable to get Baikal to run with NGINX. I have tried both, the flat package in a subdirectory, and the regular package on a subdomain. With both, I get the calendar to work with almost no effort, but the addressbooks insist on giving me a 404 during PROPFIND. I am using the current mainline version of NGINX, which I compile myself on my RPi running Raspbian. The connection to my server is SSL-secured, but I've tried with an unsecured http connection as well, and the error persists. What's driving me mad is that with Apache it worked just out of the box - I have tried that some time ago with a Ubuntu Server 12.04 in VirtualBox. So I suspect, that it is a configuration issue with NGINX, but after having tried numerous solutions an how-tos I found on the web, I am stuck. Here's my 'nginx -V':

nginx version: nginx/1.9.1
built by gcc 4.6.3 (Debian 4.6.3-14+rpi1) 
built with OpenSSL 1.0.1e 11 Feb 2013
TLS SNI support enabled
configure arguments:
 --with-cc-opt='-I /home/pi/build/staticlibssl/include -I/usr/include'
 --with-ld-opt='-L /home/pi/build/staticlibssl/lib -Wl,-rpath -lssl -lcrypto -ldl -lz'
 --sbin-path=/usr/sbin/nginx
 --conf-path=/etc/nginx/nginx.conf
 --pid-path=/var/run/nginx.pid
 --error-log-path=/var/log/nginx/error.log
 --http-log-path=/var/log/nginx/access.log
 --with-pcre=/home/pi/build/pcre-8.36
 --with-http_ssl_module
 --with-http_spdy_module
 --with-http_dav_module
 --add-module=/home/pi/build/nginx-dav-ext-module-master
 --with-file-aio
 --with-ipv6
 --with-http_gzip_static_module
 --with-http_stub_status_module
 --with-http_geoip_module
 --with-http_realip_module
 --with-http_sub_module
 --with-debug
 --without-mail_pop3_module
 --without-mail_smtp_module
 --without-mail_imap_module

Here's my nginx baikal config file:

server {
    listen       443 ssl;
    server_name  sub.domain.tld;

    # New StartSSL verified key
        ssl_certificate /etc/ssl/certs/unified.crt;
        ssl_certificate_key /etc/ssl/certs/my-private-decrypted.key;

    root  /var/www/baikal/html;
    index index.php;

    dav_methods     PUT DELETE MKCOL COPY MOVE;
        dav_ext_methods PROPFIND OPTIONS;

    rewrite ^/.well-known/caldav /cal.php redirect;
    rewrite ^/.well-known/carddav /card.php redirect;

    charset utf-8;

    location ~ /(\.ht|Core|Specific) {
        deny all;
        return 404;
    }

  location ~ [^/]\.php(/|$) {
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                if (!-f $document_root$fastcgi_script_name) {
                        return 404;
                }
        fastcgi_pass php;
        fastcgi_index index.php;
                include fastcgi_params;
        }

error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /var/www/nginx-default;
    }
}

server {
        listen                  80;
        server_name             sub.domain.tld;
        return                  301 https://sub.domain.tld$request_uri;
}

Here's the nginx access.log output:

100.200.100.200 - fberke [12/Jun/2015:12:15:05 +0200] "PROPFIND /card.php/addressbooks/fberke/privat/ HTTP/1.1" 404 313 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 Lightning/3.3.2"

And here's nginx' error.log on debug level: https://gist.github.com/fberke/f09cbac87c69bca7ab37

spidernik84 commented 9 years ago

Hello, I'd like to chime in here. I'm in the very same situation, not being able to get baikal to work in a subdir with nginx. Is there a working, simple nginx configuration anyone can provide? I have no sufficient knowledge of nginx to reach a solution, unfortunately. Thanks

evert commented 8 years ago

@check0104 :

If I change the caldav-base uri in the system settings to PROJECT_BASEURI . "groupdav/cal.php/", I get the following error messag, whenever I try to load https://ip/baikal/cal.php in my webbrowser

Don't do this =) If you change the base uri, you also need to actually access the server using that uri. I would suggest just keeping the default.

@fberke

You absolutely MUST turn off this:

dav_methods     PUT DELETE MKCOL COPY MOVE;
dav_ext_methods PROPFIND OPTIONS;

Where did you even get that? If it's in our documentation somewhere we need to get rid of it. Turning on those settings with cause nginx to handle WebDAV methods and that's not what you want. Baikal itself is responsible for handling those methods and this setting will just cause nginx to intercept it and send responses for it instead.

@spidernik84 if you're still experiencing issues, please open a new ticket with a lot more information (baikal version, nginx config, which client you are using).

Since this ticket is a bit old I'm closing it, but if there are further issues/comments just comment here and I will reopen.

atripes commented 8 years ago

I had to compile nginx from source with --add-module=../nginx-dav-ext-module-master for PROPFIND to work as expected. Also php7.0 needs php7.0-mbstring to work on a fresh Ubuntu 16.10 install.

evert commented 8 years ago

@atrioom nginx's DAV module is absolutely not needed and should be disabled.

atripes commented 8 years ago

Hmm, I just tried it with disabled DAV modules and you are right. It works without the modules. I swear that my android CardDav Sync App did not connect (PROPFIND -> 405) and only did connect once I recompiled with the ext-dav addon...