Multiple websites on same web server as nextcloud

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 20.0.5): 21.0.9
Operating system and version (eg, Ubuntu 20.04): debian 10.12
Apache or nginx version (eg, Apache 2.4.25): 2.4.38
PHP version (eg, 7.4): 7.3.31-1~deb10u1

The issue you are facing:
Trying to setup additional website on same server nextcloud was installed on. Nextcloud working ok but additional website setup point to nextcloud site.

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

Steps to replicate it:

  1. Enter url to goto additional website setup: http://site1.dname.com . Points to nextcloud login page. Used Brave browser.
  2. Try on different browser (firefox) same.
  3. Try on phone same. Try using curl, same.

The output of your Nextcloud log in Admin > Logging:

Not sure how to get this

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

<?php
$CONFIG = array (
  'passwordsalt' => 'salt',
  'secret' => 'secret',
  'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => 'ncloud.dname.com',
  ),
  'datadirectory' => '/var/www/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '21.0.9.1',
  'overwrite.cli.url' => 'http://localhost',
  'dbname' => 'dbname',
  'dbhost' => 'dbhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'dbuser',
  'dbpassword' => 'dbpass',
  'installed' => true,
  'instanceid' => 'instance',
  'has_rebuilt_cache' => true,
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'updater.secret' => 'secret',);

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

[Fri May 06 00:00:01.078236 2022] [mpm_prefork:notice] [pid 3683] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Fri May 06 00:00:01.078303 2022] [core:notice] [pid 3683] AH00094: Command line: '/usr/sbin/apache2'
[Fri May 06 00:17:50.361504 2022] [mpm_prefork:notice] [pid 3683] AH00173: SIGHUP received.  Attempting to restart
[Fri May 06 00:17:50.439744 2022] [mpm_prefork:notice] [pid 3683] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Fri May 06 00:17:50.439795 2022] [core:notice] [pid 3683] AH00094: Command line: '/usr/sbin/apache2'
[Fri May 06 00:23:50.409963 2022] [mpm_prefork:notice] [pid 3683] AH00169: caught SIGTERM, shutting down
[Fri May 06 00:23:50.566424 2022] [mpm_prefork:notice] [pid 6066] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Fri May 06 00:23:50.566530 2022] [core:notice] [pid 6066] AH00094: Command line: '/usr/sbin/apache2'
[Fri May 06 02:37:44.989331 2022] [mpm_prefork:notice] [pid 6066] AH00169: caught SIGTERM, shutting down
[Fri May 06 02:37:45.174764 2022] [mpm_prefork:notice] [pid 8929] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Fri May 06 02:37:45.174920 2022] [core:notice] [pid 8929] AH00094: Command line: '/usr/sbin/apache2'
[Fri May 06 02:41:13.161267 2022] [mpm_prefork:notice] [pid 8929] AH00169: caught SIGTERM, shutting down
[Fri May 06 02:41:13.323527 2022] [mpm_prefork:notice] [pid 9135] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Fri May 06 02:41:13.323665 2022] [core:notice] [pid 9135] AH00094: Command line: '/usr/sbin/apache2'
[Fri May 06 03:04:57.483062 2022] [mpm_prefork:notice] [pid 9135] AH00171: Graceful restart requested, doing restart
[Fri May 06 03:04:57.783327 2022] [mpm_prefork:notice] [pid 9135] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Fri May 06 03:04:57.783355 2022] [core:notice] [pid 9135] AH00094: Command line: '/usr/sbin/apache2'
[Fri May 06 03:05:08.253149 2022] [mpm_prefork:notice] [pid 9135] AH00169: caught SIGTERM, shutting down
[Fri May 06 02:41:13.161267 2022] [mpm_prefork:notice] [pid 8929] AH00169: caught SIGTERM, shutting down
[Fri May 06 02:41:13.323527 2022] [mpm_prefork:notice] [pid 9135] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Fri May 06 02:41:13.323665 2022] [core:notice] [pid 9135] AH00094: Command line: '/usr/sbin/apache2'
[Fri May 06 03:04:57.483062 2022] [mpm_prefork:notice] [pid 9135] AH00171: Graceful restart requested, doing restart
[Fri May 06 03:04:57.783327 2022] [mpm_prefork:notice] [pid 9135] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Fri May 06 03:04:57.783355 2022] [core:notice] [pid 9135] AH00094: Command line: '/usr/sbin/apache2'
[Fri May 06 03:05:08.253149 2022] [mpm_prefork:notice] [pid 9135] AH00169: caught SIGTERM, shutting down
[Fri May 06 03:05:08.446439 2022] [mpm_prefork:notice] [pid 9486] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Fri May 06 03:05:08.446547 2022] [core:notice] [pid 9486] AH00094: Command line: '/usr/sbin/apache2'
[Fri May 06 11:28:11.291075 2022] [negotiation:error] [pid 9568] [client 45.134.144.140:34440] AH00687: Negotiation: discovered file(s) matching request: /var/www/nextcloud/remote (None could be negotiated).
[Fri May 06 13:47:55.931201 2022] [mpm_prefork:notice] [pid 9486] AH00171: Graceful restart requested, doing restart
[Fri May 06 13:47:56.161787 2022] [mpm_prefork:notice] [pid 9486] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Fri May 06 13:47:56.161820 2022] [core:notice] [pid 9486] AH00094: Command line: '/usr/sbin/apache2'
[Fri May 06 13:48:15.644269 2022] [mpm_prefork:notice] [pid 9486] AH00169: caught SIGTERM, shutting down
[Fri May 06 13:48:15.770027 2022] [mpm_prefork:notice] [pid 22197] AH00163: Apache/2.4.38 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Fri May 06 13:48:15.770112 2022] [core:notice] [pid 22197] AH00094: Command line: '/usr/sbin/apache2'
[Fri May 06 15:01:13.111594 2022] [access_compat:error] [pid 22200] [client 98.193.122.234:51987] AH01797: client denied by server configuration: /var/www/nextcloud/data/.ocdata

