Apache配置多个项目公用80端口

  1. 打开Apache的配置文件httpd.conf,通常位于/etc/httpd/conf/httpd.conf/etc/apache2/httpd.conf

  2.  确保NameVirtualHost *:80指令被解注释(移除#),以启用基于域名的虚拟主机。

  3.  为每个网站添加<VirtualHost>配置块:

<VirtualHost *:80>
    ServerAdmin webmaster@example1.com
    DocumentRoot "/var/www/html/example1"
    ServerName www.example1.com
    ServerAlias example1.com
    ErrorLog "logs/example1.com-error_log"
    CustomLog "logs/example1.com-access_log" common
</VirtualHost>
 
<VirtualHost *:80>
    ServerAdmin webmaster@example2.com
    DocumentRoot "/var/www/html/example2"
    ServerName www.example2.com
    ServerAlias example2.com
    ErrorLog "logs/example2.com-error_log"
    CustomLog "logs/example2.com-access_log" common
</VirtualHost>

确保为每个网站指定正确的DocumentRoot(网站文件目录)、ServerName(主机名)和ServerAlias(别名)。

4、重启Apache。

posted @ 2024-06-15 11:51  love/coder  阅读(19)  评论(0编辑  收藏  举报