|
tid=1&我的環境是 <Linux CENTOS 6 + Apache + mysql> 〖方法一〗 1. vi /etc/httpd/httpd.conf
, b1 |5 b7 k% J. N- P2. 找到 # VirtualHost example:+ |$ A% T# e& E1 M
- 其下加入你的virtual server 設定,例如:$ x4 y% ~9 U: u) ]1 q: ?- N+ e- `
- #2014/10/02 add% n! G$ G- t' R9 ]5 m" f0 _; @2 x; e$ K
- <VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解$ z# M" e1 y8 L( F/ Y
- ServerAdmin root@av4u.com8 S2 Q7 o9 m; h1 F. Q1 X/ f( E% q- K( C* I
- DocumentRoot /home/coav4u/public_html
$ F- B- ~ a+ J, S/ d! c* l - ServerName av4u.co
- e; G6 r2 d; S5 d T - ErrorLog logs/www.av4u.co-error_log
% b8 M) K1 G* Z3 G2 g$ s9 H. U - CustomLog logs/www.av4u.co-access_log common
* }; q5 p8 G/ }. C, W# W - </VirtualHost>
; t. F5 [8 R9 q. ^ - <VirtualHost 192.168.1.12:80>
& g+ [) O+ b/ ~5 U; i/ c - ServerAdmin root@av4u.com
$ {, l( v) g) x9 i - DocumentRoot /home/coav4u/public_html
; z/ r0 E( l9 A0 G5 |7 z I - ServerName www.av4u.co
5 D+ R6 G8 w* a6 R% r6 F - ErrorLog logs/www.av4u.co-error_log% X2 p5 S: O6 I" w& @( B4 l
- CustomLog logs/www.av4u.co-access_log common
4 ^* v! Y5 {* @8 d1 } - </VirtualHost>
複製代碼 可同時指定2個 Domain name (av4u.com及www.av4u.com)到同一個虛擬空間,這個部分似乎比 nginx 設定稍微麻煩一點. @2 a; i& \' W2 ? d c
3. 重啟 Apache 才生效
% a/ g) n) g9 @4 P service httpd restart #須以root身分 --->搞定
. F) r4 J% e& V# H: Q 註: service httpd start #啟動 $ {9 J. ^1 |3 d" H" }! g: s* ^
service httpd start #停止 W0 _/ g& B E% ^+ q7 e
〖方法二〗
2 X: m: t/ d, d4 p+ {5 r1 X! U( K在/etc/httpd/conf.d/新ˋ建一獨立檔(設定一個virtual host)0 v4 J. f6 R- R
例如: 3 l! ]( ?( N7 W3 e: z
virtual1.conf; t& T4 b: ?& }; p( ?) Y8 C ?
- <VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解3 j9 ~" y7 C. n: W K# F. N' Q
- ServerAdmin root@av4u.com$ E& m, K4 G$ H9 F, z; ~& h$ O
- DocumentRoot /home/coav4u/public_html" U+ k" v* s3 j
- ServerName av4u.co2 f' V; K, ~' p+ M
- ErrorLog logs/www.av4u.co-error_log6 e$ L# L) j2 V
- CustomLog logs/www.av4u.co-access_log common
$ r+ {$ Q+ A. J N! N - </VirtualHost>
複製代碼 virtual2.conf
* b* s/ x0 f/ o- <VirtualHost 192.168.1.12:80>% k3 G |/ a& \& ^! Z0 f1 c
- ServerAdmin root@av4u.com7 k' i$ V% j2 y' W" H. u
- DocumentRoot /home/coav4u/public_html+ [& S& X- e8 Q% S- m% s
- ServerName www.av4u.co6 w5 l7 h) u8 h4 a. Q5 e
- ErrorLog logs/www.av4u.co-error_log: Q: Q5 o$ p' J4 [# g
- CustomLog logs/www.av4u.co-access_log common3 d+ j5 o6 g% [! v5 h2 c' n! q
- </VirtualHost>
複製代碼 存檔然後重啟 httpd- @; h0 v; Q+ U) ?; v/ U
但是出現 error:
7 ^/ j. o+ U. n$ l [warn] _default_ VirtualHost overlap on port 80, the first has precedence
5 X; M9 L" l/ [$ n+ U5 H( dSOL:
1 J! N9 b8 [ ?( I n由於 /etc/httpd/conf/httpd.conf 內 NameVirtualHost *:80 而 virtual1.conf及virtual2.conf 內都設定為 <VirtualHost 192.168.1.12:80> 不匹配,正確的設定為:
+ o7 ?1 I; P8 R% xhttpd.conf 及 virtual1.conf及virtual2.conf(所有虛擬主機的設定檔)不是都為 *:80 就是都為 192.168.1.12:80 即
. D* H ^- K. k. S0 R6 R5 `httpd.conf ===> NameVirtualHost *:80 , virtual1.conf及virtual2.conf ===> <VirtualHost *:80> 或者 ( Y; l/ o7 \* p3 x# o# O) _! a
httpd.conf ===> NameVirtualHost 192.168.1.12:80 , virtual1.conf及virtual2.conf ===> <VirtualHost 192.168.1.12:80>1 \6 M7 n! P) V) Z, L
+ c$ ^& C8 l# V' |7 R; i0 o
9 @7 k$ _. C/ u
( J/ l3 s7 v, T$ i% S
|