NGINX Unit
v. 1.32.1

NextCloud§

To run the NextCloud share and collaboration platform using Unit:

  1. Install Unit with a PHP language module.

  2. Install and configure NextCloud’s prerequisites.

  3. Install NextCloud’s core files. Here, we install it at /path/to/app/; use a real path in your configuration.

    Note

    Verify the resulting settings in /path/to/app/config/config.php; in particular, check the trusted domains to ensure the installation is accessible within your network:

    'trusted_domains' =>
    array (
      0 => 'localhost',
      1 => '*.example.com',
    ),
    
  4. Run the following command so Unit can access the application directory:

    # chown -R unit:unit /path/to/app/
    

    Note

    The unit:unit user-group pair is available only with official packages, Docker images, and some third-party repos. Otherwise, account names may differ; run the ps aux | grep unitd command to be sure.

    For further details, including permissions, see the security checklist.

  5. Next, put together the NextCloud configuration for Unit (use real values for share and root). The following is based on NextCloud’s own guide:

    {
        "listeners": {
            "*:80": {
                "pass": "routes"
            }
        },
    
        "routes": [
            {
                "match": {
                    "uri": [
                        "/build/*",
                        "/tests/*",
                        "/config/*",
                        "/lib/*",
                        "/3rdparty/*",
                        "/templates/*",
                        "/data/*",
                        "/.*",
                        "/autotest*",
                        "/occ*",
                        "/issue*",
                        "/indie*",
                        "/db_*",
                        "/console*"
                    ]
                },
    
                "action": {
                    "return": 404
                }
            },
            {
                "match": {
                    "uri": [
                        "/core/ajax/update.php*",
                        "/cron.php*",
                        "/index.php*",
                        "/ocm-provider*.php*",
                        "/ocs-provider*.php*",
                        "/ocs/v1.php*",
                        "/ocs/v2.php*",
                        "/public.php*",
                        "/remote.php*",
                        "/status.php*",
                        "/updater*.php*"
                    ]
                },
    
                "action": {
                    "pass": "applications/nextcloud/direct"
                }
            },
            {
                "match": {
                    "uri": "/ocm-provider*"
                },
    
                "action": {
                    "pass": "applications/nextcloud/ocm"
                }
            },
            {
                "match": {
                    "uri": "/ocs-provider*"
                },
    
                "action": {
                    "pass": "applications/nextcloud/ocs"
                }
            },
            {
                "match": {
                    "uri": "/updater*"
                },
    
                "action": {
                    "pass": "applications/nextcloud/updater"
                }
            },
            {
                "action": {
                    "share": "/path/to/app$uri",
                    "fallback": {
                        "pass": "applications/nextcloud/index"
                    }
                }
            }
        ],
    
        "applications": {
            "nextcloud": {
                "type": "php",
                "targets": {
                    "direct": {
                        "root": "/path/to/app/"
                    },
    
                    "index": {
                        "root": "/path/to/app/",
                        "script": "index.php"
                    },
    
                    "ocm": {
                        "root": "/path/to/app/ocm-provider/",
                        "script": "index.php"
                    },
    
                    "ocs": {
                        "root": "/path/to/app/ocs-provider/",
                        "script": "index.php"
                    },
    
                    "updater": {
                        "root": "/path/to/app/nextcloud/updater/",
                        "script": "index.php"
                    }
                }
            }
        }
    }
    

    Note

    The difference between the pass targets is their usage of the script setting:

    • The direct target runs the .php script from the URI or defaults to index.php if the URI omits it.
    • Other targets specify the script that Unit runs for any URIs the target receives.
  6. Upload the updated configuration. Assuming the JSON above was added to config.json:

    # curl -X PUT --data-binary @config.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config/
    

    Note

    The control socket path may vary; run unitd -h or see Startup and Shutdown for details.

  7. Adjust Unit’s max_body_size option to avoid potential issues with large file uploads, for example:

    # curl -X PUT -d '{"http":{"max_body_size": 2147483648}}' --unix-socket \
           /path/to/control.unit.sock http://localhost/config/settings
    

    After a successful update, browse to http://localhost and set up your NextCloud installation:

    NextCloud on Unit - Home Screen