Tập lệnh ví dụ này sẽ tạo tệp cấu hình apache mới cho máy chủ ảo. Đầu tiên, nó thêm một chỉ thị
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...2 và sau đó là phần máy chủ ảo chứa các cài đặt của nó
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...3
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...4
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...5
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...6
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...7
Tập tin cấu hình được tạo
# My virtual host DocumentRoot /usr/share/www ServerName my-pear.example.org
Đọc một tập tin cấu hình hiện có
Nhiệm vụ của chúng ta là mở tệp cấu hình Apache hiện có và trích xuất tất cả các chỉ thị
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...2 từ tệp đó, sử dụng phương thức getItem của vùng chứa
Tài liệu này cố gắng trả lời các câu hỏi thường gặp về việc thiết lập máy chủ ảo. Các tình huống này là những tình huống liên quan đến nhiều trang web chạy trên một máy chủ, thông qua các máy chủ ảo dựa trên tên hoặc dựa trên IP
Xem thêm
Máy chủ của bạn có nhiều tên máy chủ phân giải thành một địa chỉ duy nhất và bạn muốn phản hồi khác nhau cho
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...3 và
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...4
Ghi chú
Tạo cấu hình máy chủ ảo trên máy chủ Apache của bạn không tạo ra các mục nhập DNS cho các tên máy chủ đó một cách kỳ diệu. Bạn phải có tên trong DNS, phân giải thành địa chỉ IP của bạn, nếu không không ai khác có thể xem trang web của bạn. Bạn có thể đưa các mục nhập vào tệp
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...5 của mình để thử nghiệm cục bộ, nhưng điều đó sẽ chỉ hoạt động từ máy có các mục nhập
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...5 đó
# Ensure that Apache listens on port 80 Listen 80 DocumentRoot "/www/example1" ServerName www.example.com # Other directives here DocumentRoot "/www/example2" ServerName www.example.org # Other directives here
Dấu hoa thị khớp với tất cả các địa chỉ, vì vậy máy chủ chính không phục vụ yêu cầu nào. Do máy chủ ảo có
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...7 xuất hiện đầu tiên trong tệp cấu hình nên nó có mức độ ưu tiên cao nhất và có thể được coi là máy chủ mặc định hoặc máy chủ chính. Điều đó có nghĩa là nếu nhận được yêu cầu không khớp với một trong các chỉ thị của
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...8 đã chỉ định, thì yêu cầu đó sẽ được phục vụ bởi
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...9 đầu tiên này
Cấu hình trên là những gì bạn sẽ muốn sử dụng trong hầu hết các tình huống lưu trữ ảo dựa trên tên. Trên thực tế, điều duy nhất mà cấu hình này sẽ không hoạt động là khi bạn đang phục vụ các nội dung khác nhau dựa trên các địa chỉ IP hoặc cổng khác nhau
Ghi chú
Bạn có thể thay thế
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server0 bằng một địa chỉ IP cụ thể trên hệ thống. Các máy chủ ảo như vậy sẽ chỉ được sử dụng cho các yêu cầu HTTP nhận được khi kết nối với địa chỉ IP được chỉ định
Tuy nhiên, cũng rất hữu ích khi sử dụng
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server0 trên các hệ thống không thể dự đoán được địa chỉ IP - ví dụ: nếu bạn có địa chỉ IP động với ISP của mình và bạn đang sử dụng một số giải pháp DNS động. Vì
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server0 khớp với bất kỳ địa chỉ IP nào nên cấu hình này sẽ hoạt động mà không cần thay đổi bất cứ khi nào địa chỉ IP của bạn thay đổi
Ghi chú
Bất kỳ kỹ thuật nào được thảo luận ở đây đều có thể được mở rộng cho bất kỳ số lượng địa chỉ IP nào
Máy chủ có hai địa chỉ IP. Trên một [
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server3], chúng tôi sẽ phục vụ máy chủ "chính",
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server4 và trên một [
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server5], chúng tôi sẽ phục vụ hai hoặc nhiều máy chủ ảo
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...
Mọi yêu cầu đến một địa chỉ khác với
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server5 sẽ được phục vụ từ máy chủ chính. Yêu cầu tới
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server5 với tên máy chủ không xác định hoặc không có tiêu đề
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server8, sẽ được phục vụ từ
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...3
Máy chủ có hai địa chỉ IP [
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...00 và
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server3]. Máy đang nằm giữa mạng nội bộ [mạng nội bộ] và mạng [internet] bên ngoài. Bên ngoài mạng, tên
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server4 phân giải thành địa chỉ bên ngoài [
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server3], nhưng bên trong mạng, cùng tên đó phân giải thành địa chỉ nội bộ [
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...00]
Máy chủ có thể được thực hiện để đáp ứng các yêu cầu bên trong và bên ngoài với cùng một nội dung, chỉ với một phần
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...9
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server
Bây giờ các yêu cầu từ cả hai mạng sẽ được phục vụ từ cùng một
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...9
Ghi chú
Trên mạng nội bộ, người ta chỉ có thể sử dụng tên
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...07 thay vì tên máy chủ đủ điều kiện
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server4
Cũng lưu ý rằng, trong ví dụ trên, bạn có thể thay thế danh sách địa chỉ IP bằng
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server0, điều này sẽ khiến máy chủ phản hồi giống nhau trên tất cả các địa chỉ
Bạn có nhiều tên miền đi đến cùng một IP và cũng muốn phục vụ nhiều cổng. Ví dụ bên dưới minh họa rằng việc khớp tên diễn ra sau khi xác định được kết hợp địa chỉ IP và cổng phù hợp nhất
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...0
Máy chủ có hai địa chỉ IP [
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server3 và
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server5] lần lượt phân giải thành các tên
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...3 và
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...4
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...6
Các yêu cầu đối với bất kỳ địa chỉ nào không được chỉ định trong một trong các chỉ thị của
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...64 [chẳng hạn như
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...65 chẳng hạn] sẽ được chuyển đến máy chủ chính, nếu có.
Máy chủ có hai địa chỉ IP [
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server3 và
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server5] lần lượt phân giải thành tên
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...3 và
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...4. Trong mỗi trường hợp, chúng tôi muốn chạy máy chủ trên cổng 80 và 8080
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...3
Bất kỳ địa chỉ nào được đề cập trong đối số với máy chủ ảo không bao giờ xuất hiện trong máy chủ ảo khác là máy chủ ảo dựa trên IP nghiêm ngặt
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...4
Ví dụ sau đây cho phép máy đầu cuối ủy quyền máy chủ ảo thông qua máy chủ đang chạy trên máy khác. Trong ví dụ này, một máy chủ ảo cùng tên được định cấu hình trên một máy tại
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...30. Chỉ thị
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...31 được sử dụng để tên máy chủ mong muốn được chuyển qua, trong trường hợp chúng tôi đang ủy quyền nhiều tên máy chủ cho một máy
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...7
Nắm bắt mọi yêu cầu tới bất kỳ địa chỉ IP và cổng không xác định nào, tôi. e. , một tổ hợp địa chỉ/cổng không được sử dụng cho bất kỳ máy chủ ảo nào khác
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...8
Sử dụng vhost mặc định như vậy với cổng ký tự đại diện sẽ ngăn chặn hiệu quả mọi yêu cầu đến máy chủ chính
Một vhost mặc định không bao giờ phục vụ yêu cầu được gửi đến một địa chỉ/cổng được sử dụng cho các vhost dựa trên tên. Nếu yêu cầu chứa tiêu đề
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server8 không xác định hoặc không có thì nó luôn được cung cấp từ vhost dựa trên tên chính [vhost cho địa chỉ/cổng đó xuất hiện đầu tiên trong tệp cấu hình]
Bạn có thể sử dụng
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...33 hoặc
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...34 để viết lại bất kỳ yêu cầu nào vào một trang thông tin [hoặc tập lệnh]
Tương tự như thiết lập 1, nhưng máy chủ lắng nghe trên một số cổng và chúng tôi muốn sử dụng vhost
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...35 thứ hai cho cổng 80
# Ensure that Apache listens on port 80 Listen 80 DocumentRoot "/www/example1" ServerName www.example.com # Other directives here DocumentRoot "/www/example2" ServerName www.example.org # Other directives here3
Vhost mặc định cho cổng 80 [phải xuất hiện trước bất kỳ vhost mặc định nào có cổng ký tự đại diện] bắt tất cả các yêu cầu được gửi đến một địa chỉ IP không xác định. Máy chủ chính không bao giờ được sử dụng để phục vụ yêu cầu
Chúng tôi muốn có vhost mặc định cho cổng 80, nhưng không có vhost mặc định nào khác
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...0
Yêu cầu đến một địa chỉ không xác định trên cổng 80 được cung cấp từ vhost mặc định. Bất kỳ yêu cầu nào khác đến một địa chỉ và cổng không xác định được phục vụ từ máy chủ chính
Bất kỳ việc sử dụng
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server0 nào trong khai báo máy chủ ảo sẽ có mức độ ưu tiên cao hơn so với
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...35
Vhost dựa trên tên có tên máy chủ
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...4 [từ ví dụ dựa trên tên của chúng tôi, thiết lập 2] sẽ có địa chỉ IP riêng. Để tránh sự cố với máy chủ định danh hoặc proxy đã lưu địa chỉ IP cũ vào bộ nhớ đệm cho vhost dựa trên tên, chúng tôi muốn cung cấp cả hai biến thể trong giai đoạn di chuyển
Giải pháp rất dễ dàng, vì chúng ta chỉ cần thêm địa chỉ IP mới [
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server5] vào chỉ thị
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...40
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...1
Hiện có thể truy cập vhost thông qua địa chỉ mới [dưới dạng vhost dựa trên IP] và thông qua địa chỉ cũ [dưới dạng vhost dựa trên tên]
Chúng tôi có một máy chủ với hai vhost dựa trên tên. Để khớp đúng máy chủ ảo, khách hàng phải gửi đúng tiêu đề
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server8. HTTP/1 cũ. 0 không gửi tiêu đề như vậy và Apache không biết vhost mà máy khách đã cố gắng tiếp cận [và phục vụ yêu cầu từ vhost chính]. Để cung cấp khả năng tương thích ngược nhiều nhất có thể, chúng tôi tạo một vhost chính trả về một trang duy nhất chứa các liên kết có tiền tố URL tới các máy chủ ảo dựa trên tên
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...2
Do chỉ thị
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...42, yêu cầu tới URL
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...43 luôn được cung cấp từ sub1-vhost.
Yêu cầu tới URL
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...44 chỉ được cung cấp từ sub1-vhost nếu khách hàng đã gửi đúng tiêu đề
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server8. Nếu không có tiêu đề
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server8 nào được gửi, máy khách sẽ nhận được trang thông tin từ máy chủ chính.
Xin lưu ý rằng có một điều kỳ lạ. Yêu cầu tới
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...47 cũng được phục vụ từ sub1-vhost nếu khách hàng không gửi tiêu đề
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server8
Các lệnh
Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.example.com DocumentRoot "/www/mainserver" DocumentRoot "/www/example1" ServerName www.example.com # Other directives here ... DocumentRoot "/www/example2" ServerName www.example.org # Other directives here ...34 được sử dụng để đảm bảo rằng một ứng dụng khách đã gửi đúng tiêu đề
DocumentRoot "/www/server1" ServerName server.example.com ServerAlias server8 có thể sử dụng cả hai biến thể URL, tôi. e. , có hoặc không có tiền tố URL