我有两个项目- site_a和site_B -我希望将它们托管在运行Apache的Ubuntu服务器上。我对为它们设置单独的域不感兴趣。
除了每个项目的public/
目录之外,每个项目都包含我不想公开访问的文件,因此,我将项目存储在/home
而不是/var/www
中。
我试过在两个项目的.conf
文件中指定ServerName
,在apache2.conf
文件中指定<Directory>
,但不确定如何实现。目前,每当我在浏览器中访问{domain}/
时,都会显示site_a/public
的内容。
以下是我目前尝试的方法:
site_a.配置文件:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName localhost/site_a
DocumentRoot /home/site_a/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
site_B.配置文件:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName localhost/site_b
DocumentRoot /home/site_b/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
apache2.conf:
<Directory /home/site_a>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/site_b>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
1条答案
按热度按时间ia2d9nvy1#
由于您希望两个站点在同一个域上响应,因此您只能有1个VirtualHost。如果您只有1个VirtualHost,Apache就无法知道基于域的站点A和站点B是什么。
一个域,2个站点
按如下方式设置文件:
mkdir site_a
:在此处放置站点a的文件mkdir site_b
:在此放置站点B的文件一个域,2个端口
要查看站点a:http://example.com/
要查看站点B:http://example.com:81/