In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Build a virtual host virtual Web host:
1. Run multiple Web sites in the same physical server, each of which does not independently occupy a real computer
Virtual host types supported by httpd:
1. Domain name-based virtual host (commonly used by enterprises)
two。 Virtual host based on IP address
3. Port-based virtual host
Large company example project:
Two physical hosts (ABG B)
There are two virtual sites in each of the two hosts
There are accp sites and kgc sites in hosts An and B.
The content of the website is exactly the same, and when providing business to the outside world, it not only uses a reasonable distribution, but also plays a dual hot standby.
Learn the architecture of one host and two websites
one。 Build a virtual host-an example of a domain name-based application:
1. Build 2 virtual Web sites
Www.kgc.com, IP address is 173.17.17.11
Www.kcce.com, IP address is 173.17.17.11
two。 When the two domain names are accessed in the browser, different contents are displayed.
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.17.1 7.2www 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.17.11 Prepare web documents for virtual hosts: [root@www ~] # mkdir-p / var/www/html/kgccom [root@www ~] # mkdir-p / var/www/html/kccecom [root@www ~] # echo "www.kgc.com" > / var/www/html/kgccom/index.html [root@www ~] # echo "www.kcce.com" > / var/www/html/kccecom/index.html add virtual host configuration: [root@www ~] # vim / usr/local/httpd/conf/extra/httpd-vhosts.conf 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/kccecom" ServerName www.kcce.com accesses the virtual Web host Demo1 on the client respectively: access the virtual host based on the domain name, add the second network card to the virtual machine settings, and display:
The above is the way to access the virtual host based on the domain name
two。 Build a virtual host-example of a port-based application:
1. Build two virtual Web sites
Www.kcce.com, the address and port of IP is 173.17.17.11 virtual 80
Www.kcce.com, the address and port of IP is 173.17.17.11
two。 When accessing the two ports in the browser, different contents are displayed.
[root@www ~] # vim / usr/local/httpd/conf/extra/httpd-vhosts.conf
< VirtualHost 173.1 7.17.11:80>DocumentRoot "/ var/www/htm/kccecom" ServerName www.kcce.com DocumentRoot "/ var/www/htm/kccepad" ServerName www.kcce.comListen 80Listen 835 listening ports are written in the main configuration file Demo2: access based on different ports [root@localhost extra] # vim vhost.conf DocumentRoot "/ var/www/html/kgc02/" ServerName www.kgc.com ErrorLog "logs/www.kgc02.com.error_log" CustomLog "logs/www. Press Esc after kgc02.com.access_log "common Require all granted input is complete Input: wq save exit [root@localhost extra] # cd / var/www/html/ [root@localhost html] # lsaccp kgc [root@localhost html] # mkdir kgc02 [root@localhost html] # lsaccp kgc kgc02 [root@localhost html] # cd kgc02/ [root@localhost kgc02] # vim index.htmlthis is kgc02 web press Esc after the input is complete Input: wq save exit [root@localhost kgc02] # vim / etc/httpd/conf/httpd.conf input: / Listen found the location of the listening port Listen 192.168.56.131:80Listen 192.168.56.131:8080#Listen 80 what needs to be changed here is to turn off the monitoring of IPv6 to the comment, at the same time, change the listening address of IPv4 to the IP address of your own Linux, copy it using yy, paste in the following line, change the port to 808, and press Esc after modification. Input: wq save and exit [root@localhost kgc02] # systemctl restart httpd / / restart the service [root@localhost kgc02] # netstat-ntapActive Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0 0. 0 systemctl restart httpd 111 0.0.0 0 * LISTEN 1/systemd Tcp 0 0 192.168.56.131 LISTEN 52732/httpd # you can see that both ports are listening at this time. * LISTEN 52732/httpd tcp 0 192.168.56.131 LISTEN 52732/httpd #
Verify: use win7's browser, enter: www.kgc.com:8080
What is displayed at this time is the home page of the 8080 port kgc02 that we wrote in advance.
If you type: www.kgc.com:80, the interface of this is kgc web is also displayed.
This is the port-based way to access the virtual host
Demo3: access based on different IP
Previously, we had two network cards with addresses of 192.168.56.131 and 192.168.56.134, which need to be used here.
[root@localhost kgc02] # cd / etc/httpd/conf/extra/ [root@localhost extra] # lsvhost.conf [root@localhost extra] # vim vhost.conf//11,29 s / ^ / # / g / / comment lines 11 to 29 globally You do not need to use / / here to change the * number to the IP DocumentRoot "/ var/www/html/accp/" ErrorLog "logs/www.accp.com.error_log" CustomLog "logs/www.accp.com.access_log" common Require all granted / / change the * number to the IP of the second network card here. And change the following accp to accp02 to distinguish between DocumentRoot "/ var/www/html/accp02/" ErrorLog "logs/www.accp02.com.error_log" CustomLog "logs/www.accp02.com.access_log" common Require all granted # after modification, press Esc Input: wq save exit create directory site: [root@localhost extra] # cd / var/www/html/ [root@localhost html] # mkdir accp02 [root@localhost html] # cd accp02/ [root@localhost accp02] # vim index.htmlthis is 134accp02 web# press Esc after input, enter: wq save exit [root@localhost accp02] # vim.. / accp/index.htmlthis is 131accp web# after modification, press Esc Input: wq save exit modify listening address: [root@localhost accp02] # vim / etc/httpd/conf/httpd.confListen 192.168.56.131:80Listen 192.168.56.134:80#Listen 192.168.56.131vim 8080 annotate port 8080 and add a line of 192.168.56.134 port 80 listening # press Esc after modification, enter: wq save exit [root@localhost accp02] # systemctl restart httpd verification: use win7 browser Input: 192.168.56.131 / 192.168.56.134
Modify DNS: [root@localhost accp02] # cd / etc/httpd/conf/extra/ [root@localhost extra] # vim vhost.conf DocumentRoot "/ var/www/html/accp/" ServerName www.accp.com 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 ErrorLog "logs/www.accp02.com.error_log The above two paragraphs of "CustomLog" logs/www.accp02.com.access_log "common Require all granted # need to add ServerName to add a new area: [root@localhost extra] # vim / etc/named.rfc1912.zoneszone" naccp.com "IN {type master File "naccp.com.zone"; allow-update {none;};}; # add the above # press Esc after modification, and enter: wq save exit [root@localhost extra] # cd / var/named/ [root@localhost named] # cp-p accp.com.zone naccp.com.zone [root@localhost named] # vim naccp.com.zone$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.56.134 / / IP address changed to address of the second network card # Press Esc after modification, enter: wq save exit [root@localhost named] # systemctl restart named [root@localhost named] # systemctl restart httpd / / restart service verification: use win7 browser, enter: www.accp.com / www.naccp.com
These are the ways to access virtual hosts based on different IP
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.