52AV手機A片王|52AV.ONE
標題:
Apache 如何設定多個虛擬伺服器(Virtual Server)
[打印本頁]
作者:
IT_man
時間:
2014-10-3 10:29
標題:
Apache 如何設定多個虛擬伺服器(Virtual Server)
我的環境是 <Linux CENTOS 6 + Apache + mysql>
〖方法一〗
1. vi /etc/httpd/httpd.conf
1 N* L! }9 j' P" [% n( k
2. 找到 # VirtualHost example:
# P2 o! `, [, g
其下加入你的virtual server 設定,例如:
5 C+ o; \$ v1 u% n
#2014/10/02 add
# S1 r8 V, \1 ]
<VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解
* c: T( h: H* A0 @! p# h8 M/ g ?
ServerAdmin root@av4u.com
0 e$ k/ {6 l1 k" \0 U! n! }4 N
DocumentRoot /home/coav4u/public_html
4 U, ^# Q' c7 O- d( W
ServerName av4u.co
! n6 l Z& U% o6 e$ k s
ErrorLog logs/www.av4u.co-error_log
+ D# R% h i& Y% k' P
CustomLog logs/www.av4u.co-access_log common
. ~! d8 q/ \5 [# [* o) h" q
</VirtualHost>
; ~; x" { w9 r3 U P& {/ E
<VirtualHost 192.168.1.12:80>
5 k0 v# r! J) x& f. H; p+ `3 A! E
ServerAdmin root@av4u.com
6 t3 v! P& K0 S: |; d
DocumentRoot /home/coav4u/public_html
: C5 C0 v2 I, w* [' U- `4 E
ServerName www.av4u.co
; y- Q5 p, L! m8 F" \" H" i
ErrorLog logs/www.av4u.co-error_log
3 g1 F0 \0 S6 q& L0 j4 P
CustomLog logs/www.av4u.co-access_log common
" O! L, g6 j6 P6 c
</VirtualHost>
複製代碼
可同時指定2個 Domain
name (av4u.com及
www.av4u.com
)到同一個虛擬空間,這個部分似乎比 nginx 設定稍微麻煩一點
& U, k% f, I! s) T3 F5 t5 C" q, M2 j$ k6 Q
3. 重啟 Apache 才生效
" E; i2 V5 a) ]. H
service httpd restart #須以root身分 --->搞定
4 t6 E) y4 }& u0 G [' P8 u
註: service httpd start #啟動
. M, X, a2 Y' o. n2 M4 A" U
service httpd start #停止
. J R$ W. H3 D& e' D% {
〖
方法二
〗
0 [; b0 {+ k5 J a
在/etc/httpd/conf.d/新ˋ建一獨立檔(設定一個virtual host)
& q, g" n( H6 _4 A/ _" R, [ N
例如:
1 E. }8 |0 f# C3 Y5 V
virtual1.conf
( Q9 @. S. n8 \9 a4 B
<VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解
7 P/ N; I% X+ \
ServerAdmin root@av4u.com
8 g* c" ?. S8 Y- C' T9 x
DocumentRoot /home/coav4u/public_html
+ `& v7 ^5 M/ c* x) p2 p; N* r1 \
ServerName av4u.co
3 x% {, N/ p/ L1 o3 U
ErrorLog logs/www.av4u.co-error_log
) u) W6 o* d6 W/ x' K* F
CustomLog logs/www.av4u.co-access_log common
* L' x$ e/ u' s9 g4 f
</VirtualHost>
複製代碼
virtual2.conf
' {, U" v; g& K
<VirtualHost 192.168.1.12:80>
9 k& K9 c# u: j4 l
ServerAdmin root@av4u.com
) ]9 P2 J2 z& M' e0 e$ i
DocumentRoot /home/coav4u/public_html
N3 Z5 D* r' a3 p! z3 J* z: |
ServerName www.av4u.co
3 Y* C1 U% z( d$ g; k
ErrorLog logs/www.av4u.co-error_log
& L$ x' I" T; {# W* L
CustomLog logs/www.av4u.co-access_log common
3 f( y; f& t" \
</VirtualHost>
複製代碼
存檔然後重啟 httpd
2 \; L; ]4 k8 d8 A/ F8 \+ {6 W
但是出現 error:
; y- _% D, n# q8 m% S4 H2 l
[warn] _default_ VirtualHost overlap on port 80, the first has precedence
& C! E" A% k* b4 t9 ~2 J
SOL:
$ a+ H) V# L5 w: q1 l
由於 /etc/httpd/conf/httpd.conf 內 NameVirtualHost *:80 而 virtual1.conf及virtual2.conf 內都設定為
<VirtualHost 192.168.1.12:80> 不匹配,正確的設定為:
( k J! x% V- S7 F1 u
httpd.conf 及
virtual1.conf及virtual2.conf(所有虛擬主機的設定檔)不是都為
*:80 就是都為
192.168.1.12:80 即
7 Y* e+ J- F- f M
httpd.conf ===>
NameVirtualHost *:80 ,
virtual1.conf及virtual2.conf ===>
<VirtualHost *:80> 或者
+ h z5 ^% L: m# S5 ^9 ?4 z
httpd.conf ===>
NameVirtualHost 192.168.1.12:80 ,
virtual1.conf及virtual2.conf ===>
<VirtualHost 192.168.1.12:80>
- g, C# M* Q& t& d: y/ H) o6 @6 ~, a
! V; y% g+ Y; q
; [2 g: ]5 s( J- u
+ S& L* ]. X% w6 C% B
歡迎光臨 52AV手機A片王|52AV.ONE (https://www.52av.one/)
Powered by Discuz! X3.2