Ubuntu apache 虚拟主机配置

区别于Windows 下apache,配置文件通常只有一个,就是httpd.conf。

本机环境是通过 apt-get install xxx

Linux下 Apache的配置文件是 /etc/apache2/apache2.conf,Apache在启动时会自动读取这个文件的配置信息。而其他的一些配置文件,如 httpd.conf等,则是通过Include指令包含进来。

在apache2.conf里有sites-enabled目录,而在 /etc/apache2下还有一个sites-available目录,其实,这里面才是真正的配置文件,而sites- enabled目录存放的只是一些指向这里的文件的符号链接,你可以用ls /etc/apache2/sites-enabled/来证实一下。

所以,如果apache上配置了多个虚拟主机,每个虚拟主机的配置文件都放在 sites-available下,那么对于虚拟主机的停用、启用就非常方便了:当在sites-enabled下建立一个指向某个虚拟主机配置文件的链 接时,就启用了它;如果要关闭某个虚拟主机的话,只需删除相应的链接即可,根本不用去改配置文件。

1.
sudo
cp
/etc/apache2/sites-avaliable/000-default.conf
, 命名为
test.conf

2.修改配置文件:test.conf

<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.test.com

ServerAdmin [email protected]

DocumentRoot /var/www/html/test/

ErrorLog /var/www/html/test/error.log

CustomLog /var/www/html/test/access.log combined

<Directory "/var/www/html/test">

    Options FollowSymLinks

    DirectoryIndex index.php index.html index.htm

    AllowOverride All #注意这个地方的配置,会影响本地目录下的.htaccess的启用

    Order deny,allow

    Allow from All

</Directory>

# 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

# 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>

  

3. 建立链接文件:

sudo ln -s /etc/apache2/sites-available/test.conf /etc/apache2/sites-enabled/test.conf

或者: sudo a2ensite test.conf

4.重启apache 服务器

sudo /etc/init.d/apache2 restart

5. 修改hosts(/etc/hosts)

添加127.0.0.1	www.test.com

到这里基本就可正常访问了!

附:如果这里还需要对目录级的URL重写支持,继续往下:

1.
终端运行

sudo a2enmod

程序提示可供激活的模块名称,输入:rewrite

成功会提示 rewrite already load

2.
修改/etc/apache2/sites-enabled/test.conf
(该链接指向的是站点配置文件)
把下的AllowOverride
属性改为All,保存。(上面我们已经配置为
All)

3.
重新加载apache

sudo /etc/init.d/apache2 restart

资料参考:http://www.cnblogs.com/andhm/archive/2012/08/02/2619680.html

时间: 2024-12-05 14:43:20

Ubuntu apache 虚拟主机配置的相关文章

Apache虚拟主机配置

在一个Apache服务器上可以配置多个虚拟主机,实现一个服务器提供多站点服务,其实就是访问同一个服务器上的不同目录.Apache虚拟主机配置有3中方法:基于IP配置.基于域名配置和基于端口配置,这里介绍基于域名配置和基于端口配置,基于IP配置方法类似. 1. Apache基于域名配置虚拟主机: 打开Apache安装目录下的配置文件conf/extra/httpd-vhosts.conf,添加如下配置信息: <VirtualHost _default_:80> DocumentRoot &quo

Apache虚拟主机配置详解

1.配置环境说明 系统环境:CentOS7 Apache环境:编译安装的httpd-2.4.7 系统限制:关闭了防火墙和selinux hosts文件中配置以下域名解析 192.168.115.150    www.web1.com 192.168.115.150    www.web2.com 2.Apache虚拟主机简介 虚拟主机是指在一个机器上运行多个网站(例如:www.web1.com和www.web2.com).每个站点希望用不同的域名和站点目录,或者是不同端口.不同的IP就需要虚拟主

apache虚拟主机配置及解析

Apache虚拟主机配置及解析 1.修改httpd-vhosts.conf 打开apache(Apache24)/conf/extra/httpd-vhosts.conf文件,添加虚拟主机信息,可以这只不同的域名指向不同的文件目录 <VirtualHost *:80> ServerAdmin [email protected]163.com # 服务管理员邮箱地址,出问题时发送邮件到这个邮箱 DocumentRoot "D:/AppServ/www/wx" # apache

IP、Apache虚拟主机配置部分学习笔记

IP地址 IP地址就是计算机的一个"编号",该编号是唯一的.相当于我们的身份证号码一样. IP地址格式:a.b.c.d  ,每一段的取值范围0-255. 本机的IP地址:127.0.0.1      只能是自己访问自己,别人无法通过这个IP访问你的电脑. 本机的域名:localhost         只能是自己访问自己,别人无法通过这个域名来访问你的电脑. 别人要想访问你的电脑,必须通过网卡的IP地址来访问. nslookup  www.baidu.com  命令窗口查看域名对应得I

http服务(四)——apache虚拟主机配置

apache虚拟主机分为三类:基于IP.基于端口.基于域名.通常虚拟主机和物理主机不能同时使用,开启虚拟主机需注释掉以下一行: DocumentRoot "/var/www/html" 一.基于IP 1. 假设服务器有个IP地址为192.168.1.10,使用ifconfig在同一个网络接口eth0上绑定3个IP: [[email protected] root]# ifconfig eth0:1 192.168.1.11 [[email protected] root]# ifcon

phpStudy 2014的Apache虚拟主机配置

安装phpStudy直接百度下载,傻瓜式安装很简单,一直点击下一步即可,中途根据个人爱好设置WWW目录,我的设置在D盘根目录里. 打开虚拟主机配置,打开D:\phpStudy\Apache\conf下的 httpd.conf文件去掉#Include conf/extra/httpd-vhosts.conf前面的#保存即可.这一步操作非常关键 在D:\WWW目录下建立web应用例如 classmath. 打开D:\phpStudy\Apache\conf\extra下的httpd-vhosts.c

Apache 虚拟主机 配置方法

打开httpd.conf文件 去掉LoadModule vhost_alias_module modules/mod_vhost_alias.so前面的#号 去掉Include conf/extra/httpd-vhosts.conf这句前面的#号 然后打开apache目录下\conf\extra下的httpd-vhosts.conf文件,加入如下代码 #配置自己的虚拟主机 <VirtualHost *:80> #网站目录,如果在www目录下的php目录,下面 #就填写F:/www/php D

Apache虚拟主机配置(多个域名访问多个目录)

为了方便管理虚拟主机,我决定使用一种方法,那就是修改httpd-vhosts.conf文件. 第一步首先要使扩展文件httpd-vhosts.conf生效:1. 打开 apache/conf/httpd.conf 文件2. 找到 # Include conf/extra/httpd-vhosts.conf3. 去掉前面的注释符#号4. 打开 apache/conf/extra/httpd-vhosts.conf5. 添加以上的多端口或多域名代码(这里以多域名为例):6. 打开apache2/co

CentOS下Apache虚拟主机配置

通过phpinfo可以看到Apache安装的目录 修改配置文件,首先将配置文件备份 编辑httpd.conf,并找到虚拟路径配置的部分 vi httpd.conf 在vi下先按esc在键入 :/vhosts 将以下这一段复制一遍 结果如下 附上我配置的