網(wǎng)上看了很多亂七八糟的文章,始終沒有完美綁定域名,google 了很多文章后,參考老問題.apache 如果綁定多個(gè)域名終于成功了,拿出來分享下。假如我現(xiàn)在的服務(wù)器ip 是1.1.1.1,兩個(gè)域名ww
網(wǎng)上看了很多亂七八糟的文章,始終沒有完美綁定域名,google 了很多文章后,參考老問題.apache 如果綁定多個(gè)域名終于成功了,拿出來分享下。
假如我現(xiàn)在的服務(wù)器ip 是1.1.1.1,兩個(gè)域名www.a.com 和www.b.com 。
www.a.com 綁定到/var/www/a下.www.b.com 綁定到/var/www/b下。用基于域名的方式配置虛擬主機(jī)。
1、將 http://www.a.com 與 http://www.b.com 的DNS 解析到你的服務(wù)器IP 上。
2、刪除apache 的默認(rèn)主機(jī)配置文件。你也不希望創(chuàng)建2個(gè)虛擬主機(jī)后人家還能直接訪問/var/www/ 吧 ; 進(jìn)入 /etc/apache2/sites-enabled/ ; 刪除 000-default 文件。
3、在 /etc/apache2/sites-enabled/ 目錄,創(chuàng)建2個(gè)文件。文件名用 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