I want to make an application running on apache2 (ubuntu) available over the internet. So i decided to setup virtual host after purchasing a SSL certificate. Everything works fine on my Local network.

When I visit (on local network), Everything works fine.

When I also visit example.com, I am served the default index.php from (/var/www/html)

But when I visit example.com/moodle over public internet, the browser redirects to (with error 404)

What am I doing wrong.



<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

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



<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin sa@xxx.com
                ServerName lms.xxx.com
                DocumentRoot /var/www/html 

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

                SSLEngine on

                SSLCertificateFile      /home/vlms/sslcert/cert.pem
                SSLCertificateKeyFile /home/vlms/sslcert/cert.key

                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                <Directory /var/www/html/>

                     Options +FollowSymlinks

                     AllowOverride All

                     Require all granted


moodle/config.php (could the problem be from here?)

<?php  // Moodle configuration file

global $CFG;
$CFG = new stdClass();

$CFG->dbtype    = 'mariadb';
$CFG->dblibrary = 'native';
$CFG->dbhost    = '';
$CFG->dbname    = 'xxx';
$CFG->dbuser    = 'xxx';
$CFG->dbpass    = 'xxx';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
  'dbpersist' => 0,
  'dbport' => '',
  'dbsocket' => '',
  'dbcollation' => 'utf8mb4_general_ci',

$CFG->wwwroot   = '';
$CFG->dataroot  = '/var/www/moodledata';
$CFG->admin     = 'xxx';

$CFG->directorypermissions = 0777;

require_once(__DIR__ . '/lib/setup.php');

// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!
  • 1
    There are no redirects there. It sounds like your redirect is coming from Moodle. – Michael Hampton Aug 18 '20 at 0:55
  • @MichaelHampton Thanks for your response, I edited the post. I added the moodle/config.php file, please see if you can figure out where i went wrong. Thanks – Jafar Kams Aug 18 '20 at 7:13

Moodle redirects you exactly how you configured it:

$CFG->wwwroot   = '';

Change that line to the proper URL:

$CFG->wwwroot   = 'https://example.com/moodle';
  • Thanks @GeraldSchneider . It works now. But I still get some error in console. Mixed Content: The page at 'lms.xxx.com/moodle' was loaded over HTTPS, but requested an insecure image ''. This content should also be served over HTTPS. Any Idea? – Jafar Kams Aug 18 '20 at 14:17
  • Check the developer tools of your browser which images are affected, find out where their URLs come frome and correct them. – Gerald Schneider Aug 18 '20 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.