!
也想出现在这里? 联系我们
广告位
当前位置:首页>教程分享>服务器教程>云服务器Apache配置虚拟主机实例

云服务器Apache配置虚拟主机实例

服务器租用后,安装Apache程序,如果是配置Apache虚拟主机,可以参考下面的教程。

1、基于ip地址的虚拟主机
代码如下:
Listen 80

    DocumentRoot /home/httpd/html1
    ServerName www.ok1.com
    ErrorLog /usr/local/apache/logs/error1_log
    CustomLog /usr/local/apache/logs/access1_log combined


    DocumentRoot /home/httpd/html2
    ServerName www.ok2.com
    ErrorLog /usr/local/apache/logs/error2_log
    CustomLog /usr/local/apache/logs/access2_log combined

2、基于IP 和多端口的虚拟主机配置
代码如下:
Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080


 DocumentRoot /www/example1-80
 ServerName www.example1.com

 DocumentRoot /www/example1-8080
 ServerName www.example1.com


 DocumentRoot /www/example2-80
 ServerName www.example1.org


 DocumentRoot /www/example2-8080
 ServerName www.example2.org

3、单个IP 地址的服务器上基于域名的虚拟主机配置
代码如下:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

DocumentRoot /www/example1
ServerName www.example1.com
ServerAlias example1.com. *.example1.com
# Other directives here


DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here

下面是实例:

1. 为了测试不同的域名,在Windows/System32/drivers/etc/下觅得hosts文件,在其中添加实验用的域名若干,如 -
代码如下:
127.0.0.1   test1.net
127.0.0.1   test2.net

如此,则在浏览器中输入该俩域名时,Windows将其解析为127.0.0.1本地地址。即,在浏览器中访问localhost, test1.net, test2.net均可访问XAMPP的欢迎页。

2. 在apache目录下建立目录,以放置您不同的网站。为保护XAMPP原有的htdocs中的欢迎页内容,实验另外建立了与htdocs平级的htdocs1目录,在其下建立了test1.net, test2.net两个子目录用以放置实验用的网站。如下 -
apache/htdocs1/test1.net - 放置test1.net网站内容
apache/htdocs1/test2.net - 放置test2.net网站内容

给TA打赏
共{{data.count}}人
人已打赏
服务器教程

云服务器远程桌面登录蓝屏怎么办?

2021-4-17 19:14:48

服务器教程

香港服务器Nginx日常维护命令有哪些?

2021-4-17 19:14:50

声明 本站上的部份代码及教程来源于互联网,仅供网友学习交流,若您喜欢本文可附上原文链接随意转载。无意侵害您的权益,请发送邮件至 [email protected] 或点击右侧 私信:吉吉国王 反馈,我们将尽快处理。
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
OneEase