我想让一个在 apache2(ubuntu)上运行的应用程序在互联网上可用。所以我决定在购买 SSL 证书后设置虚拟主机。在我的本地网络上一切正常。
当我访问 172.16.2.28/moodle(在本地网络上)时,一切正常。
当我访问 example.com 时,我会从 (/var/www/html) 获得默认的 index.php
但是当我通过公共互联网访问 example.com/moodle 时,浏览器会重定向到 172.16.2.28/moodle(出现错误 404)
我究竟做错了什么。
-
000-默认.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
默认 SSL 配置文件
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin [email protected]
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(问题会不会出在这里?)
<?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!
答案1
Moodle 会按照您的配置准确重定向您:
$CFG->wwwroot = 'http://172.16.0.30/moodle';
将该行更改为正确的 URL:
$CFG->wwwroot = 'https://example.com/moodle';