tid=1&我的環境是 <Linux CENTOS 6 + Apache + mysql> 〖方法一〗 1. vi /etc/httpd/httpd.conf$ ?$ N, m, |) k
2. 找到 # VirtualHost example:- t. B# J, J9 I1 w# R/ Q
- 其下加入你的virtual server 設定,例如:
) r. v8 e; {9 O& m - #2014/10/02 add z2 I' ~' W7 Z$ v# o8 ?
- <VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解
2 f6 \$ M; F( Y - ServerAdmin root@av4u.com
, m- f, J, V* N- h - DocumentRoot /home/coav4u/public_html
: x: q- q( m( v, M2 ` - ServerName av4u.co: b0 s' }1 x/ K# s1 {- f
- ErrorLog logs/www.av4u.co-error_log6 D! L9 w1 E4 v# o/ w+ P( K8 a
- CustomLog logs/www.av4u.co-access_log common
# w4 t$ w) f) x) _ - </VirtualHost>
# l7 t% o5 s$ k! [2 \1 X( a7 k - <VirtualHost 192.168.1.12:80>
4 B6 x; K. d7 G q r# R - ServerAdmin root@av4u.com$ e6 \$ G9 _9 d8 n; @& u A* A/ d$ I
- DocumentRoot /home/coav4u/public_html
7 t( f! P9 l* P2 c - ServerName www.av4u.co
% D9 M& ^( V$ z! d" l* ^ - ErrorLog logs/www.av4u.co-error_log
( s# l. E" ]4 D% T; b7 o - CustomLog logs/www.av4u.co-access_log common1 y& d2 ?, P# `
- </VirtualHost>
複製代碼 可同時指定2個 Domain name (av4u.com及www.av4u.com)到同一個虛擬空間,這個部分似乎比 nginx 設定稍微麻煩一點; L- V1 K+ T* e! y, n9 _
3. 重啟 Apache 才生效
8 O/ m8 C& ?% Q service httpd restart #須以root身分 --->搞定' v% c) D- v: n6 ?2 ^
註: service httpd start #啟動
3 E5 F d7 m0 |5 J3 _/ J) ~ service httpd start #停止: t6 b: {% \. G: k( X$ C- r
〖方法二〗
3 j' n. n, q# h3 ^在/etc/httpd/conf.d/新ˋ建一獨立檔(設定一個virtual host)
' d- @! L! T. R& t6 Q例如: / T8 i y( j( a2 v6 {3 f
virtual1.conf
& C: D5 K! u3 ]( G- <VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解
$ K5 S) R1 t5 J: Q2 x; t - ServerAdmin root@av4u.com
6 t* {+ A$ T; x2 j, f! s$ H* _/ [ - DocumentRoot /home/coav4u/public_html2 J! W0 k/ q/ j2 {& c9 J2 h5 {3 I
- ServerName av4u.co7 Y; b; F8 m+ u1 B6 V
- ErrorLog logs/www.av4u.co-error_log" Z% m6 |0 s; j) q- s% E Z2 }+ |% v
- CustomLog logs/www.av4u.co-access_log common+ `) l3 c& J$ V7 q% ^* D2 F
- </VirtualHost>
複製代碼 virtual2.conf
% r, ~) H0 }3 l# j4 T$ u+ F! a- <VirtualHost 192.168.1.12:80>2 d& U5 J9 Q6 `# F3 k% `$ V
- ServerAdmin root@av4u.com
m) j0 T! X5 K! W+ j - DocumentRoot /home/coav4u/public_html, M, J) r% E) K
- ServerName www.av4u.co$ u+ ]& k' |- m4 Z" \+ ]- q: n1 b. S/ ?
- ErrorLog logs/www.av4u.co-error_log& y# R( m; t9 {: ~
- CustomLog logs/www.av4u.co-access_log common1 w; \4 B, A( ?; v
- </VirtualHost>
複製代碼 存檔然後重啟 httpd) \+ Z8 Y9 E" [- v% E/ U* u
但是出現 error:
$ D( j$ D9 c, I7 r [warn] _default_ VirtualHost overlap on port 80, the first has precedence
# C4 k6 l& _% {7 M9 ESOL:
, [& t3 e& B! ?: h U& Q由於 /etc/httpd/conf/httpd.conf 內 NameVirtualHost *:80 而 virtual1.conf及virtual2.conf 內都設定為 <VirtualHost 192.168.1.12:80> 不匹配,正確的設定為:, Z! I$ \& h( O" A- u# W
httpd.conf 及 virtual1.conf及virtual2.conf(所有虛擬主機的設定檔)不是都為 *:80 就是都為 192.168.1.12:80 即- i& I) ^7 ~ e# c( ]
httpd.conf ===> NameVirtualHost *:80 , virtual1.conf及virtual2.conf ===> <VirtualHost *:80> 或者 & B( ^( }; p$ E( v$ g1 f
httpd.conf ===> NameVirtualHost 192.168.1.12:80 , virtual1.conf及virtual2.conf ===> <VirtualHost 192.168.1.12:80>
! C! U8 V0 Q2 d4 \; U, F7 N& W0 G, b( i
2 y( N7 ?* Y* b, N8 r2 x
, Z9 y& O( q( R B4 z1 T$ W |