1, virtual directory
HTTPD Virtual directory facilitates site management and maintenance, content classification. For example
Hhtpd://www.benet.com/news News
Httpd://www.benet.com/edu Learning
Take the redhat6.5 system as an example to configure (system default comes with httpd service), first modify the httpd.conf configuration file,
(1) Build a Web site www.benet.com
Vim/etc/httpd/conf/httpd.conf
Add site Home Document index.html
(2) and build a DNS service to resolve the domain name.
Installing the BIND Package
Vim/etc/named.conf
Vim/etc/named.rfc1912.zones
In the browser input domain name www.benet.com can see the page information just modified.
(3) Setting up the virtual directory
Include a sentence in the httpd.conf configuration file, the include conf.d/*.conf indicates that httpd in addition to the main configuration file contains a configuration file in the conf.d/directory, so we can/etc/httpd/ Create a separate configuration file for the virtual directory under the CONF.D directory.
Vim/etc/httpd/conf/httpd.conf
Create a virtual directory site and prepare a Web page document for the virtual directory
Restart the HTTPD service to view the first page of the virtual directory in the browser input www.benet.com/test
Service httpd Restart
2, User authorized access
Based on the previous setting of the virtual directory, we give the Web page of the virtual directory a user authorization limit.
(1) Modify the configuration file of the virtual directory vdir.conf
(2) Create user authentication data file
HTTPD's Basic authentication determines whether a user is allowed to access by verifying the user name and password combination. User accounts authorized for access need to be established in advance and stored in a fixed data file. Using a dedicated HTPASSWD utility, you can create an authorized user data file and maintain the user account in it.
When you use the HTPASSWD tool, you must specify the location of the user data file, and the Add-C option indicates that you created the new file, and the new user data file location is specified as/etc/httpd/user based on the configuration file you just set
(3) Verifying User access authorization
When you visit Www.benet.com/test Web page again, the browser will first pop up the authentication dialog box, only the correct user name and password can be entered to access the page
3, domain-based virtual host
Use a httpd server to build two virtual web hosts www.benet.com and www.accp.com with an IP address of 192.168.30.15
(1) Provide domain name resolution for virtual host
In reality, you need to register the domain name of each virtual Web site with your DNS service provider so that when you access any of these virtual sites, you end up with the same IP address, and in the experiment we build a DNS service on a single host.
Based on the experiment, we add the accp.com zone to the configuration file and the database file Accp.com.zone. Where the settings are the same as "www--->192.168.30.15". The key configuration steps are as follows;
Vim/etc/named.rfc1912.zones
(2) Create a virtual host configuration file vhost.conf
Create a vhost.conf file under the/ETC/HTTPD/CONF.D directory
Cd/etc/httpd/conf.d
Vim vhost.conf
Use the Namevirtualhost configuration item to specify the IP address that provides the virtual host service.
Use <virtualhost listening address >........</VirtualHost> area Configuration to establish separate configuration content for each virtual Web host, including admin mailbox, Web root directory, website name, log file storage location
(3) Create sites and Web documents for each virtual web based on configuration file settings
(4) Open a browser on the client to access the virtual Web host
4, Port-based virtual host
Port-based virtual hosts are typically used only for the same Web site, and the IP address is often the same for the site name, but different TCP ports provide access to different Web content. The port number of the server should be explicitly indicated when the browser accesses a non-80 port. such as access to http://www.benet.com:8080/.
Add a 8080-port virtual Web service based on the Web service www.benet.com just now
Modify the listening port to 8080,
Specifies that the Web root directory is/opt/benet8080 the rest of the configuration.
Create a site and a Web page document for a 8080-port virtual host
Add a listening address to the Master profile httpd.conf Listen 192.168.30.15:8080
Open the client browser to access www.benet.com:8080 virtual Web page content
Apache builds multiple Web sites (virtual hosts) on one server This approach is only available for small and midsize businesses, with less traffic and small load
Apache Configuration and application, virtual directory, access control, virtual Web host (multi-domain; multiport),