On my new iPhone, I switched on the most important business functions: email (IMAP), and synchronization of contacts and en calendar. These services are being provided by my own servers.
For the synchronization of contacts, the CardDAV-protocol is used. For the calendar, a similar protocol called CalDav is in use. Baïkal is the server side software that facilitates this, and it uses the Nginx web server. Recent versions of iOS support IMAP, CardDAV and CalDAV. My laptop synchronizes this data with the same server, using the same protocols.
Setup of email and contacts was quickly done on the iPhone. Calendar synchronization did not work at the first attempt. Reason for a bit of investigation.
When searching the web for keywords iOS and Baïkal, a number of specific problem reports came up. To enable access to a properly functioning Baïkal-server from iOS, a few specific settings have to be made in the web server. When contacting the Baïkal-server, iOS uses a default path, something like https://my.server.com/baikal/.well-known/caldav. For this, a redirect-rule must be set up in the web server, causing the iPhone’s request to be redirected to the correct address.
Most of the documentation for Baïkal does not assume Nginx is the web server. A separate issue is that it is not always clear where exactly the redirect rules must be implemented. Options:
- In the root folder of the website controlled by Nginx, a folder called .well-known must exist. In that folder, a file named .htaccess must exist which contains (Nginx specific) redirect rules. This did not cause a redirect upon request by iOS.
- In the base configuration of Nginx. Changing this session led to a redirect of the iPhone’s request to the right url.
Example of redirect rules for Nginx in the .htaccess file:
rewrite ^/.well-known/carddav$ /card.php;
rewrite ^/.well-known/caldav$ /cal.php;
Example of redirect rules in the server block of file /etc/nginx/nginx.conf:
server {
listen 443;
server_name my.server.com;
root /var/www/baikal/html;
index index.php;
rewrite ^/.well-known/caldav /dav.php redirect;
rewrite ^/.well-known/carddav /dav.php redirect;
charset utf-8;
After making this change, the iPhone’s calendar still did not synchronize. When entering the Baïkal server address, iOS validates a number of things, and decides that no calendar can be found. In the access logs of the Nginx server, the incoming requests are visible. The last request all cause a http 405 error (method not allowed).
iOS asks the CalDAV server many different questions, some of which Baïkal appears not to support. Errors like this can therefore not completely be avoided, even when synchronization works. However, from the iPhone, the calendar could still not be synchronized.
I noticed that configuration of synchronization of contacts on the iPhone had not been problematic at all. An analysis:
- The default url expected by the Baïkal-server for the contacts is https://my.server.com/baikal/card.php/addressbooks/erwin/default/
- iOS had changed it (and still working) into https://my.server.com/baikal/card.php/principals/erwin
- When setting up calendar synchronization, iOS expects https://my.server.com, and asks for more information at https://my.server.com/baikal/.well-known/caldav.
- This leads to a redirect to https://my.server.com/baikal/cal.php/addressbooks/erwin/default/ which causes only error messages.
- This is why I entered as the address for calendar synchronization on iOS: https://my.server.com/baikal/cal.php/principals/erwin. And this works.
So, for synchronization of contacts and calendar on iOS using a Baïkal-server running on Nginx:
- The redirect rules (for iOS) must be correctly applied in Nginx, so in its base configuration.
- The url’s that must be entered into iOS for connecting with Baïkal are different from what other Baïkal-clients use.