|
tid=1&我的環境是 <Linux CENTOS 6 + Apache + mysql> 〖方法一〗 1. vi /etc/httpd/httpd.conf
3 ^7 Z# N4 t7 }! w. {2. 找到 # VirtualHost example:2 Y7 ~: e1 f4 R% M
- 其下加入你的virtual server 設定,例如:& q! C$ \( q. c$ a6 r/ h4 ~
- #2014/10/02 add
$ O1 F: A8 w+ n- N9 b) A9 u* s* T& T - <VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解
6 t/ c: z4 |$ ^& X' T - ServerAdmin root@av4u.com
7 [ f* p) X" D& s" s2 W - DocumentRoot /home/coav4u/public_html$ Y4 d0 l1 W- K7 {
- ServerName av4u.co- f0 Z' L* r' x1 y! o) b. q( P
- ErrorLog logs/www.av4u.co-error_log+ |; ?+ |! V" h9 M* F
- CustomLog logs/www.av4u.co-access_log common
) p) ?- f! @. m - </VirtualHost>, l$ q6 E6 ~5 r
- <VirtualHost 192.168.1.12:80>" w9 q8 Y5 C0 Q7 ?3 Q
- ServerAdmin root@av4u.com7 ?) q |1 V7 x1 m' X1 P
- DocumentRoot /home/coav4u/public_html
- }' L) I1 P6 x+ i! O. N - ServerName www.av4u.co
`# [9 U' G5 ?) M - ErrorLog logs/www.av4u.co-error_log
& s' G8 B& q5 g/ } - CustomLog logs/www.av4u.co-access_log common4 l5 h! {, T0 L
- </VirtualHost>
複製代碼 可同時指定2個 Domain name (av4u.com及www.av4u.com)到同一個虛擬空間,這個部分似乎比 nginx 設定稍微麻煩一點* y( F+ g6 }9 y3 a6 r0 U
3. 重啟 Apache 才生效5 F+ d% G: U# d2 N; D5 r
service httpd restart #須以root身分 --->搞定
8 e- b6 C( u0 t/ |1 ]; q$ p8 T4 c, y 註: service httpd start #啟動
% ~" n" w9 Y* r9 g; V! y service httpd start #停止
7 V/ G2 @ u3 R; e〖方法二〗
: k9 I9 I6 y/ n4 g$ K% ^3 s1 }在/etc/httpd/conf.d/新ˋ建一獨立檔(設定一個virtual host)
8 M i0 d) R: }7 O' P+ F, p例如: 0 c# r. b& W# w) x: E+ G% T
virtual1.conf$ ~- v/ d0 {1 y# j9 d
- <VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解
1 I1 W9 [4 c' t* { - ServerAdmin root@av4u.com! F! `- O( l, f9 Y7 i8 ^0 i
- DocumentRoot /home/coav4u/public_html! O9 H3 L, k$ P& T
- ServerName av4u.co
1 P% \! R- Y2 [1 }, ^- _$ W - ErrorLog logs/www.av4u.co-error_log, \4 z7 `% m* o1 a
- CustomLog logs/www.av4u.co-access_log common
: G: p. j: m+ k) m: i7 v - </VirtualHost>
複製代碼 virtual2.conf
3 _# u% t: ]$ d6 g- <VirtualHost 192.168.1.12:80>7 E# w) g, ?; \; o* F* \3 j8 `
- ServerAdmin root@av4u.com
/ S5 Y4 b) G7 Y/ O - DocumentRoot /home/coav4u/public_html2 ? i h- k& ?4 }: w8 u
- ServerName www.av4u.co
' D1 n1 l2 z- s+ [$ L - ErrorLog logs/www.av4u.co-error_log! p# X4 U' s. D1 b. ?
- CustomLog logs/www.av4u.co-access_log common
d1 \) T* }: d3 v - </VirtualHost>
複製代碼 存檔然後重啟 httpd! T% \( m. m# Z) V9 M& }
但是出現 error:
E& I* P( f+ M5 ?' m [warn] _default_ VirtualHost overlap on port 80, the first has precedence( u9 _' N E) B5 \
SOL:
% u" c+ J- J# p' e+ P. W% X U+ a( v由於 /etc/httpd/conf/httpd.conf 內 NameVirtualHost *:80 而 virtual1.conf及virtual2.conf 內都設定為 <VirtualHost 192.168.1.12:80> 不匹配,正確的設定為:) d7 G0 G3 f) S @. A5 }
httpd.conf 及 virtual1.conf及virtual2.conf(所有虛擬主機的設定檔)不是都為 *:80 就是都為 192.168.1.12:80 即- A1 `0 _- I% |6 |/ e6 s. j4 U
httpd.conf ===> NameVirtualHost *:80 , virtual1.conf及virtual2.conf ===> <VirtualHost *:80> 或者
: b4 I' X8 M% m5 \7 {# w1 ~httpd.conf ===> NameVirtualHost 192.168.1.12:80 , virtual1.conf及virtual2.conf ===> <VirtualHost 192.168.1.12:80>
' w4 d/ z; o+ L) x/ l) J" w0 F" l1 h0 w; q+ q5 O# d5 }, {
4 d! E" ]" H* O% C# Q
, M) n c2 W3 T8 i/ x4 B' h |