我有一个问题,我有一个主域名网站(例如示例.com和子域名.example.com)。example.com 安装了 WordPress,而子域名安装了 php 应用程序。我可以毫无问题地访问 WordPress,但是当我访问子域名.example.com它只显示 WordPress,当我打开subdomain.example.com/index.html它只是返回 404。
我的服务器运行在非常干净的 Ubuntu Server 22.04 上,运行 Apache2、MariaDB 和 php。我的 DNS 通过 Cloudflare 托管。我的 DNS 设置正确,包括 A 名称等。除了基本操作外,我并没有做太多事情
example.com vhost 文件:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/
ErrorLog ${APACHE_LOG_DIR}/020-wpvhost.error.log
CustomLog ${APACHE_LOG_DIR}/020-wpvhost.access.log combined
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
# curl https://ssl-config.mozilla.org/ffdhe2048.txt >> /path/to/signed_cert_and_intermediate_certs_and_dhparams
SSLCertificateFile /etc/apache2/ssl/example.com.pem
SSLCertificateKeyFile /etc/apache2/ssl/example.com.key
# enable HTTP/2, if available
Protocols h2 http/1.1
# HTTP Strict Transport Security (mod_headers is required) (63072000 seconds)
Header always set Strict-Transport-Security "max-age=63072000"
</VirtualHost>
# intermediate configuration
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AE>SSLHonorCipherOrder off
SSLSessionTickets off
SSLUseStapling On
SSLStaplingCache "shmcb:logs/ssl_stapling(32768)"
subdomain.example.com vhost 文件:
<VirtualHost *:80>
ServerName subdomain.example.com
DocumentRoot /var/www/mysite/public
ErrorLog ${APACHE_LOG_DIR}/dash.error.log
CustomLog ${APACHE_LOG_DIR}/dash.access.log combined
<Directory /var/www/mysite/public>
Options FollowSymLinks
ReWriteEngine On
AllowOverride All
</Directory>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
# curl https://ssl-config.mozilla.org/ffdhe2048.txt >> /path/to/signed_cert_and_intermediate_certs_and_dhparams
SSLCertificateFile /etc/apache2/ssl/example.com.pem
SSLCertificateKeyFile /etc/apache2/ssl/example.com.key
# enable HTTP/2, if available
Protocols h2 http/1.1
# HTTP Strict Transport Security (mod_headers is required) (63072000 seconds)
Header always set Strict-Transport-Security "max-age=63072000"
</VirtualHost>
# intermediate configuration
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AE>SSLHonorCipherOrder off
SSLSessionTickets off
SSLUseStapling On
SSLStaplingCache "shmcb:logs/ssl_stapling(32768)"
我不知道自己到底错在哪里。
答案1
看起来,在您的 SSLvhost
部分中,您没有ServerName
、ServerAlias
或DocumentRoot
指令。如果您的网站配置为重定向到 SSL,则只有在重定向到 SSL 后,您才会获得默认网站,而这显然是您的example.com
网站。