【轉】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 里填入以下代碼:

 1 <VirtualHost *:80>
 2         ServerName www.a.com
 3    ServerAdmin webmaster@localhost
 4    DocumentRoot /var/www/www.a.com
 5    <Directory />
 6       Options FollowSymLinks
 7       AllowOverride None
 8    </Directory>
 9    <Directory /var/www/www.a.com/>
10       Options Indexes FollowSymLinks MultiViews
11       AllowOverride None
12       Order allow,deny
13       allow from all
14    </Directory>
15 
16    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
17    <Directory "/usr/lib/cgi-bin">
18       AllowOverride None
19       Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
20       Order allow,deny
21       Allow from all
22    </Directory>
23 
24    #ErrorLog ${APACHE_LOG_DIR}/error.log
25 
26    # Possible values include: debug, info, notice, warn, error, crit,
27    # alert, emerg.
28    LogLevel warn
29 
30    #CustomLog ${APACHE_LOG_DIR}/access.log combined
31 
32     Alias /doc/ "/usr/share/doc/"
33     <Directory "/usr/share/doc/">
34         Options Indexes MultiViews FollowSymLinks
35         AllowOverride None
36         Order deny,allow
37         Deny from all
38         Allow from 127.0.0.0/255.0.0.0 ::1/128
39     </Directory>
40 
41 </VirtualHost>
www.a.com.conf
 1 <VirtualHost *:80>
 2         ServerName www.b.com
 3    ServerAdmin webmaster@localhost
 4    DocumentRoot /var/www/www.b.com
 5    <Directory />
 6       Options FollowSymLinks
 7       AllowOverride None
 8    </Directory>
 9    <Directory /var/www/www.b.com/>
10       Options Indexes FollowSymLinks MultiViews
11       AllowOverride None
12       Order allow,deny
13       allow from all
14    </Directory>
15 
16    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
17    <Directory "/usr/lib/cgi-bin">
18       AllowOverride None
19       Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
20       Order allow,deny
21       Allow from all
22    </Directory>
23 
24    #ErrorLog ${APACHE_LOG_DIR}/error.log
25 
26    # Possible values include: debug, info, notice, warn, error, crit,
27    # alert, emerg.
28    LogLevel warn
29 
30    #CustomLog ${APACHE_LOG_DIR}/access.log combined
31 
32     Alias /doc/ "/usr/share/doc/"
33     <Directory "/usr/share/doc/">
34         Options Indexes MultiViews FollowSymLinks
35         AllowOverride None
36         Order deny,allow
37         Deny from all
38         Allow from 127.0.0.0/255.0.0.0 ::1/128
39     </Directory>
40 
41 </VirtualHost>
www.b.com.conf

apache詳細權限在以上配置文件修改就行。

 

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM