httpd Basics of WEB application (c)

  Earlier we talked to the httpd path aliases, access logs defined, basic authentication configuration, please refer to review https://www.cnblogs.com/qiuhom-1874/p/12561236.html ; today we chat httpd Web Hosting and configuration status page, we also mentioned in front of web hosting, is nothing more than a so-called virtual host multiple virtual sites on one physical host; usually httpd virtual host has three categories, namely ip-based virtual host, and port-based FQDN-based virtual hosting and virtual hosting; not difficult to understand host-based virtual ip IP is different to distinguish between different virtual hosts; port-based virtual host is different port distinguish between different virtual host, host-based virtual fqdn is to different users request packets host virtual host to distinguish the header; then we look at how to configure virtual hosts httpd Lane;

  1, Web Hosting

  httpd in virtual host configuration is: to configure <virtualhost IP PORT> ...... </ virtualhost> configuration block; httpd2.2 where it needs to be disabled before the host center to enable virtual host configuration, disable the method is very simple, that is host command center in the documentroot to comment; in httpd2.4, we do not need to close the center console, after the virtual host configuration, the center hosts a natural death, does not require human manual annotation; to be placed at the center mainframe most instructions can be used for virtual host configuration block; usage and center console almost no difference in what configuration;

  Example: IP-based virtual host implementation

   Note: The above configuration is mainly to provide two IP-based virtual hosts, one is 192.168.0.98:80, a host 192.168.0.99:80; we created in the corresponding file in the home directory, heavy profiles, two virtual host can take effect;

[root@test_node1-centos7 conf.d]# echo "this is a_com page ip is 192.168.0.98" > /vhost/www/html/a_com/index.html
[root@test_node1-centos7 conf.d]# echo "this is b_com page ip is 192.168.0.99" > /vhost/www/html/b_com/index.html
[root@test_node1-centos7 conf.d]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4a:bd:74 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.99/24 brd 192.168.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4a:bd74/64 scope link 
       valid_lft forever preferred_lft forever
[root@test_node1-centos7 conf.d]# ip addr add 192.168.0.98/24 dev ens33
[root@test_node1-centos7 conf.d]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4a:bd:74 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.99/24 brd 192.168.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.0.98/24 scope global secondary ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4a:bd74/64 scope link 
       valid_lft forever preferred_lft forever
[root@test_node1-centos7 conf.d]# httpd -t
Syntax OK
[root@test_node1-centos7 conf.d]# systemctl reload httpd
[root@test_node1-centos7 conf.d]# 

  Note: The above configuration is mainly to provide two sites corresponding virtual page file, and then add a new ip192.168.0.98 the original card above, after such a configuration, we configure virtual host can pass on the browser different ip address access, get a different home page response;

 

   Tip: You can see us in a different IP access to the site, get a different virtual hosts file is home to us, indicating that host-based virtual IP address without any problems we configurations; and we can also look at these two respective Web Hosting the access log file;

   Tip: different sites, each with different access and error logs are recorded with each site access and error logs information;

  Example: port-based virtual host implementation

   Note: The above configuration changes in the IP-based virtual host configuration, two virtual hosts are based on the ip address 192.168.0.99, respectively listens on two ports 80 and 81, we will visit 192.168.0.99:80 matched to a host, the host to get a response to the page, you will get access 192.168.0.99:81 b host page response;

   Tip: You can see the same IP address, different access ports, the provision of services to different virtual sites;

  Example: Based on the virtual host of different FQDN

   Note: The above two virtual hosts are configured to access different main listening through host request header to distinguish 192.168.0.99:80 user; as follows

  Before reload configuration, we sit down to resolve host, DNS resolution simulation on windows, respectively, and the www.a.com www.b.com are resolved to 192.168.0.99

 

   Tip: windows hosts file parsing in C: \ Windows \ system32 \ drivers \ etc \ hosts file name for this file syntax is the same as Linuxhosts file syntax, behind the front is ip address is a host name or an alias; as follows

   Tip: this we will be able to access different virtual sites by different parsing names

   Tip: You can see us in a different resolve the name to access, resulting in different virtual host response, in fact, this is the middle of the user to type a different host headers to distinguish between different virtual sites; as follows

 

   Tip: The user's host request header can be other strings, it is the host header can not be resolved, usually is what we type the string in the browser, the host header value corresponding to what is, but browser type string to bring us resolved to an IP then sends a corresponding request to the host to a corresponding address ip; to better understand this process, consider the following;

   Tip: When we construct a request packet, just give a string to Host request header, also can be a normal request to the home page, which shows the host request header is essentially just used to distinguish between different virtual hosts, it does not need to parse; the reason why the case has not been matched successfully host headers, which response page a host, because the configuration of a host at the top, the default host header is not matched will be at the top of the virtual host any web hosting case response; here also point to note is that, httpd2.2 FQDN when using virtual hosts, you need to listen instructions and namevirtualhost ip: port directive to specify the ip and port information of the virtual host listens; httpd2.4 you can not use namevirtualhost the instruction to specify; as follows

   Note: The above example is based on a virtual host configuration httpd2.2 the FQDN;

   2, status page configuration instructions

  On page httpd state realized by the httpd status_module module, configured to use the state of the page information, first confirm that the module is loaded, it was confirmed as follows:

   Tip: httpd2.2 2.4 and confirmation method of the same, if status_module can list, indicating that the module has been loaded, not loaded if required LoadModule status_module modules / mod_status.so can be loaded; upper httpd2.4 confirmation result, the results confirmed the following 2.2

 

   Confirmed the loaded module, the next step is configured to use

  Example: httpd2.4 configuration status page

   Tip: Configuration status page is mainly used location to specify a URI, and disposed sethandler instructions thereunder item to match the URI to how to deal with the above represented treated with server-status, to note here that point httpd status page status_module achieve, we must be in a configuration using a server-status to deal with, not the other names; also be noted that the location can be configured in any virtual host and a central host can he have said to deal with server-status, said white the display is the status page;

   Note: The above is what we just configured location corresponding content uri response; of course, the above information is more private information, usually we only host part of the IP address allows you to view, if not all hosts are allowed to view on httpd2.4, just View part of the host, to do access control based on IP address, we need to control access permission instruction is written in <requireall> ...... </ requireall> configuration section;

   Example: httpd2.2 status page configuration

   Note: There is no essential difference configuration httpd2.2 and httpd2.4 status page;

   Tip: On the Status page httpd2.2, a lot less than httpd2.4 information, see from the above tips, it tells us that if you want to show full status information, we need to use extendedstatus on instruction, if we need to be more comprehensive information, may be selected to specify the configuration server configuration section;

Guess you like

Origin www.cnblogs.com/qiuhom-1874/p/12570900.html
Recommended