如何在Ubuntu中创建Apache virtualbox导入虚拟机Host虚拟机

求问个问题,主机如何访问ubuntu虚拟机里的多个virtualhost网站?【apache吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:2,424贴子:
求问个问题,主机如何访问ubuntu虚拟机里的多个virtualhost网站?收藏
用的windows8 vmware搭建的一个ubuntu虚拟机在ubuntu虚拟机里的apache服务器一共有两个网站一个是:127.0.0.1(apache的默认页面)另一个是:修改unbuntu虚拟机的hosts文件 加入 127.0.0.1 虚拟机访问显示正常那么,问题来了!将windows主机下的8000端口映射到虚拟机的80端口修改windows下的host文件加入 127.0.0.1 windows浏览器访问 出现的是apache的默认页面 不是test页面输入127.0.0.1:8000 出现的也是apache默认页面想问问怎么才能在windows主机上成功访问虚拟机上的 页面呢?附上虚拟机里apache2的virtualhost配置:&VirtualHost *:80&ServerAdmin karlso_DocumentRoot /home/karlsohelloworld/karltest/ErrorLog /home/karlsohelloworld/karlsotestlog/error.logCustomLog /home/karlsohelloworld/karlsotestlog/access.log combinedServerAlias &Directory /home/karlsohelloworld/karltest/&Options Indexes FollowSymLinksAllowOverride NoneRequire all granted&/Directory&&/VirtualHost&-----------------------------------------------------------------------------------求大神相助,纠结了好几天了不甚感激
有人吗??求帮忙谢谢
在虚拟机里的Ubuntu里,除了lo 127.0.0.1之外,应该会有 eth0 可能是类似 192.168.254.12 的IP,你要先从 windows8 的CMD看能不能ping 192.168.254.12;再看看从windows8上的chrome能不能访问 192.168.254.12?如果都能的话才有足够的条件处理端口映射的问题。不需要在Ubuntu里/etc/hosts做定义,hosts文件是客户端去访问主机名,看是那个IP用的,服务器端只需要在apache端配置就可以了。从你问题中的描述,从头到尾都是用127.0.0.1来互相映射,其实真的很怪,因为每台机器,实体或虚拟都有自己的127.0.0.1。你先看Ubuntu里终端器里ifconfig看看IP为何?再看看windows CMD里ipconfig /all IP为何?如果ubuntu的IP是192.168.254.12的话,你就需要在windows的c:\windows\system32\driver\etc\hosts的文档里指定192.168.254.12 www.test.com192.168.254.12 www.karltest.com从windows里访问www.test,karltest.com才会到虚拟机里的ubuntu。
登录百度帐号推荐应用中国领先的IT技术网站
51CTO旗下网站
在Ubuntu 14.04 LTS系统中设置Apache虚拟主机
虚拟主机常用于在一个单独的IP地址上提供多个域名的网站服务。如果有人想在单个VPS的单个IP地址运行多个网站,这是非常有用的。在这个教程中,让我告诉你如何设置在Ubuntu 14.04 LTS的Apache网页服务器设置虚拟主机。请注意,这个教程只针对Ubuntu14.04的32位版本。
作者:disylee译来源:| 10:40
虚拟主机常用于在一个单独的IP地址上提供多个域名的网站服务。如果有人想在单个VPS的单个IP地址运行多个网站,这是非常有用的。在这个教程中,让我告诉你如何设置在Ubuntu 14.04 LTS的Apache网页服务器设置虚拟主机。请注意,这个教程只针对Ubuntu14.04的32位版本。
我不保证它也可以工作在其它更低的Ubuntu版本或者Ubuntu衍生版本(虽然可能过程是类似的)。
在这个教程中,我会使用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地址/&来测试网站服务器是否正常工作
如你所见,apache服务器已经工作了。
设置虚拟主机
1.创建虚拟目录
现在,让我们继续安装虚拟主机。正如我先前所述,我要新建2台虚拟主机分别命名为&unixmen1.local&和&unixmen2.local&.
创建一个公用的文件夹来存放这两台虚拟主机的数据。
首先,让我们为unixmen1.local这个站点创建一个目录:
sudo mkdir -p /var/www/unixmen1.local/public_html
接着,为for unixmen2.local站点创建一个目录:
sudo mkdir -p /var/www/unixmen2.local/public_html
2. 设置所有者和权限
上面目录现在只有root拥有权限。我们需要修改这2个目录的拥有权给普通用户,而不仅仅是root用户。
sudo chown -R $USER:$USER /var/www/unixmen1.local/public_html/sudo chown -R $USER:$USER /var/www/unixmen2.local/public_html/
&$USER&变量指向了当前的登录用户。
设置读写权限给apache网页根目录(/var/www)及其子目录,这样每个人都可以从目录中读取文件。
sudo chmod -R 755 /var/www/
这样,我们就创建好了一些文件夹来保存网络相关数据并分配必要的权限和所属用户。
3. 为虚拟主机创建示例页
现在,我们给网站增加示例页。第一步,让我们给虚拟主机unixmen1.local创建一个示例页。
给unixmen1.local虚拟主机创建一个示例页,
sudo vi /var/www/unixmen1.local/public_html/index.html
添加以下内容:
&html&&head&&title&www.unixmen1.local&/title&&/head&&body&&h1&Welcome To Unixmen1.local website&/h1&&/body&&/html&
保存并关闭文件。
同样的,添加示例页到第二台虚拟主机。
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&
保存并关闭文件。
4. 创建虚拟主机配置文件
默认情况下,apache有一个默认的虚拟主机文件叫000-default.conf。我们将会复制000-default.conf文件内容到我们新的虚拟主机配置文件中。
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/unixmen1.local.confsudo 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 &ServerAdmin webmaster@unixmen1.localServerName unixmen1.localServerAlias www.unixmen1.localDocumentRoot /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.logCustomLog ${APACHE_LOG_DIR}/access.log combined&# 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&
同理,修改第二台主机文件。
sudo vi /etc/apache2/sites-available/unixmen2.local.conf
使相关的修改在unixmen2 站点呈现出来。
&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 &ServerAdmin webmaster@unixmen2.localServerName unixmen2.localServerAlias www.unixmen2.localDocumentRoot /var/www/unixmen2.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.logCustomLog ${APACHE_LOG_DIR}/access.log combined&# 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.confsudo a2ensite unixmen1.local.confsudo a2ensite unixmen2.local.conf
最后,重启apache服务器。
sudo service apache2 restart
就是这样。现在,我们成功地配置了apach虚拟主机在我们的Ubuntu服务器上
测试虚拟主机
编辑/etc/hosts文件,
sudo vi /etc/hosts
在文件末尾添加如下所示的虚拟域名。
192.168.1.250
unixmen1.local192.168.1.250
unixmen2.local
保存并关闭文件。
打开你的浏览器并访问&或&。你将会看到我们之前创建的示例页。
Unixmen1.local 测试页:
Unixmen2.local 测试页
如果你想从你的远程系统访问这些站点,你需要在你的DNS服务器添加实际域名记录。不过,我没有真实的域名和DNS服务器,我只想通过我的本地系统测试,那么它刚好如我所愿地工作。
译者:&校对:【编辑推荐】【责任编辑: TEL:(010)】
大家都在看猜你喜欢
原创头条头条外电头条
24H热文一周话题本月最赞
讲师:0人学习过
讲师:0人学习过
讲师:5人学习过
精选博文论坛热帖下载排行
《系统分析师考试辅导(2007版)》内容涵盖了最新的系统分析师考试大纲信息系统综合知识的所有知识点,分析了近3年信息系统分析与设计案例...
订阅51CTO邮刊13261人阅读
【apache】
虚拟主机(Virtual Host)&是在同一台机器搭建属于不同域名或者基于不同 IP 的多个网站服务的技术. 可以为运行在同一物理机器上的各个网站指配不同的 IP 和端口, 也可让多个网站拥有不同的域名.
Apache 是世界上使用最广的 Web 服务器, 从 1.1 版开始支持虚拟主机. 本文将讲解在不同服务器 (Redhat Enterprise Linux, Ubuntu Linux, Windows) 上使用 Apache 搭建虚拟主机来搭建多个网站.
Redhat Enterprise Linux
Redhat EnterpriseLinux (包括 CentOS Linux), 是使用最广的 Linux 服务器, 大量的网站应用都部署在其上.
1. 打开文件 /etc/httpd/conf/httpd.conf, 搜索VirtualHost example, 找到代码如下:
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#&VirtualHost *:80&
#&&& ServerAdmin webmaster@dummy-
#&&& DocumentRoot /www/docs/dummy-
#&&& ServerName dummy-
#&&& ErrorLog logs/dummy--error_log
#&&& CustomLog logs/dummy--access_log common
#&/VirtualHost&
2. 仿照例子, 添加一段代码来指定某一域名的网站.
# DocumentRoot 是网站文件存放的根目录
# ServerName 是网站域名, 需要跟 DNS 指向的域名一致
&VirtualHost *:80&
&&& ServerAdmin webmaster@dummy-
&&& DocumentRoot /var/www/httpdocs/demo_neoease_com
&&& ServerName
&&& ErrorLog logs/-error.log
&&& CustomLog logs/-access.log common
&/VirtualHost&
3. 重启 httpd 服务, 执行以下语句.
service httpd restart
Ubuntu Linux
Ubuntu 在 Linux 各发行版中, 个人用户数量最多的. 很多人在本机和虚拟机中使用. 但 Ubuntu 和 Redhat 的 VirtualHost 设置方法不相同.
1. 打开目录 /etc/apache2/sites-available/, 发现default 和 default-ssl 两个文件, 其中 default 是 http 虚拟主机服务的配置文件, default-ssl 是配置 https 服务使用的. 可以复制一份 default 文件. 并修改配置文件名, 文件名必须与域名一致 (如: )
2. 打开新建的配置文件, 修改 DocumentRoot, ServerName 和对应的配置目录. 例子如下:
# DocumentRoot 是网站文件存放的根目录
# ServerName 是网站域名, 需要跟 DNS 指向的域名一致
&VirtualHost *:80&
&&& ServerAdmin webmaster@dummy-
&&& DocumentRoot /var/www/httpdocs/demo_neoease_com
&&& ServerName
&&& ErrorLog ${APACHE_LOG_DIR}/-error.log
&&& CustomLog ${APACHE_LOG_DIR}/-access.log combined
&/VirtualHost&
3. 通过 a2ensite 激活虚拟主机配置
sudo a2ensite
4. 打开目录 /etc/apache2/sites-enabled/, 你会发现所有激活的虚拟主机, 可以通过 a2dissite 进行注销
sudo a2dissite
5. 重启 Apache 服务, 激活虚拟主机
sudo /etc/init.d/apache2 restart
Windows 是市场占有率最高的 PC 操作系统, 也是很多人的开发环境. 其 VirtualHost 配置方法与 Linux 上有些差异, 以下方式适合原生 Apache, XAMPP 和WAMP 套件.
1. 打开目录 {Apache2 安装目录}\conf\extra\, 找到 httpd-vhosts.conf 文件.
2. 仿照例子, 添加一段代码来指定某一域名的网站.
# DocumentRoot 是网站文件存放的根目录
# ServerName 是网站域名, 需要跟 DNS 指向的域名一致
&VirtualHost *:80&
&&& ServerAdmin webmaster@dummy-
&&& DocumentRoot &D:/workspace/php/demo_neoease_com&
&&& ServerName
&&& ErrorLog &logs/-error.log&
&&& CustomLog &logs/-access.log& common
&/VirtualHost&
3. 打开 httpd.conf 文件, 添加如下语句.
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
4. 重启 Apache 服务.
近年苹果的雄起, 让 Mac 日催普及, 也成为很多开发人员的选择. 因为与 Linux 同源, 配置方法也相似.
1. 打开文件 /private/etc/apache2/extra/httpd-vhosts.conf.
2. 仿照例子, 添加一段代码来指定某一域名的网站.
# DocumentRoot 是网站文件存放的根目录
# ServerName 是网站域名, 需要跟 DNS 指向的域名一致
&VirtualHost *:80&
&&& ServerAdmin webmaster@dummy-
&&& DocumentRoot &/usr/docs/httpdocs/demo_neoease_com&
&&& ServerName
&&& ErrorLog &/private/var/log/apache2/-error_log&
&&& CustomLog &/private/var/log/apache2/-access_log& common
&/VirtualHost&
3. 打开文件 /private/etc/apache2/httpd.conf, 搜索Virtual hosts, 找到代码如下:
# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf
去掉前面的注释符号&#, 保存文件.
4. 重启 apache 服务, 执行以下语句.
sudo apachectl restart
最近我在不同的几台服务器上搭建了一些网站服务, 这篇文章也算是我的个人笔记, 望日后可自用, 也希望对读者有用. 文中介绍了几个主流开发和部署环境上配置虚拟主机的方法, 其他 OS 大同小异.
因为还有些朋友留言希望知道 Nginx 的配置方法, 作为补充内容, 我又写了《》
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:502108次
积分:5024
积分:5024
排名:第5462名
原创:87篇
转载:29篇
评论:59条ubuntu&14.04&apache2&virtualhost
折腾了好久的阿帕奇终于搞定了。。。比windows下的麻烦多了,而且好像跟自己编译安装的apache2还不一样。
我的环境是linux mint 17,然后是通过apt来安装的apache2。
安装命令:
& $sudo apt-get install apache2 php5
mysql-server-5
我是顺便把php和mysql安装的
安装之后 打开浏览器输入localhost就可以访问到了。
可是关键是virtualhost,因为你不可能在/var/www文件夹下面放你的网页还有程序文件的,于是漫长的折腾开始了。
一开始是折腾/etc/apache2/apache2.conf,当然是无果了。。。。
然后百度。。。发现需要a2ensites和a2dissites两个命令来启动和关闭virtualhost的。
然后百度到一篇神文章(),在他的设置之下终于成功设置虚拟主机。
好像问题都解决了。。可是。。更多的问题正在粗线。。。。。。使用thinkphp的时候,说不够权限生成文件夹。。然后我批量把/home/username/public_html下面的所有文件都修改了权限。
修改命令:
$sudo chmod 777 -R ./public_html
777这个权限太豪放了。。。大家还是选择711会比较好。。不过不知道行不行。。
至此 暂时没有什么问题了
下面贴一下vittualhost的设置代码。
1.通过复制默认的文件来新建一个&
&/etc/apache2/sites-available/000-default.conf
&/etc/apache2/sites-available/myconf.conf
2.添加这么一段(放到里面):
Options FollowSymLinks
AllowOverride All
AllowOverride None
Allow from all
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
Order allow,deny
Allow from all
3.然后关闭默认的配置开启新建的配置
$a2dissites 000-default.conf && a2ensites
myconf.conf&
4.重启一下apache2的服务
$sudo service apache2 restart
5.然后打开浏览器输入localhost看看是不是显示了你设置路径下面的index文件了?
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 virtualbox新建虚拟机 的文章

 

随机推荐