Apache - 多个网站 - 允许访问顶级文件夹
我的 Apache2 服务器上设置了多个网站。目录结构如下:
/var/www/
/var/www/site1.com
/var/www/site2.com
设置“www.site1.com”的根文件夹为 /var/www/site1, “www.site2.com”具有根文件夹 /var/www/site2,并且 http://server_ip_address 具有根文件夹 /var/ www
但是,如果我输入 http://server_ip_address/site1.com,它将打开 site1.com。我不希望这种事发生。 (也就是说,只有输入正确的地址才能访问各个站点)。
请问这个配置方法是什么。 (如果您能提供有关多个网站目录结构最佳实践的提示,也会很有帮助)?
谢谢
太平绅士
I have multiple websites setup on my Apache2 server. The directory structure is as follows:
/var/www/
/var/www/site1.com
/var/www/site2.com
It is setup such that "www.site1.com" has root folder /var/www/site1, "www.site2.com" has root folder /var/www/site2, and http://server_ip_address has root folder /var/www
However, if I type http://server_ip_address/site1.com, it opens site1.com. I don't want this to happen. (That is, individual sites should be accessible only by typing the correct address).
What is the way to configure this. (Also it would be helpful if you could give tips on best practices for directory structures for multiple websites)?
thanks
JP
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
VirtualHost 指令可用于设置单独的 DocumentRoots每个站点名称。
另请查看此文档:
http://httpd.apache.org/docs/2.2/vhosts/name -based.html
The VirtualHost directive can be used to set individual DocumentRoots for each site name.
Have also a look at this document:
http://httpd.apache.org/docs/2.2/vhosts/name-based.html
在 Ubuntu 上配置多个网站
创建 apache 配置文件:
虚拟主机的最低配置:
创建根文件夹:
更改文件夹的权限:
在 /etc/hosts 中创建新记录
添加以下行:
在已启用站点中创建正确的符号链接:
重新启动 apache:
您必须对 site2.com、site3.com 等执行相同的操作...
Configure multiple websites on Ubuntu
Create apache configuration file:
Minimal configuration for the virtual host:
Create the root folder:
Change the permissions of the folder:
Create a new record in /etc/hosts
Add the following line:
Create a correct symlinks in sites-enabled:
Restart the apache:
You have to do the same with the site2.com, site3.com etc...