后台
我一直在使用一个Apache服务器,只有一个网站,这一直工作得很好。最近,我不得不在本地创建两个站点,我找到了this指南,展示了如何做到这一点。我还提到了this堆栈溢出问题,这也帮助了我很多。
我的问题是,当我访问我在/etc/hosts
中创建并在httpd-vhosts.conf
中配置的三个主机时,它不工作,当我试图在浏览器中访问它时,它说its-site.test refused to connect.
。
我试图通过引用this堆栈溢出问题来解决这个问题,这有助于我更好地理解配置,但它仍然不起作用,并导致同样的问题。
不用说,我对Apache非常陌生,所以我可能忽略了一些明显的东西。
我的设定
我有三个不同的网站,我想使用命名的虚拟主机在我的开发过程中访问浏览器。我不想使用一个本地主机和几个命名域,而是希望每个主机都是命名域:
- its-site.test
- its-cab.test
- its-gallery.test
Hosts文件
/etc/hosts
个
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 its-site.test
127.0.0.1 its-cab.test
127.0.0.1 its-gallery.test
字符串
httpd配置
/opt/homebrew/etc/httpd/httpd.conf
个
Listen 80
Include /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
ServerName localhost:80
# Also enabled PHP but not including the config here as it may not be relevant
型
vhosts配置
/opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
个
<VirtualHost *:80>
ServerName its-site.test
ServerAlias *.its-site.test
DocumentRoot "/Users/ciesinsg/Documents/Repositories/its-site/web"
<directory "/Users/ciesinsg/Documents/Repositories/its-site/web">
Require all granted
AllowOverride All
</directory>
</VirtualHost>
<VirtualHost *:80>
ServerName its-cab.test
ServerAlias *.its-cab.test
DocumentRoot "/Users/ciesinsg/Documents/Repositories/its-cab/web"
<directory "/Users/ciesinsg/Documents/Repositories/its-cab/web">
Require all granted
AllowOverride All
</directory>
</VirtualHost>
<VirtualHost *:80>
ServerName its-gallery.test
ServerAlias *.its-gallery.test
DocumentRoot "/Users/ciesinsg/Documents/Repositories/its-gallery/web"
<directory "/Users/ciesinsg/Documents/Repositories/its-gallery/web">
Require all granted
AllowOverride All
</directory>
</VirtualHost>
型
提问
有没有人看到我在这个配置中犯了什么错误,可以告诉我解决方案?
附加信息
- M1 MacBook Air
- 使用自制软件安装Apache和PHP
- ~~指向我的Drupal站点/Web文件夹~~
上一单站工作配置
如前所述,当我只服务于一个站点时,我的工作很好。我唯一的配置是httpd.conf
,没有配置/etc/hosts
或httpd-vhosts.conf
。我的httpd.conf
文件看起来像这样:
Listen 80
DocumentRoot "/Users/ciesinsg/Documents/Repositories/its-gallery/web"
<Directory "/Users/ciesinsg/Documents/Repositories/its-gallery/web">
# Also enabled PHP
型
我在配置VirtualHosts时删除了DocumentRoot
和<Directory>
。
1条答案
按热度按时间qvsjd97n1#
我使用以下解决方案解决了这个问题:
测试PHP
首先,我使用ping在
etc/hosts
中测试了我的配置:字符串
这证实了该网站是路由到正确的IP匹配我的配置。
检查虚拟主机
这是通过参考these文档并仔细检查我遵循的guide手动完成的。我不知道有任何测试来确认配置是否正常工作,但在阅读了一些关于虚拟主机的指南和文档后,我很有信心配置没有任何问题,问题一定在其他地方。
查看httpd.conf
这个配置是我默认列出的配置中最长的。因此,这是一个手动过程。我的解决方案涉及到打开
httpd-default.conf
,这是一个相邻的配置文件,它似乎具有httpd.conf
文件中的默认配置。在Apache的Homebrew安装中,它位于/opt/homebrew/etc/httpd/extra/
中,httpd.conf
文件也位于该位置。我将这两种配置并排进行了比较,并从早期的尝试中删除了我的配置。在我的例子中,我发现我不小心在
httpd.conf
文件和httpd-php.conf
文件中复制了我的PHP配置。我删除了所有的配置,并再次按照指南进行操作,确保我的Include
和LoadModule
语句被放置在相同的语句之后。在删除我的配置并更仔细地配置它之后,我在浏览器中测试了这些网站,它们都按预期工作。