|
tid=1&我的環境是 <Linux CENTOS 6 + Apache + mysql> 〖方法一〗 1. vi /etc/httpd/httpd.conf
& r" j$ x O) C2. 找到 # VirtualHost example:
; ^/ |7 ?. k0 g7 G2 m4 L- 其下加入你的virtual server 設定,例如:3 V' ?9 v# \! Z3 v* ]5 \( d
- #2014/10/02 add1 ^) f7 [# R" V9 E; R" S0 s
- <VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解
- X |8 A$ J3 y+ r - ServerAdmin root@av4u.com
$ w' f& v& a7 m) S2 H6 ]( T' N - DocumentRoot /home/coav4u/public_html* Y: X' _. s* |4 {
- ServerName av4u.co( y6 s+ c# T6 R6 |, T, h$ Z3 D
- ErrorLog logs/www.av4u.co-error_log. | Q# d, Y1 O6 ?$ ] V% ]3 N' \
- CustomLog logs/www.av4u.co-access_log common
/ g; B9 t7 H9 m: w b - </VirtualHost>
. Z% M3 j1 ^# f5 G - <VirtualHost 192.168.1.12:80>
e8 s. v$ E( q) b - ServerAdmin root@av4u.com5 _) \% \% c% f. M
- DocumentRoot /home/coav4u/public_html+ k1 K; x) M. R+ k |, T# L3 g' U
- ServerName www.av4u.co
& f @: q: S$ j - ErrorLog logs/www.av4u.co-error_log
. \/ W3 F/ X5 ~' ?1 ?$ L - CustomLog logs/www.av4u.co-access_log common! I; @ e$ Q4 x7 w2 G
- </VirtualHost>
複製代碼 可同時指定2個 Domain name (av4u.com及www.av4u.com)到同一個虛擬空間,這個部分似乎比 nginx 設定稍微麻煩一點5 A7 A; M# W8 Y. T, s7 q: e( Y
3. 重啟 Apache 才生效
4 k2 P. l" ^3 [0 _% ? service httpd restart #須以root身分 --->搞定
4 O, K5 \/ ^) a1 Q$ V4 | 註: service httpd start #啟動
, V6 r' B7 l( ?0 H6 ^2 G( S service httpd start #停止
P& P/ J8 l9 }; Q/ j〖方法二〗
- k+ ~" R& R/ \* q4 e& V' Z6 ^7 U在/etc/httpd/conf.d/新ˋ建一獨立檔(設定一個virtual host)$ L) a* O: ]/ y+ P0 c8 e
例如:
8 m( U% @+ L+ p; U0 Ivirtual1.conf- V9 l3 h) {. Q) S* x
- <VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解
2 g. x0 T5 Y( X. l' [4 i' V - ServerAdmin root@av4u.com
4 T( R9 }7 G s+ e, c- x% F - DocumentRoot /home/coav4u/public_html
# B1 P& j: D! S" P7 N - ServerName av4u.co
* M. o: G: e, p - ErrorLog logs/www.av4u.co-error_log
$ V+ \; o$ T. p" D' @# \: O - CustomLog logs/www.av4u.co-access_log common. Q$ G; H% O' Q1 m7 k- }
- </VirtualHost>
複製代碼 virtual2.conf
+ _+ {; Y0 ~: o# I( k. Q% G$ \6 C+ g- <VirtualHost 192.168.1.12:80>
/ G- D* n- ]! @! ~+ ` - ServerAdmin root@av4u.com
6 p1 {5 F) T, t9 _8 j - DocumentRoot /home/coav4u/public_html% u# z( X; ] u9 m3 W) d
- ServerName www.av4u.co
7 w* G+ n/ S5 c! ` - ErrorLog logs/www.av4u.co-error_log# m0 k: ^, @, d% P% K& b
- CustomLog logs/www.av4u.co-access_log common
2 v$ j v! D: y4 m5 C( U - </VirtualHost>
複製代碼 存檔然後重啟 httpd
8 b$ Q2 z1 ]# B+ G0 S; y. z3 P但是出現 error:
& R k- U! G, k0 |7 e [warn] _default_ VirtualHost overlap on port 80, the first has precedence
. R' Y/ ^7 X" M. a/ `4 _# BSOL:. C- v& H/ o+ C" L& x4 q0 P' I
由於 /etc/httpd/conf/httpd.conf 內 NameVirtualHost *:80 而 virtual1.conf及virtual2.conf 內都設定為 <VirtualHost 192.168.1.12:80> 不匹配,正確的設定為:
2 n* p' w" A4 A5 d0 v3 V7 shttpd.conf 及 virtual1.conf及virtual2.conf(所有虛擬主機的設定檔)不是都為 *:80 就是都為 192.168.1.12:80 即
( ]/ u' J% |. C& H2 R4 Xhttpd.conf ===> NameVirtualHost *:80 , virtual1.conf及virtual2.conf ===> <VirtualHost *:80> 或者
$ _6 G/ g; B" y8 yhttpd.conf ===> NameVirtualHost 192.168.1.12:80 , virtual1.conf及virtual2.conf ===> <VirtualHost 192.168.1.12:80>
' I4 F1 J7 X* k' }+ k2 c+ S% r3 v" ?. P1 g, M! j7 r
2 q% x& d: Z9 n6 K I) C3 t
! F4 B$ p' m. k1 C+ P$ U
|