Domain-Name-System
www 子域工作,未知原因
我有一個在 Apache2 上執行的域(來自 Strato)的虛擬伺服器。我唯一執行的站點具有以下虛擬主機:
<IfModule mod_ssl.c> <VirtualHost *:443> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost DocumentRoot /var/www/ # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf SSLCertificateFile /etc/letsencrypt/live/example.de/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.de/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf ServerName www.example.de </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet </IfModule>
和以下 apache2ctl -S:
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using xxx:xxx:xxx:xxxx::x. Set the 'ServerName' directive globally to suppress this message VirtualHost configuration: *:443 is a NameVirtualHost default server www.example.de (/etc/apache2/sites-enabled/vps.conf:2) port 443 namevhost www.example.de (/etc/apache2/sites-enabled/vps.conf:2) ServerRoot: "/etc/apache2" Main DocumentRoot: "/var/www/html" Main ErrorLog: "/var/log/apache2/error.log" Mutex ssl-stapling: using_defaults Mutex ssl-cache: using_defaults Mutex default: dir="/var/lock/apache2" mechanism=fcntl Mutex mpm-accept: using_defaults Mutex watchdog-callback: using_defaults Mutex rewrite-map: using_defaults PidFile: "/var/run/apache2/apache2.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG User: name="www-data" id=33 Group: name="www-data" id=33
畢竟我讀過我應該無法訪問 www.example.com 下的伺服器,因為我從未配置我的 DNS 條目以匹配該子域。我只有條目 example.de 並相應地設置了 IP。但它確實想在 www 下訪問我的伺服器,所以我將 ServerName 更改為 www.example.com。有趣的是,我可以在 www.example.com 和 example.com 下訪問我的伺服器,並且沒有證書錯誤。
這是我不明白的事情,但我願意理解,因為它困擾著我。
僅供參考:伺服器正在執行 owncloud。
謝謝!
這裡的關鍵是“預設伺服器”。Apache 總是有一個“預設伺服器”……它將接受主機名與定義的任何內容不匹配的任何站點的連接。
在這種情況下,正如您的日誌正確顯示的那樣:
default server www.example.de (/etc/apache2/sites-enabled/vps.conf:2)
www.example.de 是您的預設站點,任何不匹配的主機名都將發送到該站點。
我通常建議人們為預設站點設置一個標準的“404”站點,以告訴人們他們沒有到達正確的站點……然後確保正確定義了正確的域。