大网数据广告活动
服务器运维问答

Apache Virtual Hosts - Map different paths of the same domain (or IP) to different sites

· 52CE 我爱测

I'm running Apache/2.4.29 (Ubuntu). I have only one domain name. I would like to map different sites to different paths after the domain name. For example: mydomain.com/test001 maps to /var/www/test001/public mydomain.com/test002…

问题原文

原帖链接 · Roger 71 · CC BY-SA 4.0

I'm running Apache/2.4.29 (Ubuntu).
I have only one domain name.
I would like to map different sites to different paths after the domain name.

For example:

mydomain.com/test001 maps to /var/www/test001/public
mydomain.com/test002 maps to /var/www/test002/public

I've already tried many different virtual host configurations but none of them worked.
Could anyone please tell me the right syntax of the virtual host?

EDIT I've changed my configuration according to the answer given by @JoeSlav,
now this is my virtual host conf

<VirtualHost *:80>
    ServerName test06.com
    ServerAlias www.test06.com
    DocumentRoot /var/www/test06/public

    Alias /test03/ /var/www/test03/public
    Alias /test04/ /var/www/test04/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

When I ask for http://test06.com/test03/ I get the directory listing page. I can see my index page in the list but if try to click on it (or if write the complete path on the browser) I get this message:
"Not Found"
"The requested URL /test03/index.html was not found on this server"

Some additional information:
- /var/www/test06/public/index.html is correctly shown by the browser if I ask for test06.com;
- I'm mapping test06.com to my server ip through the hosts file.

已采纳解答

原帖链接 · Roger 71 · CC BY-SA 4.0

The answer given by JoeSlav was almost correct.
There has to be no trailing slash after the sub-path parameter.

This is the working configuration:

<VirtualHost *:80>
    ServerName test06.com
    ServerAlias www.test06.com
    DocumentRoot /var/www/test06/public

    Alias /test03 /var/www/test03/public
    Alias /test04 /var/www/test04/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-03-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。