网上看了很多乱七八糟的文章,始终没有完美绑定域名,google 了很多文章后,参考老问题.apache 如果绑定多个域名终于成功了,拿出来分享下。假如我现在的服务器ip 是1.1.1.1,两个域名ww
网上看了很多乱七八糟的文章,始终没有完美绑定域名,google 了很多文章后,参考老问题.apache 如果绑定多个域名终于成功了,拿出来分享下。
假如我现在的服务器ip 是1.1.1.1,两个域名www.a.com 和www.b.com 。
www.a.com 绑定到/var/www/a下.www.b.com 绑定到/var/www/b下。用基于域名的方式配置虚拟主机。
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/ 目录,创建2个文件。文件名用 a.conf 和 b.conf 。
在 a.conf 里填入以下代码: ServerName www.a.com ServerAdmin webmaster@localhost DocumentRoot /var/www/a/ Options FollowSymLinks AllowOverride None Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ AllowOverride None Options ExecCGI -MultiViews SymLinksIfOwnerMatch Order allow,deny Allow from all 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/" Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 36
在 b.conf 里填入以下代码:
,
ServerName www.b.com ServerAdmin webmaster@localhost DocumentRoot /var/www/b/ Options FollowSymLinks AllowOverride None Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ AllowOverride None Options ExecCGI -MultiViews SymLinksIfOwnerMatch Order allow,deny Allow from all 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/" Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 41
4、在 /etc/apache2/sites_enabled/ 里面建立ln 链接
ln -s /etc/apache2/sites-available/a.conf /etc/apache2/sites-1 enabled/b.conf
ln -s /etc/apache2/sites-available/b.conf /etc/apache2/sites-1 enabled/b.conf
5、重启apache
,
sudo /etc/init.d/apache2 1 restart