apache2 - Google Compute Engine Apache2 子域仍然指向主页而不是虚拟主机文件夹
问题描述
我一直在尝试在我的 Google Cloud Console 中创建子域,然后将它们定向到我的 /var/www 目录中的文件夹。
我创建了一个子域:
DNS Name: subdomain.example.com
Type: CNAME
TTL: 300
Data: example.com
我创建了一个文件夹
/var/www/子域
我创建了一个带有消息“子域!”的文件
/var/www/subdomain/index.html
之后,我复制了我的 000-default.conf
cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/subdomain.conf
我将新文件代码编辑为:
<VirtualHost *:80>
ServerAdmin webmaster@subdomain.example.com
DocumentRoot /var/www/subdomain
ServerName subdomain.example.com
ServerAlias www.subdomain.example.com
Redirect permanent / https://subdomain.example.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
然后我做了
sudo a2ensite subdomain.conf
sudo service apache2 restart
然而我的子域仍然指向文档根/var/www/html
我注意到当我这样做时systemctl reload apache2
会出错Failed to connect to bus: No such file or directory
我错过了一步还是需要添加其他内容?
解决方案
问题是配置了http但没有配置https。
必须添加到 default-ssl.conf
<VirtualHost *:443>
ServerName www.yoursite.com
DocumentRoot /var/www/site
SSLEngine on
SSLCertificateFile /path/to/www_yoursite_com.crt
SSLCertificateKeyFile /path/to/www_yoursite_com.key
SSLCertificateChainFile /path/to/DigiCertCA.crt
</VirtualHost>
推荐阅读
- android - Android Studio 4.1调试断点不起作用
- wordpress - 在 Woocommerce 中隐藏特定类别档案中的缺货产品
- azure-storage - Azure 存储帐户(经典)- 仅使用帐户名称访问?
- python - 如何用python提取excel中的上标或下标数据?
- python - 在 matplotlib 中用相同的空间绘制不同大小的散点图
- javascript - php 中新行的 jQuery 语法是什么?
- flutter - 连接到 PHP Json Flutter
- python - 怎么不是和!Python中的不同?
- mysql - 为什么当值大于一定位数时结果不同?
- java - 消息气泡自定义可绘制对象