0

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 172.16.2.28/moodle (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 172.16.2.28/moodle (with error 404)

What am I doing wrong.

-

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

  
</VirtualHost>

default-ssl.conf

<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
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>
                <Directory /var/www/html/>

                     Options +FollowSymlinks

                     AllowOverride All

                     Require all granted

                 </Directory>
    </VirtualHost>
</IfModule>

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

<?php  // Moodle configuration file

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

$CFG->dbtype    = 'mariadb';
$CFG->dblibrary = 'native';
$CFG->dbhost    = '172.16.0.30';
$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   = 'http://172.16.0.30/moodle';
$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!
2
  • 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
0

Moodle redirects you exactly how you configured it:

$CFG->wwwroot   = 'http://172.16.0.30/moodle';

Change that line to the proper URL:

$CFG->wwwroot   = 'https://example.com/moodle';
2
  • 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 '172.16.0.30/moodle/?redirect=0'. 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.