PASTE HERE


Output errors in nextcloud.log in /var/www/ or as admin user in top right menu, filtering for errors. Use a pastebin service if necessary.

no error could be found filtering for keyword error

You’ll want to use containers (Docker, etc.) or Virtual Machines to handle this. It is so much easier. So very much easier, whether it is 3 services or 30. My .02 :wink:

Sorry but this has nothing do do with Nextcloud and there are plenty of guides out there how you can configure multiple VirtialHosts in Apache in order to host multiple sites with multiple domains or subdomains…

This should cover the basics: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04

It’s written for Ubuntu but it works exactley the same on Debian.

1 Like

Adding more info for problem.
contents of /etc/apache2/sites-enabled/othersite.conf

<VirtualHost *:80>
     ServerAdmin notroot@localhost.com
     ServerName othersite.dname.com
     DocumentRoot /var/www/othersite/public_html/
     ErrorLog /var/www/othersite/logs/error.log
     CustomLog /var/www/othersite/logs/access.log combined
</VirtualHost>

contents of nextcloud conf file in enabled:

Alias / "/var/www/nextcloud/"
<Directory /var/www/nextcloud/>
  Options +FollowSymlinks
  AllowOverride All
<IfModule mod_dav.c>
  Dav off
</IfModule>
SetEnv HOME /var/www/nextcloud
SetEnv HTTP_HOME /var/www/nextcloud
</Directory>

<VirtualHost *:80>
  ServerName nextcloud.dname.com
  ServerAdmin admin@localhost.com
  DocumentRoot /var/www/nextcloud
  <directory /var/www/nextcloud>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews
    SetEnv HOME /var/www/nextcloud
    SetEnv HTTP_HOME /var/www/nextcloud
  </directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =nextcloud.dname.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Output of apache2 -S:

notroot@dname:~$ sudo apachectl -S
AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/ports.conf:1
VirtualHost configuration:
*:443                  nextcloud.dname.com (/etc/apache2/sites-enabled/nextcloud-le-ssl.conf:2)
*:80                   is a NameVirtualHost
         default server othersite.dname.com (/etc/apache2/sites-enabled/othersite.conf:2)
         port 80 namevhost othersite.dname.com (/etc/apache2/sites-enabled/othersite.conf:2)
         port 80 namevhost othersite.dname.com (/etc/apache2/sites-enabled/nextcloud.conf:13)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

