【发布时间】:2020-11-20 11:25:04
【问题描述】:
我想以某种方式设置我的虚拟主机,这样我的项目就不会出现在 htdocs 文件夹中,并且我想使用子域来访问它们。因此,例如,与其去“/xampp/htdocs/myproject”内的“http://localhost/myproject”,我更愿意去“http://myproject.sites.local”将位于“/Users/myname/Projects/myproject”内。
我知道我必须转到 xampp 中“etc”文件夹中的 httpd.conf 并取消注释包含虚拟主机的行,然后完成。然后我去“/etc/hosts”文件添加“127.0.0.1 sites.local”,然后我的httpd-vhosts.conf文件中有这段代码:
<Directory "/Users/marioplantosar/Projects">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<Virtualhost *:80>
VirtualDocumentRoot "/Users/marioplantosar/Projects"
UseCanonicalName Off
</Virtualhost>
<Virtualhost *:80>
VirtualDocumentRoot "/Users/marioplantosar/Projects/%1"
ServerName sites.local
ServerAlias *.sites.local
UseCanonicalName Off
</Virtualhost>
我猜第一部分有效,因为如果我访问“http://sites.local”,它会打开 Projects 文件夹根目录(它只列出子文件夹,因为“Projects”文件夹内没有索引文件。但是其他部分不起作用,它只是抛出“ERR_NAME_NOT_RESOLVED”错误。所以我在ServerAlias中有通配符“*”,以便它捕获sites.local的每个子域,我使用“%1”打开相应的文件夹在“项目”文件夹中,但它只是不工作。最奇怪的部分是它工作了几个月,直到昨天,我不知道发生了什么,它突然停止工作。
【问题讨论】:
标签: apache xampp virtualhost hosts