1

Any help would be greatly appreciated. I am stuck with this issue for a long time now.

Now here is the thing. I have on my ubuntu 16.04 server two vhosts, one for Nextcloud (https://mydomain.com/owncloud/) that works perfectly and one for my wordpress (https://mydomain.com/) that does not work. Each time I enter https://mydomain.com it returns https://mydomain.com:16501 and my web browser safari says it cannot connect to the server mydomain.com.

My wordpress used to work and I have no idea where this 16501 comes from.

I have basicaly three vhosts in sites-enabled...

000.default.conf

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

RewriteEngine on
RewriteCond %{SERVER_NAME} =mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

nextcloud.conf

<IfModule mod_ssl.c>
   <VirtualHost _default_:443>

     ServerAdmin mail@mymail.com
     ServerName mydomain.com
     DocumentRoot /var/www/html

Alias /nextcloud "/var/www/owncloud/"

<Directory /var/www/owncloud/>
  Options +FollowSymlinks
  AllowOverride All

 <IfModule mod_dav.c>
  Dav off
 </IfModule>

 SetEnv HOME /var/www/owncloud
 SetEnv HTTP_HOME /var/www/owncloud

</Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined 

     <IfModule mod_headers.c>
          Header always set Strict-Transport-Security "max-age=15768000; preload"
     </IfModule>

SSLCertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf


   </VirtualHost>
</IfModule>

wordpress.conf

<IfModule mod_ssl.c>
   <VirtualHost _default_:443>

     ServerAdmin mail@mymail.com
     ServerName mydomain.com
     ServerAlias www.mydomain.com
     DocumentRoot /var/www/html

<Directory /var/www/html/>
  AllowOverride All

</Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined 

SSLCertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf


   </VirtualHost>
</IfModule>

Thanks for your help!

Edwin
  • 129
  • What do your error logs say? /var/log/apache – Mark D Nov 15 '18 at 16:21
  • I have this in the log file... [Fri Nov 16 06:25:02.191539 2018] [mpm_prefork:notice] [pid 1360] AH00163: Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g configured -- resuming normal operations [Fri Nov 16 06:25:02.191556 2018] [core:notice] [pid 1360] AH00094: Command line: '/usr/sbin/apache2' – Edwin Nov 16 '18 at 10:36
  • Does your access log have log entries for when you attempt to visit each of the domains? If it does then the problem is probably somewhere within the application If it doesn't then and your error log doesn't accumulate entries then the problem is likely with actually hitting the urls in question (i.e.) dns. – Mark D Nov 17 '18 at 16:43
  • Thanks for your help Mark. In fact, when I tail /var/log/apache2/access.log, I don´t see any entries with my tries to visit my mydomain.com website, only with the mydomain.com/owncloud accesses. where should I look then??? – Edwin Nov 18 '18 at 10:27

1 Answers1

0

You are have two VirtualHost's with the same ServerName directive, so Apache can't threat this and uses only the first one. The first one is those defined in the file nextcloud.conf, because the letter 'n' is located before 'w' in the alphabet.

One way to solve this is to combine the content of nextcloud.conf and wordpress.conf and create one VirtualHost - you can name the new configuration file mydomain.com.conf, for example:

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>

        ServerAdmin mail@mymail.com
        ServerName mydomain.com      # Note along with mydomain.com your cert. file must
        ServerAlias www.mydomain.com # contain www.mydomain.com to use ServerAlias here

        DocumentRoot /var/www/html    
        <Directory /var/www/html/>
            AllowOverride All
        </Directory>

        Alias /nextcloud "/var/www/owncloud/"
        <Directory /var/www/owncloud/>

            Options +FollowSymlinks
            AllowOverride All

            <IfModule mod_dav.c>
                 Dav off
            </IfModule>

            SetEnv HOME /var/www/owncloud
            SetEnv HTTP_HOME /var/www/owncloud

            <IfModule mod_headers.c>
                Header always set Strict-Transport-Security "max-age=15768000; preload"
            </IfModule>

        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined 

        SSLCertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

    </VirtualHost>
</IfModule>

In this case you should be able to access the WordPress installation at https://mydomain.com and the ownCloud installation at https://mydomain.com/nextcloud. Don't forget to a2dissite the old conf files, a2ensite the new one and restart Apache.

Another way is to use different domain names (FQDN) for the booth VirtualHosts. For example mydomain.com for WordPress and www.mydomain.com (or cloud.mydomain.com) for ownCloud. In this case you do not need to use the directive Alias /nextcloud "/var/www/owncloud/" instead that you can use DocumentRoot /var/www/owncloud/, so you will be able to access your ownCloud directly at https://www.mydomain.com (respectively at https://clould.mydomain.com).

In addition: within the Apaches documentation you will be advised to do not use the rewrite engine when you can use more simple directives. Within your HTTP host definition you can use the Redirect directive as it is shown here. The only limitation of this approach is that you must create HTTP VirtualHost per FQDN.

pa4080
  • 29,831
  • I have followed your comment, @pa4080, but it hasn't help. I still can access https://mydomain.com/owncloud and when I try to access https://mydomain.com, my browsers read https://mydomain.com:16501 and say "can't connect to the server"... – Edwin Nov 20 '18 at 11:39
  • Hi, @Edwin, have you tried to flush the browser's cache or to use incognito session. – pa4080 Nov 20 '18 at 13:37
  • Yes I did!!! Incognito session and flushed cache. I tried everything... – Edwin Nov 20 '18 at 21:07