一台独立的服务器是可以可以建立多个网站的,一个ip地址,一个端口

# 1,若开启虚拟主机,这个一定要有(IP:端口),找到 #NameVirtualHost *:80 修改成:
 NameVirtualHost 127.0.0.1:80  
 
# 2,修改<Directory "/var/www/html">  改成 <Directory "/var/www"> 
 
# 3,增加网站
 
# 默认陷阱主机,禁止非法绑定,在www目录下面新建一个nosite目录
<VirtualHost 127.0.0.1:80>
    DocumentRoot /var/www/nosite
    ServerName 127.0.0.1
    <Location />
        Order Allow,Deny
        Deny from all
    </Location>
</VirtualHost>
 
# huanhang.com
<VirtualHost 127.0.0.1:80>
    DocumentRoot /var/www/huanhang.com
    ServerName www.huanhang.com
    ServerAlias huanhang.com www.huanhang.com
    <Directory "/var/www/huanhang.com">
        Options -Indexes FollowSymLinks
        AllowOverride all
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog "/log/httpd/huanhang.com-error.log"
    CustomLog "/log/httpd/access/huanhang.com-access.log" common
</VirtualHost>
 
# blog.huanhang.com
<VirtualHost 127.0.0.1:80>
    DocumentRoot /var/www/blog.huanhang.com
    ServerName blog.huanhang.com
    ServerAlias blog.huanhang.com
    <Directory "/var/www/blog.huanhang.com">
        Options -Indexes FollowSymLinks
        AllowOverride all
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog "/log/httpd/blog.huanhang.com-error.log"
    CustomLog "/log/httpd/access/blog.huanhang.com-access.log" common
</VirtualHost>
 
  
# 4,重新启动 Apache
# 现在访问:huanhang.com 和 blog.huanhang.com 就会显示不同的内容了。
 
# 注意事项:
# 请将上面的127.0.0.1替换成你服务器的IP,和其他对应的替换成自己的就可以了。

  

原文地址:https://www.cnblogs.com/xigua1hao/p/5353497.html