Cannot connect IOS cardDAV/calDAV to Nextcloud

Nextcloud version (eg, 20.0.5): 24.0.1
Operating system and version (eg, Ubuntu 20.04): buntu 20.04
Apache or nginx version (eg, Apache 2.4.25): Nginx Proxy Manager 2.9.18
PHP version (eg, 7.4): Don’t know

The issue you are facing:
Cannot add nextcloud cardDAV and calDAV accounts to IOS.

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. https://docs.nextcloud.com/server/19/user_manual/pim/sync_ios.html
  2. Type in account info
  3. Unable to verify account information pops up

The output of your Nextcloud log in Admin > Logging:

Could not connect to appstore: cURL error 28: Failed to connect to apps.nextcloud.com port 443: Connection timed out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://apps.nextcloud.com/api/v1/apps.json

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

Sorry don't know how to get this from container

The output of your Apache/nginx/system log in /var/log/____:

This neither.

Settings of my npm:

You have to install a profile from Settings–>Mobile&Desktop. Then you will get the DAV functions.

EDIT:
No, the profile only mitigates the error, not solve it. You can see a Nextcloud server list in the calendar app, but my calendar on nextcloud is not present on that list, meaning it is not syncing. They only exist on nextcloud.

I am tired, simple answer:

The long answer for the whole process, hope this helps:

The problem is service discovery. If you use a reverse proxy (nginx proxy manager in my case), then you need to add a redirecting code.

  1. CalDav and CardDav iOS issues - #4 by v1001001p
  2. Include link to service discovery trouble shooting in iOS sync guide by networkException · Pull Request #8318 · nextcloud/documentation · GitHub
  3. https://docs.nextcloud.com/server/latest/admin_manual/issues/general_troubleshooting.html#service-discovery
  4. [CalDAV and Apple] Impossible to use CalDAV with Mac and iOS - #5 by drag
  5. https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html
  6. How to forward a location to another location? · Issue #2093 · NginxProxyManager/nginx-proxy-manager · GitHub
    Note: Browser redirection works, but for iOS clients you must set up the rules in the reverse proxy manager, otherwise it will just refuse to redirect for some reason. You can also just manually enter the redirected address if you need a quick fix.