Let's look at the domain name and IP, each domain name will correspond to an IP. Look at the regular domain name www.baidu.com, when the browser enters the domain name, the browser needs to find the domain name corresponding IP (in this process need to "convert" the domain name to IP, this process is called Domain name resolution. There are many servers dedicated to resolving domain names on the Internet: DNS servers, after locating the IP, and then requesting the server that the IP represents.
After we install Apache, we can test it with localhost to prove that Apache is installed successfully. Where localhost is a domain name, a special domain name, representing the "native server", its corresponding IP is 127.0.0.1.
However, we usually do not need DNS server for domain name resolution, but a text (Hosts file) to resolve the domain name. C:\Windows\System32\drivers\etc\hosts
We can open the Hosts file and add a new domain name.
Note: This file requires an administrator to be able to modify it. Therefore, we need to open the editor (such as Notepad, sublime, and so on) as an administrator and open the hosts file in that editor for modification.
:
Access by domain name www.phpstudy.com:
Appears to indicate that the www.phpstudy.com domain name setting was successful.
Troubleshoot: Why input localhosts and input www.phpstudy.com both access the same file (site) It works! It?
A: Both Localhosts and 127.0.0.1 represent native servers, and the added www.phpstudy.com corresponding IP is also 127.0.0.1, which means the input localhosts, Www.phpstudy.com and 127.0.0. Both access the native server. The location of the default home page for Apache installation is D:\amp\apache\htdocs\ (Apache installation location \htdocs). Since entering the above three access, all only into the hosts folder, and not specific to a file name (site), so Apache default display index.html file (site).
Port:
There are more than 60,000 ports in a single computer, but typically a single server provides only a few or more than 10 services. Common default ports are: Web services: 80 -Port MySQL database service: 3306 -Port Mail Service: 110 -Port mail delivery service: 25 ports and so on. Execution procedure: When a client makes a request, the server checks whether its port corresponds, and then provides the service or rejects it. For example, when the browser makes a Web request, the Apache default port is 80, so Apache provides its clients with the services it wants.
80 ports in the Apache configuration file:
Test: Enter the domain name localhost:80 press ENTER
Enter LOCALHOST:50 Press ENTER
Can be added by artificially adding a 50 port: After saving after restarting Apache test indicates that Port 50 is available.
Host Configuration:
A host can also be called a Web site, and a browser can be accessed through a domain name. The most central component of a host (web site) is the host name (domain name) and the actual folder location of the host
Name: ServerName
Actual folder location: DocumentRoot
There is a default site (htdocs) when installing Apache:
Let's change the default configuration: ServerName:www.phpstudy.com documentroot: "D:\amp\apache\my new Web"
Remember that you need to comment out the default configuration DocumentRoot, because Apache defaults to a single site, with two documentroot actual paths still executing the default path.
Restart Apache for testing: From here, the setup was successful, but the browser does not have permission to access it. (You do not have permission to access my new Web folder.) Htdocs can access it because the permissions are already set when Apache is installed)
"ServerName (www.phpstudy.com) as a museum, DocumentRoot (D:\amp\apache\my new Web) as a detailed address, the client as a person. When people go to visit the museum, according to the detailed address found, want to go in to enjoy the time, the door affixed, this library is not open to anyone "
This step we are going to break the authority.
Add permissions to the My new Web:
Open Apache configuration file
= "This is the Apache default installation when the Htdocs permission settings, there is no need to hack."
We add = "Ps:order is the order, Deny,allow is first rejected at allow (at this point the reject is meaningless). You can also reject Allow,deny first. (example: Deny from 127.0.0.2)
= "This is the default page from the global role, all the folders play a role (you can continue to add the default page, study.php, etc.), when the input domain name is not specific to a page file name, will display index.html.
After Setup, test:
Configuration is successful!
PS: Default page can also be set separately = "Valid for this folder and subordinate folders
Multi-site Configuration:
The first step is to open the Apache configuration file and find the following (multi-site configuration)
Initially commented out = "changed to
Second step, open the httpd-vhost.conf file (D:\amp\apache\conf\extra\httpd-vhost.conf)
= = no useless to delete
To set:
Step three, set the IP
Open the Hosts file (C:\Windows\System32\drivers\etc\hosts)
Add as (what domain name is set to add what)
To restart the Apache test:
PS: When multi-site configuration is performed, the default htdocs is invalidated.
Virtual Host Configuration