1. Modify httpd.conf
Open the appserv installation directory, find the httpd.conf file, and remove the # sign in front of the following two lines of text.
[plain] view plaincopy
[plain] view plaincopy
II , modify httpd-vhosts.conf
Open the file and see content similar to the following. The configuration of the virtual host is also configured according to the following content. The content is explained below
[plain] view plaincopy
Note 1: NameVirtualHost specifies the IP address or domain name used by the virtual host, but it is best to use the IP address. NameVirtualHost is a necessary directive when using domain name-based virtual hosts. Multiple NameVirtualHost can be defined.
Note 2: All requests that match the NameVirtualHost or
Note 3: If you set NameVirtualHost or
ServerAdmin Administrator Email
DocumentRoot Website Directory (Note: If the path in the website directory has spaces, please add double quotes at both ends of the path)
ServerName Domain name to be bound (required)
ServerAlias to be bound The alias of a specified virtual host. (Optional, if there are multiple domain names, separate them with spaces. If not, remove the line)
Supports two wildcards: * and ?, such as *.abc.com, which means that any second-level domain name of abc.com is Accessible.
CustomLog user log file (optional, remove this line if not needed)
ErrorLog error log (optional, remove this line if not needed)
Virtual host based on IP address
[plain] view plaincopy
[plain] view plaincopy
Mixed use of various virtual hosts
[plain] view plaincopy
Problems when virtual hosts are mixed
1. Mixed use of virtual hosts can be understood like this: one line NameVirtualHost All virtual hosts defined by the directive are grouped together; the group is the same as an IP-based virtual host. That is, the entire group defined by a row of NameVirtualHost is regarded as an IP-based virtual host.
2. The port specified by the virtual host must be defined by Listen. If the virtual host does not specify a port, it is assumed to be port 80. If NameVirtualHost * is defined this way, refers to all defined ports for all addresses.
3. More specific address definitions are preferred. For example, the NameVirtualHost directive defines *:80, and an IP-based virtual host is defined as 192.168.0.1:80. If there is a request for 192.168.0.1:80 at this time, the request will be directed to 192.168.0.1:80 first. Defined virtual host. So to avoid confusion, do not define address ranges that overlap or include each other.
4. A virtual host can be both domain name-based and IP-based. Like the last virtual host in the previous example. In this way, requests that meet both definitions will be directed to the same virtual host. Sometimes this can be done when distinguishing between internal and external network access to a virtual host, because requests from the internal network may be different from requests from the external network, but they need to point to the same virtual host.
Use "_default_" virtual host
This virtual host can be understood as an IP-based virtual host
[plain] view plaincopy
Local machine proxy virtual host running on other machines
[plain] view plaincopy
Configuration example
Requirement 1:
This is an IP-based virtual host usage example
A project data application. In order to prevent normal access due to domain name resolution problems, IP is used to access the interface. For example: http://61.122.3.6:8080/ This way. The configuration of the virtual host is as follows:
1. Add a line under Listen 80 in httpd.conf, the content is: Listen 8080, that is, listen to the 8080 port
2. Configure the virtual host configuration
[plain] view plaincopy
The above introduces the apache2.2 virtual host configuration, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.