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

Build a virtual host based on domain name, port and IP address (including multiple Demo labs)

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

Share

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

Virtual host virtual Web host concept:

Running multiple Web sites on the same physical server, each of which is not independent

Take up a real computer

Types of virtual hosts supported by the Httpd service

Domain name-based virtual host-commonly used

Port-based virtual host

Virtual host based on IP address

Basic architecture topology diagram (simple drawing)

Domain name-based virtual host (including Demo)

Domain name-based virtual hosts are configured with different domain names for each virtual host, but all point to the same IP address. It is also the most widely used type of virtual host.

Demo

1. Install DNS and HTTP services required for the experiment

[root@localhost ~] # yum-y install bind httpd

2. Modify the global configuration file and zone configuration file of DNS service

Global configuration file (/ etc/named.conf)

Change the listening port to any and allow access to any

Zone profile (/ etc/named.rfc1912.zones)

Add two areas: kgc.com and accp.com

3. Configure the area data configuration file

[root@localhost ~] # cd / var/named/ [root@localhost ~] # cp-p named.localhost kgc.zone [root@localhost ~] # cp-p named.localhost accp.zone [root@localhost ~] # vim kgc.zone/accp.zonevi Editor Delete IPV6 address add www IN A 192.168.116.135 (native IP address) wq save exit by G location last line

4. Modify the HTTP main configuration file

Location: / etc/httpd/conf/httpd.conf

Press G to locate the last line I insert 1 / / * as IP address 80 is the port number 2 DocumentRoot / var/www/html/kgc / / website address 3 ServerName www.kgc.com / / domain name 4 Errorlog "logs/www.kgc.com.error_log" / / error log address 5 CustomLog "logs/www.kgc.com.access_log" common / / log address (use common at the end to refer to the following configuration) 6 7 Require all granted 8 9 / / closing End 10 11 12 DocumentRoot / var/www/html/accp 13 ServerName www.accp.com 14 Errorlog "logs/www.accp.com.error_log" 15 CustomLog "logs/www.accp.com.access_log" common 16 17 Require all granted 18 19

5. Set up the home page corresponding to the domain name

[root@localhost httpd] # cd / var/www/html/ [root@localhost html] # mkdir accp kgc [root@localhost html] # cd kgc/ [root@localhost kgc] # this is kgc webwq Save exit in vim index.htmlvi Editor [root@localhost kgc] # cd.. / [root@localhost html] # cd accp/ [root@localhost accp] # vim index.htmlvi Editor this is kgc webwq Save exit [root@localhost accp] #

6. Verify the test results

Port-based virtual host (including Demo) Demo

1. Modify the HTTP main configuration file

Location: / etc/httpd/conf/httpd.conf

1 / / Port 80 is the default port of http 2 DocumentRoot / var/www/html/kgc 3 ServerName www.kgc.com 4 Errorlog "logs/www.kgc.com.error_log" 5 CustomLog "logs/www.kgc.com.access_log" common 6 7 Require all granted 8 9 10 11 / / modified port is 8080 12 DocumentRoot / var/www/ Html/kgc02 13 ServerName www.kgc.com 14 Errorlog "logs/www.kgc02.com.error_log" 15 CustomLog "logs/www.kgc02.com.access_log" common 16 17 Require all granted 18 19

2. Set up the corresponding home page

[root@localhost httpd] # cd / var/www/html/ [root@localhost html] # mkdir kgc02 [root@localhost html] # cd kgc02/ [root@localhost kgc] # vim index.htmlvi Editor this is kgc02 webwq Save exit

3. Modify the main configuration file

Find Listen and modify it according to the following figure

4. Verify the experimental results.

Virtual Host (including Demo) Demo based on IP

Note: this experiment requires adding another network card in advance to ensure that at least two network cards exist.

1. Modify the HTTP main configuration file

Location: / etc/httpd/conf/httpd.conf

1 / modify IP address 2 DocumentRoot / var/www/html/kgc 4 Errorlog "logs/www.kgc.com.error_log" 5 CustomLog "logs/www.kgc.com.access_log" common 6 7 Require all granted 8 9 10 11 / modify port to 8080 12 DocumentRoot / var/www/html/kgc02 14 Errorlog "logs/www.kgc02. Com.error_log "15 CustomLog" logs/www.kgc02.com.access_log "common 16 17 Require all granted 18 19

Line 3 and behavior 13 specify the domain name, because this experiment visits the website through a different IP address and does not need to use a domain name, so it can be deleted.

2. Modify the listening address

Address: / etc/httpd/conf/httpd.conf

Find Listen and modify it according to the following figure

Experimental verification can be carried out by entering systemctl restart httpd. (first of all, you need to make sure that there is a corresponding home page under the site)

3. Experimental verification

Note: the firewall must be turned off! Or make sure that the HTTP service is passed, or it will definitely go wrong. The lesson of blood.

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