简体   繁体   English

Apache - 多个网站 - 允许访问顶级文件夹

[英]Apache - multiple websites - allow top folder access

I have multiple websites setup on my Apache2 server. 我在Apache2服务器上设置了多个网站。 The directory structure is as follows: 目录结构如下:

/var/www/ 在/ var / WWW /

/var/www/site1.com /var/www/site1.com

/var/www/site2.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 设置为“www.site1.com”具有根文件夹/ var / www / site1,“www.site2.com”具有根文件夹/ var / www / site2,并且http:// server_ip_address具有根文件夹/ var /万维网

However, if I type http://server_ip_address/site1.com , it opens site1.com. 但是,如果我输入http://server_ip_address/site1.com ,它会打开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 J.P

The VirtualHost directive can be used to set individual DocumentRoots for each site name. VirtualHost指令可用于为每个站点名称设置单个DocumentRoot。 Have also a look at this document: http://httpd.apache.org/docs/2.2/vhosts/name-based.html 另请查看此文档: http//httpd.apache.org/docs/2.2/vhosts/name-based.html

Configure multiple websites on Ubuntu 在Ubuntu上配置多个网站

Create apache configuration file: 创建apache配置文件:

sudo nano /etc/apache2/sites-available/site1.com

Minimal configuration for the virtual host: 虚拟主机的最小配置:

    <VirtualHost *:80>
         DocumentRoot /var/www/site1.com
         ServerName www.site1.com
         # Other directives here
    </VirtualHost>

Create the root folder: 创建根文件夹:

    sudo mkdir /var/www/site1.com

Change the permissions of the folder: 更改文件夹的权限:

    sudo chmod -R 775 /var/www/site1.com/

Create a new record in /etc/hosts 在/ etc / hosts中创建新记录

    sudo nano /etc/hosts

Add the following line: 添加以下行:

    127.0.0.1       www.site1.com

Create a correct symlinks in sites-enabled: 在已启用站点中创建正确的符号链接:

    sudo a2ensite site1.com

Restart the apache: 重启apache:

    sudo /etc/init.d/apache2 restart

You have to do the same with the site2.com, site3.com etc... 你必须对site2.com,site3.com等做同样的事情......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM