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

A tutorial on how to build a virtual host

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

Share

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

Today, the editor will bring you an article on building a tutorial for the use of virtual hosts. The editor thinks it's pretty good, so I'll share it for you as a reference. Let's follow the editor and have a look.

Virtual web host

Running multiple web sites on the same physical server, each of which does not independently occupy a real computer

Virtual host types supported by httpd * domain name-based virtual hosts * IP address-based virtual hosts * port-based virtual hosts

Case 1-- Building two virtual web sites based on domain names-- the www.accp.com ip address is the local address and the www.kgc.com ip address is the local address. When the two domain names are accessed in the browser, different content experimental environments are displayed respectively.

A Linux host acts as a server

A win7 host for testing

1. Install http and dns services [root@localhost ~] # yum install httpd bind-y / / install http,dns service 2, configure dns main configuration file [root@localhost ~] # vim / etc/named.conf # # main configuration file options {listen-on port 53 {any;}; # # listen locally to all listen-on-v6 port 53 {:: 1;} Directory "/ var/named"; dump-file "/ var/named/data/cache_dump.db"; statistics-file "/ var/named/data/named_stats.txt"; memstatistics-file "/ var/named/data/named_mem_stats.txt" Recursing-file "/ var/named/data/named.recursing"; secroots-file "/ var/named/data/named.secroots"; allow-query {any;} # # allow all 3, configure zone configuration file (etc/named.rfc1912.zones) [root@localhost ~] # vim / etc/named.rfc1912.zones # # configure zone configuration file zone "localhost" IN {# # copy two templates to the following type master; file "named.localhost"; allow-update {none;};} Zone "accp.com" IN {# # modify localhost to accp.com type master; file "accp.com.zone"; # # create zone data configuration file allow-update {none;};}; zone "kgc.com" IN {# # modify localhost to kgc.com type master File "kgc.com.zone"; # # create a zone data profile allow-update {none;};} 4. Edit the zone data configuration file (accp.com.zone kgc.com.zone) [root@localhost ~] # cd / var/named/ # # change to the / var/named directory [root@localhost named] # cp-p named.localhost accp.com.zone # # copy template for accp.com.zone [root@localhost named] # vim accp.com.zone # # Edit the zone data configuration file $TTL 1D @ IN SOA @ rname.invalid. (0; serial 1D Refresh 1H; retry 1W Expire 3H) Minimum NS @ A 127.0.0.1www IN A 192.168.13.133 # # Delete ipv6 add domain name resolution address to native [root@localhost named] # cp-p accp.com.zone kgc.com.zone## edit kgc's zone data configuration file without changing 5 Turn off the firewall and enable the service [root@localhost named] # systemctl start named # # enable the dns service [root@localhost named] # systemctl stop firewalld.service # # turn off the firewall [root@localhost named] # setenforce 0 # # turn off the enhanced feature 6, enter the win7 test host, modify the DNS parsing server to see if it can be parsed

seven, Create a http extension profile in Linux [root@localhost named] # cd / etc/httpd/conf # # switch to the http configuration directory [root@localhost named] # mkdir extra # # create an extension profile directory [root@localhost named] # cd extra [root@localhost named] # vim vhost.conf # # Edit the extension profile # # label * all ip port 80 Documentroot "/ var/www/ Html/accp/ "# # site directory ServerName www.accp.com # # domain name Errorlog" logs/www.accp.com.error_log "# # error log file Customlog" logs/www.accp.com.access_log "common # # access log # # Control directory permissions Require all granted # # allow everyone to access # # the logs above is a soft connection / var/log/httpd # # as long as you change the accp to kgc "/ var/www/html/kgc/" ServerName www.kgc.com Errorlog "logs/www.kgc.com.error_log" Customlog "logs/www.kgc.com.access_log" common Require all granted 8 Go to the web site Create a web page content file for accp and kgc [root@localhost extra] # cd / var/www/html/ # # switch to a web site [root@localhost html] # mkdir accp kgc # # create a site directory for both sites [root@localhost html] # cd accp/ [root@localhost accp] # vim index.html # # Edit accp page content this is an accp web [root@localhost html] # cd kgc/ [root @ localhost accp] # vim index.html # # Edit kgc page content this is a kgc web9 Load the http extension configuration file into the main configuration file and open the http service [root@localhost www] # cd / etc/httpd/conf # # switch to the http configuration file directory [root@localhost conf] # vim httpd.conf # # Edit the main configuration file Include conf/extra/vhost.conf # # add the extension configuration file directory [root@localhost conf] # systemctl start httpd # # start http service 10 at the last line Use the domain name for page access

Case 2-based on port 1 Configure the extension configuration file content [root@lolocalhost extra] # vim vhost.conf Documentroot "/ var/www/html/kgc/" ServerName www.kgc.com Errorlog "logs/www.kgc.com.error_log" Customlog "logs/www.kgc.com.access_log" common Require all granted # # port number changed to 8080 Documentroot "/ var/www/html/kgc02/" # # directory changed to 02 ServerName www.kgc.com Errorlog "logs/www.kgc02.com.error_log" # # log file changed to 02 Customlog "logs/www.kgc02.com.access_log" common Require all granted 2 Edit site directory and site content [root@localhost extra] # cd / var/www/html/ [root@localhost html] # mkdir kgc02 [root@localhost html] # vim index.html # # Edit kgc02 page content this is a kgc02 web3, configure http master configuration file, and modify listening port And restart the network service [root@localhost html] # vim / etc/httpd/conf/httpd.conf # # modify the configuration file Listen 192.168.13.133 etc/httpd/conf/httpd.conf 80 # # modify the ipv4 listening port Listen 192.168.13.133:8080#Listen 8 listen # annotate the ipv6 port [root@localhost html] # systemctl restart httpd.service # # restart the network service [root@localhost html] # netstat-ntap # # check Check the listening port open status tcp 0 192.168.13.133 LISTEN 4093/httpd 8080 0.0.0.0 LISTEN 4093/httpd 4 Test the web page

Case 3-based on IP

Add a network card to Linux to make different IP

one, Configure the contents of the extended configuration file [root@lolocalhost extra] # vim vhost.conf # # modify the ip address Documentroot "/ var/www/html/accp/" # # Domain name is not useful here to delete Errorlog "logs/www.accp.com.error_log" Customlog "logs/www.accp.com.access_log" common Require all granted # # modify ip address Documentroot "/ var/www/html/accp02/" # # modify directory accp02 and log Errorlog "logs/www.accp02.com.error_log" Customlog "logs/www.accp02.com.access_log" common Require all granted 2 Edit site directory and site content [root@localhost extra] # cd / var/www/html/ [root@localhost html] # mkdir accp02 # # create directory site content for 132ip address [root@localhost html] # cd accp02/ [root@localhost accp02] # echo "this is 132 web" > index.html [root@localhost accp02] # cd.. / [root@localhost html] # cd accp # # modify 133ip address page content [root@localhost accp] # vim index.htmlthis is 133 web3 Configure the http master profile and modify the listening port And restart the network service [root@localhost html] # vim / etc/httpd/conf/httpd.conf # # modify the configuration file Listen 192.168.13.133etc/httpd/conf/httpd.conf 80 # # add two ip port listeners Listen 192.168.13.132:80#Listen 192.168.13.133etc/httpd/conf/httpd.conf 8080 # # Note 8080 Port # Listen 8comment # annotate the ipv6 port [root@localhost conf] # systemctl restart httpd .service # # restart network service 4 Test the web page

Extension: different ip and different domain name access 1 Configure the content of the extension profile [root@lolocalhost extra] # vim vhost.conf Documentroot "/ var/www/html/accp/" ServerName www.accp.com # # add the domain name Errorlog "logs/www.accp.com.error_log" Customlog "logs/www.accp.com.access_log" common Require all granted Documentroot "/ var/www/html/accp02/" ServerName www.naccp.com # # Add another domain name, Errorlog "logs/www.accp02.com.error_log" Customlog "logs/www.accp02.com.access_log" common Require all granted 2 Add a new domain name resolution [root@localhost /] # vim / etc/named.rfc1912.zones zone "accp.com" IN {type master to the dns zone configuration file File "accp.com.zone"; allow-update {none;};} zone "naccp.com" IN {type master; file "naccp.com.zone"; allow-update {none;};} 3. Configure the zone data configuration file [root@localhost named] # cd / var/named/ [root@localhost named] # cp-p accp.com.zone naccp.com.zone # # copy [root@localhost named] # vim naccp.com.zone # # configure the zone data configuration file $TTL 1D @ IN SOA @ rname.invalid. (0; serial 1D Refresh 1H; retry 1W Expire 3H) Minimum NS @ A 127.0.0.1www IN A 192.168.13.132 # # the naccp here needs to modify 132ip address 4, restart dns and http services, and test [root@localhost named] # systemctl restart named # # restart DNS [root@localhost named] # systemctl restart httpd.service # # restart the network

These are the details of building a virtual host. Have you gained anything after reading it? If you want to know more about it, you are welcome to follow the industry information!

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