ubuntu 14.04设置Apache虚拟主机的方法
linux  /  管理员 发布于 7年前   371
方案
在这个教程中,我会使用Ubuntu 14.04 32位 LTS,并搭建2个测试网站分别命名为“unixmen1.local” 和 “unixmen2.local”.我的测试机分别为192.168.1.250/24和server.unixmen.local。你可以根据你的需要更改虚拟域名。
安装Apache网站服务器
安装apache服务器之前,我们来更新一下我们的Ubuntu服务器:
sudo apt-get update然后,用下面命令来安装apache网络服务器:
sudo apt-get install apache2安装apache服务器之后,让我们通过这个URL http://你的服务器的IP地址/ 来测试网站服务器是否正常工作
保存并关闭文件。
同样的,添加示例页到第二台虚拟主机。
sudo vi /var/www/unixmen2.local/public_html/index.html添加以下内容:
复制代码代码如下:
<html>
<head>
<title>www.unixmen2.local</title>
</head>
<body>
<h1>Welcome To Unixmen2.local website</h1>
</body>
</html>
保存并关闭文件。
5. 创建虚拟主机配置文件
默认情况下,apache有一个默认的虚拟主机文件叫000-default.conf。我们将会复制000-default.conf文件内容到我们新的虚拟主机配置文件中。
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/unixmen1.local.conf
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/unixmen2.local.conf确保虚拟主机配置文件末尾包含.conf扩展名。
现在,修改unximen1.local.conf文件以符合需求。
sudo vi /etc/apache2/sites-available/unixmen1.local.conf使相关的变化直接呈现在unixmen1站点中(译注:以“#”开头的注释行可以忽略。)。
复制代码代码如下:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#
ServerName www.example.com
ServerAdmin [email protected]
ServerName unixmen1.local
ServerAlias www.unixmen1.local
DocumentRoot /var/www/unixmen1.local/public_html
# Available loglevels: trace8, …, trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log comb
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
修改虚拟主机文件后,禁用默认的虚拟主机配置(000.default.conf),然后启用新的虚拟主机配置,如下所示。
复制代码代码如下:
sudo a2dissite 000-default.conf
sudo a2ensite unixmen1.local.conf
sudo a2ensite unixmen2.local.conf
最后,重启apache服务器。
sudo service apache2 restart
就是这样。现在,我们成功地配置了apach虚拟主机在我们的Ubuntu服务器上
测试虚拟主机
编辑/tc/hosts文件,
sudo vi /etc/hosts在文件末尾添加如下所示的虚拟域名。
192.168.1.250 unixmen1.local192.168.1.250 unixmen2.local保存并关闭文件。
打开你的浏览器并访问http://unixmen1.local 或 http://unixmen2.local。你将会看到我们之前创建的示例页。
Unixmen1.local 测试页:
Unixmen2.local 测试页
如果你想从你的远程系统访问这些站点,你需要在你的DNS服务器添加实际域名记录。不过,我没有真实的域名和DNS服务器,我只想通过我的本地系统测试,那么它刚好如我所愿地工作。
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号