如何为多个网站配置 apache,例如 <my_website_name>.localhost



我想在本地计算机上设置多个网站。我希望本地网络上的所有其他计算机都能够访问这些计算机。

所以我想映射不同的项目/www/html/<proj_web_root>

<proj_name>.localhost以便所有其他计算机都可以访问这些网站

<proj_name>.my_ip和我在当地喜欢<proj_name>.localhost

如何在/etc/apache2/sites-enabled文件和/etc/hosts中为每个网站配置此项

就个人而言,我会避免使用 .local 域作为共享组域。使用类似 .dev 的内容

在Apache中,您可以在VirtualHost中使用ServerName和ServerAlias指令,并重写规则来实现URL路由,例如

<VirtualHost *:80>
ServerName www.dev
ServerAlias sub.dev
DocumentRoot /www/html
RewriteRule ^(.*) %{HTTP_HOST}/$1
</VirtualHost>

您也可以明显地使用通配符别名。另存为 dev.conf in/etc/apache/sites-available.要激活工作:

a2enmod rewrite
a2ensite dev

我通常不赞成主机黑客,但如果您坚持,这只是向/etc/hosts 添加内容的情况

这种方法的一个问题是不能对主机名进行通配符。我建议使用 dnsmasq 之类的东西,因为您可以添加通配符条目。在你的/etc/dnsmasq.conf 中,你可以添加类似的东西(相应地更改 IP 地址):

address=/.dev/10.0.0.2
在所有情况下,请与您的/

etc/resolv.conf 联系以了解您的 dns 解析的优先级

相关内容

最新更新