gpt4 book ai didi

linux - Apache 虚拟主机配置

转载 作者:太空宇宙 更新时间:2023-11-04 05:23:20 26 4
gpt4 key购买 nike

我正在尝试设置两个虚拟主机(example.com.conf 和 test.com.conf):

<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

<VirtualHost *:80>
ServerAdmin admin@test.com
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/test.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

问题是,如果我在浏览器中访问本地主机,则会显示网站 www.example.com。如果我输入 localhost/test.com 则会出现未找到错误。我的目标应该是使用 localhost/example.com 和 localhost/test.com 来寻址两个网站。

最佳答案

听起来你可以使用ServerPath directive对于apache,在你的情况下,这样的事情应该有效:

<VirtualHost 127.0.0.1>
# primary vhost
DocumentRoot "/var/www/example.com"
RewriteEngine On
RewriteRule "." "/var/www/example.com/public_html"
# ...
</VirtualHost>

<VirtualHost 127.0.0.1>
DocumentRoot "/var/www/example.com/public_html"
ServerName localhost
ServerPath "/example/"
RewriteEngine On
RewriteRule "^(/sub1/.*)" "/var/www/example$1"
# ...
</VirtualHost>

<VirtualHost 127.0.0.1>
DocumentRoot "/var/www/test.com/public_html"
ServerName localhost
ServerPath "/test/"
RewriteEngine On
RewriteRule "^(/sub2/.*)" "/var/www/test$1"
# ...
</VirtualHost>

第一个虚拟主机将是本地主机默认为 example.com 页面。

关于linux - Apache 虚拟主机配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37624204/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com