Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

10.5.1 Based on IP address


May 24, 2021 That's what Linux should learn



If a server has multiple IP addresses, and each IP address corresponds to each site deployed on the server, the page resources of different sites are accessed when a user requests access to a different IP address. M oreover, each site has a separate IP address, which is also beneficial to SEO. Therefore, providing virtual site host functionality in this way is not only the most common, but also welcomed by web site hosts (especially grass-roots web hosts).

In Chapters 4 and 9, Mr. Liu explained two methods for configuring the network, and we can choose between them in the experiment and at work. F or the current experiment, the IP addresses that need to be configured are shown in Figure 10-13. After configuring and restarting the network card service, remember to check the connectivity of the network to ensure that all three IP addresses are properly accessible, as shown in Figure 10-14 (this is important, be sure to test it well, and then go to the next step!).

10.5.1 Based on IP address Figure 10-13 uses the nmtui command to configure network parameters

Step 1: Create three directories in /home/wwwroot to hold data for different sites and write the home file of the site to each of them. E ach home page file should have information that clearly distinguishes between the content of different websites, so that we can check the results more intuitively later.

10.5.1 Based on IP address Figures 10-14 check the connectivity of the three IP addresses

[root@linuxprobe ~]# mkdir -p /home/wwwroot/10 [root@linuxprobe ~]# mkdir -p /home/wwwroot/20 [root@linuxprobe ~]# mkdir -p /home/wwwroot/30 [root@linuxprobe ~]# echo "IP:192.168.10.10" > /home/wwwroot/10/index.html [root@linuxprobe ~]# echo "IP:192.168.10.20" > /home/wwwroot/20/index.html [root@linuxprobe ~]# echo "IP:192.168.10.30" > /home/wwwroot/30/ i ndex.html Step 2: Start at approximately 113 lines in the profile of the httpd service, write three additional virtual host site parameters based on IP address, and then save and exit. Remember that the httpd service needs to be restarted before these configurations take effect.

[root@linuxprobe ~]# vim /etc/httpd/conf/httpd.conf .................. O mit some of the output information... 1 13 <VirtualHost 192.168.10.10> 114 DocumentRoot /home/wwwroot/10 115 ServerName www.linuxprobe.com 116 <Directory /home/wwwroot/10 > 117 AllowOverride None 118 Require all granted 119 </Directory> 120 </VirtualHost> 121 <VirtualHost 192.168.10.20> 122 DocumentRoot /home/wwwroot/20 123 ServerName bbs.linuxprobe.com 124 <Directory / h ome/wwwroot/20 > 125 AllowOverride None 126 Require all granted 127 </Directory> 128 </VirtualHost> 129 <VirtualHost 192.168.10.30> 130 DocumentRoot /home/wwwroot/30 131 ServerName tech.linuxprobe.com 132 <Directory /home/wwwroot/30 > 133 AllowOverride None 134 Require all granted 135 </Directory> 136 </VirtualHost> .................. O mit some of the output information... S tep root@linuxprobe 3: Visit the website and you'll see the default home page of the httpd service. I t's time for everyone to react right away - this is SELinux messing around. B ecause the SELinux security context of the current/home/wwwroot directory and the site data directory inside does not match the site service, the httpd service program cannot obtain these site data directories. We need to manually set the SELinux security context for the new site data directory correctly (see the experiment above) and use the restorecon command to make the newly set SELinux security context effective immediately so that we can immediately see how the site is accessed, as shown in Figures 10-15.

[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/10 [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/10/ [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/20 [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/20/ [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/30 [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/30/* [root@linuxprobe ~]# restorecon -Rv /home/wwwroot restorecon reset /home/wwwroot context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/10 context unconfined_u:object_r :home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/10/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/20 context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/20/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/30 context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/30/index.html context unconfined_u:object_r :home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 [root@linuxprobe ~]# firefox

10.5.1 Based on IP address

Figure 10-15 Access to the virtual host site based on different IP addresses