tid=1&我的環境是 <Linux CENTOS 6 + Apache + mysql> 〖方法一〗 1. vi /etc/httpd/httpd.conf; I9 i7 {4 j/ h- L& a# x
2. 找到 # VirtualHost example:
4 T7 o5 k a! x% `7 ~: J- 其下加入你的virtual server 設定,例如:
% q, f$ N' P2 @- m% c- S3 ?6 ^ - #2014/10/02 add
$ r4 }( M8 }& U! p! p1 b - <VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解4 a+ G! U; _7 T( D( X }
- ServerAdmin root@av4u.com% J5 [* M" b) x+ t: W' |9 B
- DocumentRoot /home/coav4u/public_html& h& u) v K0 D, w: I; P
- ServerName av4u.co
/ i8 L$ P8 B4 h/ y- x6 b - ErrorLog logs/www.av4u.co-error_log
" F! y% E0 m n( Q# l - CustomLog logs/www.av4u.co-access_log common2 r0 w! A, F1 ]6 N4 p4 ]
- </VirtualHost>
4 x' d/ m1 ^8 J - <VirtualHost 192.168.1.12:80>
\* y6 s9 \7 K1 s1 y8 D* \; h. ] C - ServerAdmin root@av4u.com
1 K, V2 T; |9 _) x - DocumentRoot /home/coav4u/public_html/ `" A1 m" f: z4 E
- ServerName www.av4u.co$ q; u& l* r& b% z; n
- ErrorLog logs/www.av4u.co-error_log6 R3 T) j+ D$ ~, _# z" J
- CustomLog logs/www.av4u.co-access_log common
# V1 u& z% T. s( n. I; n - </VirtualHost>
複製代碼 可同時指定2個 Domain name (av4u.com及www.av4u.com)到同一個虛擬空間,這個部分似乎比 nginx 設定稍微麻煩一點
7 ^4 k" w& z9 O6 g; h. o3. 重啟 Apache 才生效
$ j. e! j! J- g! F6 R/ ~9 X service httpd restart #須以root身分 --->搞定
# g# _8 `. ^# G A 註: service httpd start #啟動 & m d1 [1 z" V1 a9 g% ?
service httpd start #停止+ G4 Q1 z% [/ `8 M5 J4 w7 i; K
〖方法二〗7 ~; n" \" Z9 _! e
在/etc/httpd/conf.d/新ˋ建一獨立檔(設定一個virtual host)! C ~; l% F- L- U
例如: ) a$ ]: j7 s8 r1 ]# m# ~6 H i c( _
virtual1.conf9 k; y3 U7 B2 I9 W# E9 P% l
- <VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解! q1 S, E$ j* `! {/ |6 k/ g
- ServerAdmin root@av4u.com' F& F b2 S7 Q+ ?9 c
- DocumentRoot /home/coav4u/public_html
3 {1 z! B7 B/ u" D, i/ { - ServerName av4u.co9 w" p$ Z. Q" B8 z) B
- ErrorLog logs/www.av4u.co-error_log0 {7 m. @3 D. [, S
- CustomLog logs/www.av4u.co-access_log common
2 H6 T8 M' i, o8 ? - </VirtualHost>
複製代碼 virtual2.conf- m3 C( K2 [) O4 ^( Z8 z" b; M
- <VirtualHost 192.168.1.12:80>
/ J, k1 J i W' l+ } - ServerAdmin root@av4u.com
5 z9 E; C4 d% V4 L - DocumentRoot /home/coav4u/public_html3 D' ~. ^+ W. B
- ServerName www.av4u.co' R$ U$ R2 C) h$ Y! c3 Y. y5 [3 j8 u E
- ErrorLog logs/www.av4u.co-error_log) \: \# e6 n$ o/ o- X" i
- CustomLog logs/www.av4u.co-access_log common
) r! L$ w* v0 w/ M3 N" i6 [5 c4 e o - </VirtualHost>
複製代碼 存檔然後重啟 httpd
R [4 A- E" J: X! X& F但是出現 error:
, R8 E0 [. g7 D/ p$ ^% ~ [warn] _default_ VirtualHost overlap on port 80, the first has precedence
. L4 p2 W- a4 lSOL:; V% o ?2 A+ P( }; m
由於 /etc/httpd/conf/httpd.conf 內 NameVirtualHost *:80 而 virtual1.conf及virtual2.conf 內都設定為 <VirtualHost 192.168.1.12:80> 不匹配,正確的設定為:
+ ?/ @& X* K1 _/ D/ q( H4 Lhttpd.conf 及 virtual1.conf及virtual2.conf(所有虛擬主機的設定檔)不是都為 *:80 就是都為 192.168.1.12:80 即* V" t0 |# I9 I) O
httpd.conf ===> NameVirtualHost *:80 , virtual1.conf及virtual2.conf ===> <VirtualHost *:80> 或者
. C7 R0 X: ?" E+ Chttpd.conf ===> NameVirtualHost 192.168.1.12:80 , virtual1.conf及virtual2.conf ===> <VirtualHost 192.168.1.12:80>
' m5 H3 O, G: d1 l& u' r- |9 [5 P1 z2 F- Y& v& J! V8 D
4 d& s$ ~0 P/ L! i; i3 V9 n0 k/ q+ a0 n! B! d
|