【转】Ubuntu+apache绑定多个域名

时间:2023-03-09 01:12:30
【转】Ubuntu+apache绑定多个域名

1. 将 http://www.a.com 与 http://www.b.com 的DNS解析到你的服务器IP上。

2. 删除apache的默认主机配置文件。你也不希望创建2个虚拟主机后人家还能直接访问/var/www/ 吧 ;
进入 /etc/apache2/sites-enabled/ ; 删除 000-default 文件。

3. 在 /etc/apache2/sites-enabled/ 目录 , 用VI创建2个文件。文件名用 www.a.com.conf ; www.b.com.conf
在 www.a.com.conf 里填入以下代码:

 <VirtualHost *:80>
ServerName www.a.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/www.a.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/www.a.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</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 ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn #CustomLog ${APACHE_LOG_DIR}/access.log combined 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>

www.a.com.conf

 <VirtualHost *:80>
ServerName www.b.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/www.b.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/www.b.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</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 ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn #CustomLog ${APACHE_LOG_DIR}/access.log combined 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>

www.b.com.conf

apache详细权限在以上配置文件修改就行。

文章转自:http://forum.ubuntu.org.cn/viewtopic.php?t=341070