【转】让Moodle支持多个域名
默认情况下,moodle仅能绑定一个域名。但是由于学校网络分内网和外网,总希望如果是外网访问的,用外网的域名,用内网访问的,就转到内网的ip。这样访问的速度会更快一些,也减低对防火墙的压力。尤其是当外网ip不够用,用外网ip的非80端口映射内网ip的80端口时,让moodle支持多个域名是很有必要的。
如我校的这个案例:内网ip10.1.2.60,用80端口;外网ip不够用,只好将218.75.25.143的8080端口给映射过来。我试着自己修改根目录下的config.php文件。虽然我对php不是很熟悉,但是这几句简单的代码还是能轻易写出来的。核心的代码如下:
if($_SERVER['HTTP_HOST'] == "10.1.2.60"){
$CFG->wwwroot = 'http://10.1.2.60';}
else{
$CFG->wwwroot = 'http://218.75.25.143:8080';}
附:config.php文件。
<?php /// Moodle Configuration File
unset($CFG);
$CFG->dbtype = 'mysql';
$CFG->dbhost = 'localhost';
$CFG->dbname = 'moodle';
$CFG->dbuser = 'root';
$CFG->dbpass = 'wzms_mysql';
$CFG->dbpersist = false;
$CFG->prefix = 'mdl_';
if($_SERVER['HTTP_HOST'] == "10.1.2.60"){
$CFG->wwwroot = 'http://10.1.2.60';}
else{
$CFG->wwwroot = 'http://218.75.25.143:8080';}
$CFG->dirroot = '/var/www/html';
$CFG->dataroot = '/var/www/moodledata';
$CFG->admin = 'admin';
$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode
$CFG->unicodecleanfilename = true; //中文支持
require_once("$CFG->dirroot/lib/setup.php");
// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,
// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.
?>