header info from curl request:

notroot@dname:~$ curl -s -D headers.txt -o /dev/null http://othersite.dname.com
notroot@dname:~$ less headers.txt
HTTP/1.1 302 Found
Date: Fri, 06 May 2022 16:16:57 GMT
Server: Apache/2.4.38 (Debian)
Referrer-Policy: no-referrer
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Robots-Tag: none
X-XSS-Protection: 1; mode=block
Set-Cookie: ocsk6whwcglg=csfnd5l56vvrh2qfdr6fnc8ujd; path=/; HttpOnly; SameSite=Lax
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: oc_sessionPassphrase=B9SOCOy8ayQZmY30Ji62Ulh%2BPJObvtV0bQcrZDXr3KB1q%2B53RkGWmXxRlTmyarFo9lOJ3827nDyebzSRIbcFXAhfapa92IzNXm08X6zY4IY5FpQ9UN%2FXbFk8ws8kIjBm; path=/; HttpOnly; SameSite=Lax
Set-Cookie: ocsk6whwcglg=61o1ajah6p0hnul0en2btt061u; path=/; HttpOnly; SameSite=Lax
Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-ajBkODRuZlFhS0tSUnZPbVhtM0dXbUY0SmF5SUZBWUlyNXFFOUwrOEFMQT06eFNNYXBFK3FLWlB5QkxUY0tpZVdIQ01QYXRYU1lYNWMzL2l3cDhyTWJkaz0='; style-src 'self' 'unsafe-inline'; frame-src *; img-src * data: blob:; font-src 'self' data:; media-src *; connect-src *; object-src 'none'; base-uri 'self';
Set-Cookie: nc_sameSiteCookielax=true; path=/; httponly;expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=lax
Set-Cookie: nc_sameSiteCookiestrict=true; path=/; httponly;expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=strict
Location: http://othersite.dname.com/index.php/login
Content-Length: 0
Content-Type: text/html; charset=UTF-8

The curl header output has the ‘othersite’ in the location:

Location: http://othersite.dname.com/index.php/login

The virtual hosts are using the same IP and the dns seems to be routing to that IP ok. It ‘seems’ to be a php setting that I’m not familiar with that maybe? redirecting to nextcloud? I don’t have any php or any other processing lang setup for the other site. Just serving static html files.

output of folder permissions

ls -l /var/www/
total 12
drwxr-xr-x  2 root     root     4096 Feb 27  2021 html
drwxr-xr-x  4 www-data www-data 4096 May  5 21:14 othersite
drwxr-xr-x 14 www-data www-data 4096 May  5 18:48 nextcloud

Restarted apache, reloaded configs manually… Used different browsers on different devices. All times goes to nextcloud site’s login. Does not go to othersite’s index.html

notroot@dname:~$ ls -l /var/www/othersite/public_html/
total 12
lrwxrwxrwx 1 www-data www-data   42 May  5 21:20 index.html -> /var/www/othersite/public_html/wordle.html
-rw-r--r-- 1 www-data www-data 9725 May  5 21:19 wordle.html

Why is there stuff outside the VirtualHost section and whats the Alias directive for?

If you put lines above the VirtualHost section, they got processed first. Apache processes the files in sites-enabled in aphanumeric order and then the lines in them from top to bottom. In your case the first line in the first file is Alias / "/var/www/nextcloud/", so every request will always go there…

Thanks for the feedback… I’ll try commenting out that line to see what happens.

It worked! I commented out that line and reloaded config and restarted apache. Pages from 2nd site started serving.

Thanks for your help.

That was not put in by me. It was either setup during the default deployment of the nextcloud linode VM or during one of the nextcloud updates. Not sure which so I didn’t feel confident enough to alter it unless using built in mechanisms/scripts in nextcloud. Is there anything else odd you see in the nextcould.conf that seems odd? Let me know. I’m hoping the comments I manually put in will not affect nextclouds scripts and tools for updating and or altering nextcloud.

1 Like

I don’t know the Linode install scripts. But that’s a general problem with appliances and one-click install soutions. They may work fine as long as you use them as intended, but are often not the best solotion, if you want to change or add things manually afterwards…

Anyways… Glad it worked out :slight_smile: