Ubuntu
虛擬主機設置重定向請求到本地 IP 地址
我想讓一個在 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-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>
預設-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(問題可能來自這裡嗎?)
<?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!
Moodle 會準確地重定向您的配置方式:
$CFG->wwwroot = 'http://172.16.0.30/moodle';
將該行更改為正確的 URL:
$CFG->wwwroot = 'https://example.com/moodle';