Nextcloud in the webroot of nginx : how to add a sub-domain for other website?


My domain name points to the Nextcloud homepage and it’s perfect, everything works with nginx (config found on nextcloud):

I want to add a new service (kanboard) that will be placed in a different directory of the server.

Netcloud: mydomain.tld
Storage in: /var/www/nextcloud
New website : kanboard.mydomain.tld or/and mydomain.tld/kanboard
Storage in: /var/www/kanboard

I tried to add a “location” but index.php returns “file not found” and index.htm returns the nextcloud home page.

location /kanboard/ {
	root    /var/www/kanboard;
location ~ /kanboard/.+\.php$ {
	fastcgi_pass unix:/run/php/php7.3-fpm.sock;
	include fastcgi_params;
	#we are directly using the $request_filename as its a single php script
	fastcgi_param SCRIPT_FILENAME $request_filename;

Since the nginx file for netcloud.conf contains address redirects and rewrites that I don’t know what to do, can you tell me what might work?

Nextcloud version (eg, 20.0.5): 20.0.8
Operating system and version (eg, Ubuntu 20.04): debian 10.8
Apache or nginx version (eg, Apache 2.4.25): nginx 1.14.2
PHP version (eg, 7.4): PHP 7.3

You need to set up a new server with the server-section of nginx. My preferred way of doing this is to create a new file with the according directives in /path/to/nginx/sites-available and put a symlink pointing to that configuration file in /path/to/nginx/sites-enabled. After that the configuration can be tested with nginx -t and reloaded from nginx with nginx -s reload.

For further reading have a look at the nginx documentation: NGINX Docs | Creating NGINX Plus and NGINX Configuration Files

Thank you Bernie

it looks simple but each time I have the impression that the file […]/sites-enabled/nextcloud.conf takes the upper hand by rewriting the addresses

Assuming my address is
I want to be able to use

I have taken the example available on Nginx configuration — Nextcloud latest Administration Manual latest documentation as it is.
And I wish to draw inspiration from step 5 How to Install Kanboard on Ubuntu 18.04 - RoseHosting

Do I have to integrate everything in the nextcloud.conf file? Maybe with an alias?
Or is it possible to make two *.conf files so I don’t break everything in case of an update?

In the end it looks more complex than I expected.

If you have nextcloud running in a webroot of a domain (e.g.:, I would not recommend to install any other webservice the same webroot. I would recommend to use another subdomain (e.g.

The configuration of nginx is set together from different files and consists of blocks, which themselves can contain different blocks. Similar to an html document. Roughly this is what it needs to look like (also see the first link I posted below):

http {
    server {
        listen 80;
        location {
        location {
    server {
        listen 80:
        location {

All this starts in nginx/nginx.conf. The different enabled servers (symlinks in nginx/sites-enabled/... pointing to nginx/sites-available/... get included via an include directive in the http-section of nginx.conf.

You can see this tree, if you enter nginx -T, which tests the configuration and prints the complete configuration to standard output.

For getting what you want to achieve, you need to configure different server sections with listen and server_name directives, so that nginx knows which server configuration serves which request. Best way to do this is to create nginx/sites-available/ containing the server directive, containing a listen-, server_name-, root- and location-directives. According to what you exactly want, more directives might be needed. Then create a symlink pointing to that new configuration file in nginx/sites-enabled/. Then check, if the configuration is valid with nginx -t and load it with nginx -s reload.

I hope, I could give you a rough idea how nginx configuration works. I am sorry, I don’t have the time to guide you through a complete nginx configuration setup. For further reading I recommend:

Full example configuration nginx

Step-5: Setting up server blocks

Understanding nginx server and location block selection algorithms

If you read and understand those links, I am sure you will manage to configure nginx to serve and with the help of the nginx configuration examples given from nextcloud and rosehosting.

1 Like

Thanks again for your feedback

In fact, by using a sub-domain, the configuration is healthier and it worked the first time

1 Like