Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to access an Apache virtual host (theoretical part)

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Build a virtual host

■ virtual Web host

● runs multiple Web sites on the same server, each of which is not independent

Take up a real computer

Virtual host types supported by ■ httpd

● domain name-based virtual host

● virtual host based on IP address

● port-based virtual hosts:

Build a virtual host-an example of a domain name-based ■ application:

● builds two virtual Web sites

Www.kgc.com, IP address is 173.17.17.11

Www.kcce.com, IP address is 173.17.17.11

When ● accesses the two domain names in a browser, it displays different contents.

1. Provide domain name resolution for virtual hosts

[root@dnssvr ~] # vim / var/named/chroot/var/named/kgc.com.zone

@ IN NS dnssvr.kgc.com.

Dnssvr IN A 173.1 7.1 7.2

Www IN A 173.17.17.11

[root@dnssvr ~] # vim / var/named/chroot/var/named/kcce.com.zone

.

@ IN NS dnssvr.kgc.com.

Www IN A 173.17.1711

two。 Prepare web page documents for virtual hosts

[root@www] # mkdir-p / var/www/html/kgc

[root@www] # mkdir-p / var/www/html/accp

[root@www ~] # echo "www.kgc.com" >

/ var/www/html/kgccom/index.html

[root@www ~] # echo

! Www.accp.com ">

/ var/www/html/kccecom/index.html

3. Add virtual host configuration

[root@www ~] # vim / usr/local/httpd/conf/extra/httpd-vhosts.comf

DocumentRoot "/ var/www/html/kgccom"

ServerName www.kgc.com

ErrorLog "logs/www.kgc.com.error_log"

CustomLog "logs/www.kgc.com.access_log" common

< Directory "/var/www/html" >

Require all granted

DocumentRoot "/ var/www/html, accp

ServerName www.accp.com

ErrorLog "logs/www.accp.com.error_log"

CustomLog "logs/www.accp.com.access_log" common

< Directory "/var/www/html" >

Require all granted

< /VirtualHost>

4. The client accesses the virtual Web host separately

Build a virtual host-example of a port-based ■ application:

● builds two virtual Web sites

Www.kgc.com, the address and port of IP is 173.17.17.11 virtual 80

Www.accp.com, the address and port of IP is 173.17.17.11

When accessing the two ports in the browser, different contents are displayed.

[root@www ~] # vim / usr/loca/httpd/conf/extra/httpd-vhosts.conf

< VirtualHost 173.17.17.11:80习 DocumentRoot "/var/wwwhtml/kccecom" ServerName www.kgc.com Listen 80 Listen 8353 构建虚拟主机一 基于IP ■应用示例: ●构建2个虚拟Web站点 www.kgc.com, IP地址为220.181.120.61 www.kcce.com, IP地址为122.115.32.133 在浏览器中访问这两个IP时P分别显示不同的内容 [root@www ~]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf < VirtualHost 220.181.120.61:80>

DocumentRoot "/ var/www/html/kgccom"

ServerName www.kgc.com

I

DocumentRoot "/ var/www/htm/kccecom"

ServerName www.kcce.com

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report