Apache如何配置单个IP多个域名?

tomfriwel
  • 991

例如:
www.domain.com
blog.domain.com
api.domain.com
请问如何配置Apache?

回复
阅读 2.2k
1 个回答

需要配置httpd-vhosts.conf文件增加虚拟主机

<VirtualHost www.domain.com:80>
    ServerName www.domain.com 
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/www.domain.com"
    ErrorLog "/Applications/XAMPP/xamppfiles/htdocs/logs/www.domain.com-error_log.log"
    CustomLog "/Applications/XAMPP/xamppfiles/htdocs/logs/www.domain.com-access_log.log" common
    <Directory "/Applications/XAMPP/xamppfiles/htdocs/www.domain.com">
        Options Indexes FollowSymLinks Includes execCGI
        Order Deny,Allow
        Allow from all
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost blog.domain.com:80>
    ServerName blog.domain.com 
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/blog.domain.com"
    ErrorLog "/Applications/XAMPP/xamppfiles/htdocs/logs/blog.domain.com-error_log.log"
    CustomLog "/Applications/XAMPP/xamppfiles/htdocs/logs/blog.domain.com-access_log.log" common
    <Directory "/Applications/XAMPP/xamppfiles/htdocs/blog.domain.com">
        Options Indexes FollowSymLinks Includes execCGI
        Order Deny,Allow
        Allow from all
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost api.domain.com:80>
    ServerName api.domain.com 
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/api.domain.com"
    ErrorLog "/Applications/XAMPP/xamppfiles/htdocs/logs/api.domain.com-error_log.log"
    CustomLog "/Applications/XAMPP/xamppfiles/htdocs/logs/api.domain.com-access_log.log" common
    <Directory "/Applications/XAMPP/xamppfiles/htdocs/api.domain.com">
        Options Indexes FollowSymLinks Includes execCGI
        Order Deny,Allow
        Allow from all
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

具体路径根据你自己的路径配置。
希望能帮到你

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