ubuntu apache 配置虚拟主机
2012-09-27 15:13
369 查看
比如有两个域名www.linuxidc 和www.linuxidc.net两个域名要做解析
在/etc/apache2/sites-available 目录下建立a和b两个文件,这里只是为了使用的方便,你仔细观察可以看出在sites-enabled文件下也会有相关的文件连接(只是一个软连接)到sites-available 文件下相应的文件上
为了方便管理,这里做的都使用一个名称也容易记忆。
编辑相应文件内容如下
NameVirtualHost www.linuxidc
<VirtualHost www.linuxidc>
ServerName www.linuxidc
ServerAlias linuxidc *.linuxidc
ServerAdmin webmaster@linuxidc
DocumentRoot /var/www/a/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/a/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
# Commented out for Ubuntu
#RedirectMatch ^/$ /apache2-default/
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/a.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
文件b里的内容基本和a是一样的,只需要所少数几处改一下
执行a2ensite a a2ensite b 命令使虚拟主机生效
重启apache
Java代码
/etc/init.d/apache2 restart
或者重新加载apache2
Java代码
/etc/init.d/apache2 reload
修改hosts文件
Java代码
vi /etc/hosts
插入下面两行
127.0.0.1 www.linuxidc
127.0.0.1 www.linuxidc.net
现在访问两个域名,会发现解析到了不同的目录
如果哪个虚拟主机不想使用只需要执行命令
Java代码
a2dissite b
这样再访问www.linuxidc.net就不能正确解析
在/etc/apache2/sites-available 目录下建立a和b两个文件,这里只是为了使用的方便,你仔细观察可以看出在sites-enabled文件下也会有相关的文件连接(只是一个软连接)到sites-available 文件下相应的文件上
为了方便管理,这里做的都使用一个名称也容易记忆。
编辑相应文件内容如下
NameVirtualHost www.linuxidc
<VirtualHost www.linuxidc>
ServerName www.linuxidc
ServerAlias linuxidc *.linuxidc
ServerAdmin webmaster@linuxidc
DocumentRoot /var/www/a/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/a/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
# Commented out for Ubuntu
#RedirectMatch ^/$ /apache2-default/
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/a.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
文件b里的内容基本和a是一样的,只需要所少数几处改一下
执行a2ensite a a2ensite b 命令使虚拟主机生效
重启apache
Java代码
/etc/init.d/apache2 restart
或者重新加载apache2
Java代码
/etc/init.d/apache2 reload
修改hosts文件
Java代码
vi /etc/hosts
插入下面两行
127.0.0.1 www.linuxidc
127.0.0.1 www.linuxidc.net
现在访问两个域名,会发现解析到了不同的目录
如果哪个虚拟主机不想使用只需要执行命令
Java代码
a2dissite b
这样再访问www.linuxidc.net就不能正确解析
相关文章推荐
- Ubuntu Linux Apache虚拟主机的安装配置
- ubuntu下和windows下配置apache虚拟主机
- Ubuntu上apache多端口配置虚拟主机的方法
- Ubuntu Apache 虚拟主机 VirtualHost 初级配置
- Ubuntu 16.04与Apache虚拟主机配置的步骤详解
- ubuntu系统下apache配置虚拟主机及反向代理详解
- 转:Ubuntu上apache多端口配置虚拟主机的方法
- ubuntu下配置apache虚拟主机
- Ubuntu下Apache多站点虚拟主机配置
- Ubuntu Server 14.04 & Apache2.4 虚拟主机、模块重写、隐藏入口文件配置
- ubuntu中Apache 虚拟主机的配置
- Ubuntu下配置Apache的虚拟主机
- Ubuntu下配置Apache的虚拟主机
- Ubuntu上apache多端口配置虚拟主机的方法
- ubuntu下apache&php&虚拟主机开发环境配置
- Ubuntu 配置 apache 虚拟主机以后出现 [warn] NameVirtualHost *:80 has no VirtualHosts
- Apache 虚拟主机的配置[Ubuntu]
- ubuntu下apt-get安装apache的虚拟主机的配置
- ubuntu下Apache虚拟主机的配置
- Ubuntu下Apache配置虚拟主机