In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
As we all know, a physical server can only run one site, but if you want to achieve a server running multiple sites, you have to use virtual hosts. A virtual host, as the name suggests, is a virtual host that, when configured, is accessed by clients as if they were accessing multiple backend servers.
There are three different ways to implement virtual hosting:
IP-based virtual hosting: different IP addresses are used to provide different sites
PORT-based virtual hosting: using different ports to provide different sites
HOSTNAME Based Virtual Hosting: Offering Different Sites with Different Hostnames
For a more intuitive experience, the following three ways to implement virtual hosts:
Explain the experimental environment. The experimental host is centos7.3 and the IP address is: 192.168.1.104.
First install the httpd service, here using httpd2.4.6 version:
# yum -y install httpd
View installation files after installation:
# rpm -ql httpd
The corresponding file makes some simple explanations:
Service script: /etc/rc.d/init.d/httpd Script configuration file: /etc/sysconfig/httpd Run directory: /etc/httpd Profile: Main configuration file: /etc/httpd/conf/httpd.conf Extended configuration: /etc/httpd/conf.d/*.conf Socket monitored: 80/tcp, 443/tcp Document root directory: /var/www/html CGI:/var/www/cgi-bin/ Default homepage: index.html
Before experimenting, make sure that in the httpd.conf configuration file:
httpd service listens on port 80
Comment out Root "/var/www/html/"
IP-based virtual host implementation:
The IP address of this machine is 192.168.1.104. You need to add an IP address:
# ifconfig ens36:0 192.168.1.200 netmask 255.255.255.0 broadcast 192.168.1.255 up
Check with ifconfig:
You can see that ens36:0 has been added successfully.
For ease of administration, we create a VirtualHost.conf file in the extension configuration file:
]# vim VirtualHost.conf
Add the following:
DocumentRoot "/var/www/test1/" ServerName 192.168.1.104 DocumentRoot "/var/www/test2/" ServerName 192.168.1.200
Then add a home page for the two sites you added
First create two directories:
# mkdir -pv /var/www/test{1,2}mkdir: created directory '/var/www/test1'mkdir: created directory '/var/www/test2'
Provide the home page file for test1:
# vim /var/www/test1/index.html
Add the following:
Test1 Page
Save exit. Test2 is the same;
Perform syntax checking:
# httpd -tSyntax OK
Reread the profile:
# systemctl reload httpd
Test results:
Site test1:
Test site 2:
Second, port-based virtual host implementation:
Edit Extension Profile:
]# vim VirtualHost.conf
Add the following:
DocumentRoot "/var/www/test1/" ServerName 192.168.1.104 DocumentRoot "/var/www/test2/" ServerName 192.168.1.200
In the main configuration file, add a line under listening ports
Listen 8080
save and exit
Perform syntax checking:
# httpd -tSyntax OK
Note: Because the port is added here, the service needs to be restarted to take effect.
# systemctl restart httpd# ss -tnlState Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 :::8080 :::* //Port 8080 Listened to LISTEN 0 128 :::80 :::* //Port 80 Listened to LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::*
Test results:
Site 1:
Site 2:
Third, because IP and port-based virtual hosts are not commonly used, here is a demonstration of virtual host implementation based on FQDN:
Add the following to the extension profile:
In order to resolve the host name successfully, we need to modify the host file. We use the browser test under win here, so we need to modify the hosts file under win. The path is:
C:\Windows\System32\drivers\etc\hosts
add the following prior
Start testing:
Site test1:
Test site 2:
Above, even though there are three implementations of httpd-based virtual hosts, in daily production, it is often necessary to implement access control for specific users. The following is a simple demonstration of user-based control access:
Edit the extension profile and add the following:
Next, use htpasswd to generate the password:
Create the admin directory and home page file
# mkdir /var/www/test1/admin The requested URL/admin/index.html was not found on this server. //Added content
As shown in the figure:
Then visit:
Enter username Password:
At this point httpd's virtual hosting and user authentication are complete.
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
ClientServer*Mar 100: 21:07.427: DHCPD: DHCPDISCOVER received from client 0100.0c29.3772.04 on inter
© 2024 shulou.com SLNews company. All rights reserved.