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
+ o; t) [& Q; r* W {# Q, p
2. 找到 # VirtualHost example:
+ G; P* k: G3 Z" ~
其下加入你的virtual server 設定,例如:
7 e& F; q* h; _$ t2 L) j% Y. P$ c
#2014/10/02 add
' U& I& y& |! l
<VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解
4 g' h. \% {# d' }$ [; g
ServerAdmin
[email protected]
/ A$ J+ g; `8 s4 i6 c _6 S; m
DocumentRoot /home/coav4u/public_html
, {% Y9 y l) b7 B
ServerName av4u.co
/ z9 T. K8 _1 Y* H! f- h
ErrorLog logs/www.av4u.co-error_log
H( C; I4 _* `$ J: D
CustomLog logs/www.av4u.co-access_log common
U0 T8 Y; N1 g7 }3 R) w3 p
</VirtualHost>
8 G" t( ~, X& \: H8 k- J. l# L
<VirtualHost 192.168.1.12:80>
1 b% O7 _1 a2 O; C# u# Y
ServerAdmin
[email protected]
2 i% n, T# Y( U' I/ a7 @: B
DocumentRoot /home/coav4u/public_html
7 H2 _5 P8 Y9 u3 L9 `6 t9 R6 J
ServerName www.av4u.co
# h+ ^7 ~8 W$ P1 N: h+ o9 ?- j; E& K
ErrorLog logs/www.av4u.co-error_log
( L; y2 |% i. T% ?$ `# V; \& b
CustomLog logs/www.av4u.co-access_log common
$ _$ t/ }% t' G0 C
</VirtualHost>
複製代碼
可同時指定2個 Domain
name (av4u.com及
www.av4u.com
)到同一個虛擬空間,這個部分似乎比 nginx 設定稍微麻煩一點
$ _# M& |! t$ V) T# D$ p# h- n
3. 重啟 Apache 才生效
; J2 A) {6 f& ?8 r
service httpd restart #須以root身分 --->搞定
2 h$ @- y6 u- ]/ N+ y9 S' o
註: service httpd start #啟動
8 H% @) |- N$ z5 X# G
service httpd start #停止
% k; h$ i+ I C4 j' ?1 Z# ^5 W/ F7 y* G
〖
方法二
〗
7 D) A4 Q D; y0 k/ [( j
在/etc/httpd/conf.d/新ˋ建一獨立檔(設定一個virtual host)
4 k) b- [- h* Y2 F
例如:
. _' y8 E* N+ ~
virtual1.conf
2 \- F$ v: ~! j: Y4 C- ?* \# @
<VirtualHost 192.168.1.12:80> #或 <VirtualHost 127.0.0.1:80> #符號為註解
- C+ V$ p5 F! v6 F$ r5 W8 B& D
ServerAdmin
[email protected]
) |& {" u( {7 k, Z4 |7 D* j
DocumentRoot /home/coav4u/public_html
P. _. O# q y! K& `7 W4 H, B
ServerName av4u.co
& A' ^$ V- B/ b; c6 M b
ErrorLog logs/www.av4u.co-error_log
' v4 q! T/ o! P
CustomLog logs/www.av4u.co-access_log common
, q: z g2 T2 S
</VirtualHost>
複製代碼
virtual2.conf
2 z: }+ k. @7 A/ ~; v
<VirtualHost 192.168.1.12:80>
8 C7 M& `) s) y' |; p- y Y
ServerAdmin
[email protected]
5 e' B! j8 F% H( o0 K
DocumentRoot /home/coav4u/public_html
5 Q" F' V' q3 N& u
ServerName www.av4u.co
* {2 o4 _7 Z" G" O' A& Z, G
ErrorLog logs/www.av4u.co-error_log
; U5 s* |5 O W3 x2 c
CustomLog logs/www.av4u.co-access_log common
+ Q d$ }; q6 m% f
</VirtualHost>
複製代碼
存檔然後重啟 httpd
2 K4 `- x' E( l3 C$ V2 I
但是出現 error:
( Q6 I/ U8 i9 u, {2 k" C, V' i
[warn] _default_ VirtualHost overlap on port 80, the first has precedence
$ V$ K5 b* y- }- ^: p
SOL:
; V1 d) A w l' e. E5 g
由於 /etc/httpd/conf/httpd.conf 內 NameVirtualHost *:80 而 virtual1.conf及virtual2.conf 內都設定為
<VirtualHost 192.168.1.12:80> 不匹配,正確的設定為:
9 c% L+ m$ ~9 r) T1 {% r% C
httpd.conf 及
virtual1.conf及virtual2.conf(所有虛擬主機的設定檔)不是都為
*:80 就是都為
192.168.1.12:80 即
& W# } G6 ]5 f
httpd.conf ===>
NameVirtualHost *:80 ,
virtual1.conf及virtual2.conf ===>
<VirtualHost *:80> 或者
+ b# |6 ]5 q7 F
httpd.conf ===>
NameVirtualHost 192.168.1.12:80 ,
virtual1.conf及virtual2.conf ===>
<VirtualHost 192.168.1.12:80>
: d: R. | `+ H. ?0 B
4 g& Z8 z: q. d0 R8 ]! K
* `( N. Y8 ?0 b" s: R
5 v+ T/ m4 L/ A1 o& j2 p7 x
歡迎光臨 52AV手機A片王|52AV.ONE (https://nhkie.com/)
Powered by Discuz! X3.2