tid=1&我的環境是 <Linux CENTOS 6 + Apache + mysql> 〖方法一〗 1. vi /etc/httpd/httpd.conf
2 I( s; P3 b9 P# M& F3 ]+ e2. 找到 # VirtualHost example:1 b" ~8 _. u4 X5 M
- 其下加入你的virtual server 設定,例如:
1 p& i& ^) k( t; x, E) j' u5 |7 i - #2014/10/02 add
& \' u$ k2 x- g# A0 F - <VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解( c& h; ^0 \/ Z7 {/ ~
- ServerAdmin root@av4u.com
+ r& f$ l" z5 |! M: q - DocumentRoot /home/coav4u/public_html5 d, n, m. c# ?
- ServerName av4u.co
( Y/ n* B8 v) O* f1 v: w8 d t- n - ErrorLog logs/www.av4u.co-error_log# Z# [' ~, Y1 j: {7 O% K% R2 l
- CustomLog logs/www.av4u.co-access_log common
! k% a3 g! J' a! E; `+ R7 m' Z - </VirtualHost>3 {; K; s1 n1 S- q D! g
- <VirtualHost 192.168.1.12:80>
& o% ]5 B! \: J* T# l7 I - ServerAdmin root@av4u.com
; T, @$ v' f8 l: e& Z; C7 F - DocumentRoot /home/coav4u/public_html* X1 f& F, I; W, Z3 a
- ServerName www.av4u.co( ?5 l5 w$ h% Q- N8 t4 f0 Z4 A; a
- ErrorLog logs/www.av4u.co-error_log
' b* J: o* U3 x( X0 P/ t( _ - CustomLog logs/www.av4u.co-access_log common! L4 [- L; v. x6 a. d6 A
- </VirtualHost>
複製代碼 可同時指定2個 Domain name (av4u.com及www.av4u.com)到同一個虛擬空間,這個部分似乎比 nginx 設定稍微麻煩一點, z8 X. f0 ?3 y7 {
3. 重啟 Apache 才生效: [! `1 W+ K5 h+ y
service httpd restart #須以root身分 --->搞定6 B- {. q( h0 R2 a6 H
註: service httpd start #啟動
0 }& S% `' A+ ^, U% J- `' p service httpd start #停止
0 X. d. X! A& y7 `& d9 {2 I〖方法二〗
6 D3 m7 u9 k" x' W1 [, J" d在/etc/httpd/conf.d/新ˋ建一獨立檔(設定一個virtual host)
! D' x: k, X' Y1 b7 z6 l例如: 2 C% g4 M9 b) n+ S9 e9 Z
virtual1.conf
; e) j+ a" w3 y! E$ m3 K- <VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解9 y( v4 c! v+ L3 y
- ServerAdmin root@av4u.com
- G3 C/ s$ X, D1 R8 }1 U$ T( o3 i4 o - DocumentRoot /home/coav4u/public_html0 h1 ~" k' }9 `: t4 l
- ServerName av4u.co
4 d+ T) z0 n6 [# A$ i( K - ErrorLog logs/www.av4u.co-error_log: }3 \$ A& k: u( \( I- @
- CustomLog logs/www.av4u.co-access_log common( r9 V- {1 X3 F) |& z
- </VirtualHost>
複製代碼 virtual2.conf
' r i3 Z8 X' o. m6 ~2 B- <VirtualHost 192.168.1.12:80>* L' E4 A& E% w; a, ~
- ServerAdmin root@av4u.com
3 b8 _% J, g4 G - DocumentRoot /home/coav4u/public_html+ }/ D9 }8 r# o1 a, Y8 C
- ServerName www.av4u.co
' I* v' M3 z4 {! }5 f& U - ErrorLog logs/www.av4u.co-error_log6 W/ a1 E; ?: ^& X
- CustomLog logs/www.av4u.co-access_log common
7 y% U# }; S S# c+ @ - </VirtualHost>
複製代碼 存檔然後重啟 httpd
9 u$ d1 x" y& D; L8 K9 c3 j6 B但是出現 error:
# \% N. ]& @# X; t' C) ^& \ [warn] _default_ VirtualHost overlap on port 80, the first has precedence/ x- F" D, y `9 J2 j) Z/ ^% o/ C
SOL:
* \4 ~0 v# F3 W* g4 m由於 /etc/httpd/conf/httpd.conf 內 NameVirtualHost *:80 而 virtual1.conf及virtual2.conf 內都設定為 <VirtualHost 192.168.1.12:80> 不匹配,正確的設定為:
; H9 B8 h) u; Q9 ?httpd.conf 及 virtual1.conf及virtual2.conf(所有虛擬主機的設定檔)不是都為 *:80 就是都為 192.168.1.12:80 即
3 q3 q7 w$ `* ^( z8 n8 Q' Phttpd.conf ===> NameVirtualHost *:80 , virtual1.conf及virtual2.conf ===> <VirtualHost *:80> 或者
9 U) `' d* u4 t! i% v( [# `httpd.conf ===> NameVirtualHost 192.168.1.12:80 , virtual1.conf及virtual2.conf ===> <VirtualHost 192.168.1.12:80>% Q B4 t( `% r, [+ L
' h. m' R3 G: L& R t$ z; W
4 x7 t* q! ]7 S7 ~. M
- y3 F- G1 E) n& ~, ^ |