Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
<?xml version="1.0" encoding="EUC-KR"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ko" xml:lang="ko"><head>
<meta content="text/html; charset=EUC-KR" http-equiv="Content-Type" />
<!--
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
This file is generated from xml source: DO NOT EDIT
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-->
<title>가상호스트 예 - Apache HTTP Server Version 2.4</title>
<link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
<link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
<script src="../style/scripts/prettify.min.js" type="text/javascript">
</script>
<link href="../images/favicon.ico" rel="shortcut icon" /></head>
<body id="manual-page"><div id="page-header">
<p class="menu"><a href="../mod/">모듈</a> | <a href="../mod/directives.html">지시어들</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">용어</a> | <a href="../sitemap.html">사이트맵</a></p>
<p class="apache">Apache HTTP Server Version 2.4</p>
<img alt="" src="../images/feather.png" /></div>
<div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
<div id="path">
<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.4</a> > <a href="./">가상호스트</a></div><div id="page-content"><div id="preamble"><h1>가상호스트 예</h1>
<div class="toplang">
<p><span>가능한 언어: </span><a href="../en/vhosts/examples.html" hreflang="en" rel="alternate" title="English"> en </a> |
<a href="../fr/vhosts/examples.html" hreflang="fr" rel="alternate" title="Français"> fr </a> |
<a href="../ja/vhosts/examples.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
<a href="../ko/vhosts/examples.html" title="Korean"> ko </a> |
<a href="../tr/vhosts/examples.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
</div>
<div class="outofdate">이 문서는 최신판 번역이 아닙니다.
최근에 변경된 내용은 영어 문서를 참고하세요.</div>
<p>이 문서는 자주 문의되는 가상호스트
질문에 답을 하려고 쓰여졌다. 상황은 <a href="name-based.html">이름기반</a>이나 <a href="ip-based.html">IP기반</a> 가상호스트를 통해 한 서버에서
여러 웹사이트를 서비스하려는 경우이다. 한 프록시 서버 뒤에서
여러 서버를 사용하여 사이트를 운영하는 경우를 다룬 문서도
곧 나올 것이다.</p>
</div>
<div id="quickview"><a href="https://www.apache.org/foundation/contributing.html" class="badge"><img src="https://www.apache.org/images/SupportApache-small.png" alt="Support Apache!" /></a><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#purename">IP 주소 한개에 여러 이름기반
웹사이트 운영하기.</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#twoips">여러 IP 주소에서 이름기반
호스트.</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#intraextra">(내부와 외부 주소와 같이)
다른 IP 주소로 같은 내용을 서비스하기.</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#port">여러 포트에서 서로 다른 사이트
운영하기.</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#ip">IP기반 가상호스트</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#ipport">포트기반과 ip기반이 혼합된
가상호스트</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#mixed">이름기반과 IP기반이 혼합된
가상호스트</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#default"><code>_default_</code> 가상호스트
사용하기</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#migrate">이름기반 가상호스트를 IP기반
가상호스트로 옮기기</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#serverpath"><code>ServerPath</code>
지시어 사용하기</a></li>
</ul><h3>참고</h3><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="purename" id="purename">IP 주소 한개에 여러 이름기반
웹사이트 운영하기.</a></h2>
<p>서버에 IP 주소가 한개 있고, DNS에서 여러 주소(CNAMES)가
이 컴퓨터를 가리킨다. 이 컴퓨터에서 <code>www.example.com</code>과
<code>www.example.org</code>의 웹서버를 실행하고 싶다.</p>
<div class="note"><h3>Note</h3><p>아파치 서버에 가상호스트 설정을
한다고 그 호스트명에 대한 DNS 항목이 자동이로 생성되지
않는다. <em>반드시</em> DNS에 IP 주소를 가리키는
이름이 있어야 한다. 안그러면 아무도 웹사이트를 볼
수 없다. 검사해보기 위해 <code>hosts</code> 파일에 항목을
추가할 수 있지만, 이는 hosts 항목을 가진 컴퓨터에만
반영된다.</p>
</div>
<div class="example"><h3>서버 설정</h3><p><code>
# 아파치가 포트 80을 기다린다<br />
Listen 80<br />
<br />
# 모든 IP 주소에서 가상호스트 요청을 기다린다<br />
NameVirtualHost *:80<br />
<br />
<VirtualHost *:80><br />
<span class="indent">
DocumentRoot /www/example1<br />
ServerName www.example.com<br />
<br />
# 다른 지시어들도 있다<br />
<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost *:80><br />
<span class="indent">
DocumentRoot /www/example2<br />
ServerName www.example.org<br />
<br />
# 다른 지시어들도 있다<br />
<br />
</span>
</VirtualHost>
</code></p></div>
<p>별표는 모든 주소를 가리키므로, 주서버는 어떤 요청도
서비스하지 않는다. <code>www.example.com</code>이
설정파일에 처음으로 나오므로 가장 높은 우선순위를 가지며,
<cite>기본</cite>혹은 <cite>초기</cite> 서버가 된다.
어떤 <code>ServerName</code> 지시어에도 해당되지않는 요청은
첫번째 <code>VirtualHost</code>가 서비스한다.</p>
<div class="note">
<h3>주의</h3>
<p>원한다면 <code>*</code> 대신 시스템의 실제 IP
주소를 사용할 수 있다. 이 경우
<code>VirtualHost</code>의 아규먼트는
<code>NameVirtualHost</code>의 아규먼트와 일치해야
<em>한다</em>:</p>
<div class="example"><p><code>
NameVirtualHost 172.20.30.40<br />
<br />
<VirtualHost 172.20.30.40><br />
# 생략 ...
</code></p></div>
<p>그러나 ISP에서 동적으로 IP 주소를 가져오는 등
IP 주소를 모르는 경우에는 <code>*</code>를 사용하는
것이 유용하다. <code>*</code>는 모든 IP 주소에
해당하므로, IP 주소가 변경되어도 설정을 변경할
필요가 없다.</p>
</div>
<p>거의 대부분의 이름기반 가상호스트 설정은 위와 같다.
예외는 다른 IP 주소나 포트로 다른 내용을 서비스하려는
경우이다.</p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="twoips" id="twoips">여러 IP 주소에서 이름기반
호스트.</a></h2>
<div class="note">
<h3>주의</h3><p>여기서 설명한 방법은 IP 주소가
몇개라도 적용가능하다.</p>
</div>
<p>서버는 IP 주소가 두개있다. 하나에서
(<code>172.20.30.40</code>) "주" 서버
<code>server.domain.com</code>을 서비스하고, 다른 하나에서
(<code>172.20.30.50</code>) 여러 가상호스트를 서비스할
것이다.</p>
<div class="example"><h3>서버 설정</h3><p><code>
Listen 80<br />
<br />
# 172.20.30.40에서 실행하는 "주"서버이다<br />
ServerName server.domain.com<br />
DocumentRoot /www/mainserver<br />
<br />
# 다른 주소다<br />
NameVirtualHost 172.20.30.50<br />
<br />
<VirtualHost 172.20.30.50><br />
<span class="indent">
DocumentRoot /www/example1<br />
ServerName www.example.com<br />
<br />
# 다른 지시어들도 있다 ...<br />
<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost 172.20.30.50><br />
<span class="indent">
DocumentRoot /www/example2<br />
ServerName www.example.org<br />
<br />
# 다른 지시어들도 있다 ...<br />
<br />
</span>
</VirtualHost>
</code></p></div>
<p><code>172.20.30.50</code>이 아닌 주소에 대한 요청은
주서버가 서비스한다. 호스트명 없이, 즉 <code>Host:</code>
헤더없이 <code>172.20.30.50</code>로 요청하면
<code>www.example.com</code>이 서비스한다.</p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="intraextra" id="intraextra">(내부와 외부 주소와 같이)
다른 IP 주소로 같은 내용을 서비스하기.</a></h2>
<p>서버 컴퓨터에 IP 주소가 두개 (<code>192.168.1.1</code>과
<code>172.20.30.40</code>) 있다. 컴퓨터는 내부 (인트라넷)
네트웍과 외부 (인터넷) 네트웍 사이에 위치한다. 네트웍 밖에서
<code>server.example.com</code>은 외부 주소를
(<code>172.20.30.40</code>) 의미하고, 네트웍 내부에서 같은
이름을 내부 주소로 (<code>192.168.1.1</code>) 사용한다.</p>
<p>서버는 <code>VirtualHost</code> 섹션 한개로 내부와 외부
응답에 같은 내용을 서비스할 수 있다.</p>
<div class="example"><h3>서버 설정</h3><p><code>
NameVirtualHost 192.168.1.1<br />
NameVirtualHost 172.20.30.40<br />
<br />
<VirtualHost 192.168.1.1 172.20.30.40><br />
<span class="indent">
DocumentRoot /www/server1<br />
ServerName server.example.com<br />
ServerAlias server<br />
</span>
</VirtualHost>
</code></p></div>
<p>이제 두 네트웍에서 들어온 요청을 같은
<code>VirtualHost</code>에서 서비스한다.</p>
<div class="note">
<h3>주의:</h3><p>내부 네트웍에서는 완전한 호스트명
<code>server.example.com</code> 대신 이름
<code>server</code>도 가능하다.</p>
<p>또한 위의 예에서 IP 주소 대신 <code>*</code>을
사용하여 서버가 모든 주소에 동일하게 동작할 수
있다.</p>
</div>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="port" id="port">여러 포트에서 서로 다른 사이트
운영하기.</a></h2>
<p>같은 IP의 여러 포트에서 서로 다른 도메인을 서비스한다고
가정하자. 이는 "NameVirtualHost" 태그에 포트를 정의하면
가능하다. NameVirtualHost name:port없이 <VirtualHost
name:port>만 혹은 Listen 지시어만 사용하면 안된다.</p>
<div class="example"><h3>서버 설정</h3><p><code>
Listen 80<br />
Listen 8080<br />
<br />
NameVirtualHost 172.20.30.40:80<br />
NameVirtualHost 172.20.30.40:8080<br />
<br />
<VirtualHost 172.20.30.40:80><br />
<span class="indent">
ServerName www.example.com<br />
DocumentRoot /www/domain-80<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost 172.20.30.40:8080><br />
<span class="indent">
ServerName www.example.com<br />
DocumentRoot /www/domain-8080<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost 172.20.30.40:80><br />
<span class="indent">
ServerName www.example.org<br />
DocumentRoot /www/otherdomain-80<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost 172.20.30.40:8080><br />
<span class="indent">
ServerName www.example.org<br />
DocumentRoot /www/otherdomain-8080<br />
</span>
</VirtualHost>
</code></p></div>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="ip" id="ip">IP기반 가상호스트</a></h2>
<p>서버는 각각 <code>www.example.com</code>과
<code>www.example.org</code>에 해당하는 두 IP 주소를
(<code>172.20.30.40</code>과 <code>172.20.30.50</code>)
가진다.</p>
<div class="example"><h3>서버 설정</h3><p><code>
Listen 80<br />
<br />
<VirtualHost 172.20.30.40><br />
<span class="indent">
DocumentRoot /www/example1<br />
ServerName www.example.com<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost 172.20.30.50><br />
<span class="indent">
DocumentRoot /www/example2<br />
ServerName www.example.org<br />
</span>
</VirtualHost>
</code></p></div>
<p><code><VirtualHost></code> 지시어로 지정한 주소에
해당하지않는 주소로 (예를 들어, <code>localhost</code>)
요청이 들어오면 주서버가 있는 경우 주서버가 서비스한다.</p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="ipport" id="ipport">포트기반과 ip기반이 혼합된
가상호스트</a></h2>
<p>서버는 각각 <code>www.example.com</code>과
<code>www.example.org</code>에 해당하는 두 IP 주소를
(<code>172.20.30.40</code>과 <code>172.20.30.50</code>)
가진다. 각 IP의 80번과 8080번 포트에 가상호스트를 돌린다.</p>
<div class="example"><h3>서버 설정</h3><p><code>
Listen 172.20.30.40:80<br />
Listen 172.20.30.40:8080<br />
Listen 172.20.30.50:80<br />
Listen 172.20.30.50:8080<br />
<br />
<VirtualHost 172.20.30.40:80><br />
<span class="indent">
DocumentRoot /www/example1-80<br />
ServerName www.example.com<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost 172.20.30.40:8080><br />
<span class="indent">
DocumentRoot /www/example1-8080<br />
ServerName www.example.com<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost 172.20.30.50:80><br />
<span class="indent">
DocumentRoot /www/example2-80<br />
ServerName www.example.org<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost 172.20.30.50:8080><br />
<span class="indent">
DocumentRoot /www/example2-8080<br />
ServerName www.example.org<br />
</span>
</VirtualHost>
</code></p></div>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="mixed" id="mixed">이름기반과 IP기반이 혼합된
가상호스트</a></h2>
<p>주소중 몇몇은 이름기반 가상호스트로, 다른 것은 IP기반
가상호스트로 서비스하고 싶다.</p>
<div class="example"><h3>서버 설정</h3><p><code>
Listen 80<br />
<br />
NameVirtualHost 172.20.30.40<br />
<br />
<VirtualHost 172.20.30.40><br />
<span class="indent">
DocumentRoot /www/example1<br />
ServerName www.example.com<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost 172.20.30.40><br />
<span class="indent">
DocumentRoot /www/example2<br />
ServerName www.example.org<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost 172.20.30.40><br />
<span class="indent">
DocumentRoot /www/example3<br />
ServerName www.example3.net<br />
</span>
</VirtualHost><br />
<br />
# IP-기반<br />
<VirtualHost 172.20.30.50><br />
<span class="indent">
DocumentRoot /www/example4<br />
ServerName www.example4.edu<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost 172.20.30.60><br />
<span class="indent">
DocumentRoot /www/example5<br />
ServerName www.example5.gov<br />
</span>
</VirtualHost>
</code></p></div>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="default" id="default"><code>_default_</code> 가상호스트
사용하기</a></h2>
<h3><a name="defaultallports" id="defaultallports">모든 포트에 대한
<code>_default_</code> 가상호스트</a></h3>
<p>어떤 가상호스트에도 해당하지않은 IP 주소와 포트에 대한
<em>모든</em> 요청을 처리하기.</p>
<div class="example"><h3>서버 설정</h3><p><code>
<VirtualHost _default_:*><br />
<span class="indent">
DocumentRoot /www/default<br />
</span>
</VirtualHost>
</code></p></div>
<p>default(기본) 가상호스트의 포트로 와일드카드를 사용하여 어떤 요청도
주서버로 못가도록 만든다.</p>
<p>default 가상호스트는 절대로 이름기반 가상호스트가 사용하는
주소/포트로의 요청을 서비스하지 않는다. 알 수 없거나
<code>Host:</code> 헤더가 생략된 요청은 항상 최초의 이름기반
가상호스트(설정파일에서
주소/포트가 처음으로 나온 가상호스트)가 서비스한다.</p>
<p><code class="directive"><a href="../mod/mod_alias.html#aliasmatch">AliasMatch</a></code>나
<code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>을
사용하여 어떤 요청을 특정 페이지(혹은 스크립트)로
재작성할(rewrite) 수 있다.</p>
<h3><a name="defaultdifferentports" id="defaultdifferentports">여러 포트에 대한
<code>_default_</code> 가상호스트</a></h3>
<p>위의 경우와 같지만, 서버는 여러 포트를 기다리고 80번
포트에 대해서 추가로 <code>_default_</code> 가상호스트를
사용하고 싶다.</p>
<div class="example"><h3>서버 설정</h3><p><code>
<VirtualHost _default_:80><br />
<span class="indent">
DocumentRoot /www/default80<br />
# ...<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost _default_:*><br />
<span class="indent">
DocumentRoot /www/default<br />
# ...<br />
</span>
</VirtualHost>
</code></p></div>
<p>80번 포트에 대한 default 가상호스트는 (<em>반드시</em>
와일드카드 포트를 가진 기본 가상호스트 이전에 나와야 한다)
지정하지않은 IP 주소로 보내진 모든 요청을 서비스한다.
주서버는 절대로 요청을 서비스하지 못한다.</p>
<h3><a name="defaultoneport" id="defaultoneport">한 포트에 대한
<code>_default_</code> 가상호스트</a></h3>
<p>80번 포트에 대해서만 default 가상호스트를 만들고 싶다.</p>
<div class="example"><h3>서버 설정</h3><p><code>
<VirtualHost _default_:80><br />
DocumentRoot /www/default<br />
...<br />
</VirtualHost>
</code></p></div>
<p>포트 80번에 지정하지않은 주소에 대한 요청은 기본
가상호스트가 서비스하고, 다른 지정하지않은 주소와 포트를
가진 요청은 주 서버가 서비스한다.</p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="migrate" id="migrate">이름기반 가상호스트를 IP기반
가상호스트로 옮기기</a></h2>
<p>(<a href="#name">이름기반</a>의 첫번째 예에서) 호스트명
<code>www.example.org</code>에 대한 이름기반 가상호스트는
자신의 IP 주소를 가져야 한다. 이름기반 가상호스트의 이전
IP 주소를 캐싱하는 네임서버나 프록시와의 문제를 피하기위해
옮기는 동안 둘 모두를 서비스하고 싶다.</p>
<p>
방법은 <code>VirtualHost</code> 지시어에 새 IP 주소만을
(<code>172.20.30.50</code>) 추가하면되므로 쉽다.</p>
<div class="example"><h3>서버 설정</h3><p><code>
Listen 80<br />
ServerName www.example.com<br />
DocumentRoot /www/example1<br />
<br />
NameVirtualHost 172.20.30.40<br />
<br />
<VirtualHost 172.20.30.40 172.20.30.50><br />
<span class="indent">
DocumentRoot /www/example2<br />
ServerName www.example.org<br />
# ...<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost 172.20.30.40><br />
<span class="indent">
DocumentRoot /www/example3<br />
ServerName www.example.net<br />
ServerAlias *.example.net<br />
# ...<br />
</span>
</VirtualHost>
</code></p></div>
<p>이제 (IP기반 가상호스트를 통한) 새로운 주소와 (이름기반
가상호스트를 통한) 이전 주소 모두 가상호스트에 접근할
수 있다.</p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="serverpath" id="serverpath"><code>ServerPath</code>
지시어 사용하기</a></h2>
<p>두 이름기반 가상호스트를 가진 서버가 있다. 올바른
가상호스트를 선택하기위해 클라이언트는 올바른
<code>Host:</code> 헤더를 보내야 한다. 오래된 HTTP/1.0
클라이언트가 이 헤더를 보내지 못하면 아파치는 클라이언트가
어떤 가상호스트를 보려고하는지 알 수 없다 (그래서 최초의
가상호스트가 요청을 서비스한다). 오래된 브라우저와 가능한 호환을
유지하기위해 최초의 가상호스트를 만들고, 여기에 이름기반
가상호스트의 URL 접두사를 포함하는 링크 목록 페이지를
둔다.</p>
<div class="example"><h3>서버 설정</h3><p><code>
NameVirtualHost 172.20.30.40<br />
<br />
<VirtualHost 172.20.30.40><br />
<span class="indent">
# primary vhost<br />
DocumentRoot /www/subdomain<br />
RewriteEngine On<br />
RewriteRule ^/.* /www/subdomain/index.html<br />
# ...<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost 172.20.30.40><br />
DocumentRoot /www/subdomain/sub1<br />
<span class="indent">
ServerName www.sub1.domain.tld<br />
ServerPath /sub1/<br />
RewriteEngine On<br />
RewriteRule ^(/sub1/.*) /www/subdomain$1<br />
# ...<br />
</span>
</VirtualHost><br />
<br />
<VirtualHost 172.20.30.40><br />
<span class="indent">
DocumentRoot /www/subdomain/sub2<br />
ServerName www.sub2.domain.tld<br />
ServerPath /sub2/<br />
RewriteEngine On<br />
RewriteRule ^(/sub2/.*) /www/subdomain$1<br />
# ...<br />
</span>
</VirtualHost>
</code></p></div>
<p><code class="directive"><a href="../mod/core.html#serverpath">ServerPath</a></code> 지시어때문에
URL <code>http://www.sub1.domain.tld/sub1/</code>에 대한
요청은 <em>항상</em> subl-가상호스트가 서비스한다.<br />
클라이언트가 올바른 <code>Host:</code> 헤더를 보낸다면,
URL <code>http://www.sub1.domain.tld/</code>에 대한 요청은
subl-가상호스트에서만 서비스한다. 만약 <code>Host:</code> 헤더를
보내지않으면 클라이언트는 최초의 호스트에 있는 정보페이지를
보게된다.</p>
<p>여기에 문제가 있음을 주의하라: 클라이언트가
<code>Host:</code> 헤더를 보내지않으면
<code>http://www.sub2.domain.tld/sub1/</code>에 대한 요청도
subl-가상호스트가 서비스한다.</p>
<p><code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>
지시어를 사용하여 올바른 <code>Host:</code> 헤더를 보내는
클라이언트는 (<em>예를 들어</em>, URL 전치사가 있거나 없는)
두 URL을 모두 사용할 수 있다.</p>
</div></div>
<div class="bottomlang">
<p><span>가능한 언어: </span><a href="../en/vhosts/examples.html" hreflang="en" rel="alternate" title="English"> en </a> |
<a href="../fr/vhosts/examples.html" hreflang="fr" rel="alternate" title="Français"> fr </a> |
<a href="../ja/vhosts/examples.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
<a href="../ko/vhosts/examples.html" title="Korean"> ko </a> |
<a href="../tr/vhosts/examples.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
</div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
<script type="text/javascript"><!--//--><![CDATA[//><!--
var comments_shortname = 'httpd';
var comments_identifier = 'http://httpd.apache.org/docs/2.4/vhosts/examples.html';
(function(w, d) {
if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
d.write('<div id="comments_thread"><\/div>');
var s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
(d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
}
else {
d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
}
})(window, document);
//--><!]]></script></div><div id="footer">
<p class="apache">Copyright 2017 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
<p class="menu"><a href="../mod/">모듈</a> | <a href="../mod/directives.html">지시어들</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">용어</a> | <a href="../sitemap.html">사이트맵</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
if (typeof(prettyPrint) !== 'undefined') {
prettyPrint();
}
//--><!]]></script>
</body></html>