How to use nginx root, alias, and location instructions
Release: 2016-07-29 09:15:53
Original
1278 people have browsed it
1. nginx root command
1. Nginx configuration
The relevant configuration is as follows:By configuring the root directory to the "/wwwroot/html/" locationusing a virtual host Method, the host name is test. You need to configure the host file of your PC. In addition, you need to configure the nginx.conf file of the server. Add the "include vhost/t.conf;" code. Be careful not to include Chinese quotation marks2 . Prepare some files. The file list is as follows
As shown above, we have listed the "directory structure and files" under the /wwwroot/html directory. We will conduct experiments based on this directory structure later. 3. Normally access the page, as shown below
Through the above picture we can know that the access to /t/a.html is successful, that is, the "location /t/" configuration and root The cooperation is normal4. Access the non-directory structure
As shown in the above access result, we cannot access c.html. Why? In fact, the problem is not root, but "location /t/". According to this instruction, we must include "/t/" in our url, otherwise it will be invalid, and we have no other configuration in the virtual host, so we cannot access c.html
5. Root's comparison configuration
As shown above, we configure the root directory to "/wwwroot/html/t/", and then reload the nginx configuration Access the a.html file, this file It really exists in this directory, and the results are as followsDue to the existence of cache, the results in the above picture cannot really show the resultsThe test was conducted by using special parameters to break through the cache, and the results are as follows: From the picture above, it can be seen that there is no cache impact, but the page is still not foundAfter clearing the cache, test again, the results are as followsThe above is the above situation . Summary
The top of the picture is the location configuration of nginx. Pay special attention to "/t/". We must carry this information in our access before we can access it. The second line is the user’s visitThe third line is the root command of nginx. Pay special attention to the "/" in the green area that must be in one-to-one correspondence. The bottom is the directory and file display of the Linux file system. Of course, the directory is the files in the /wwwroot/html/ directory. We can understand from the above picture: the first "/" of the location instruction corresponds to the last "/" of the root instruction. Then, the directory specified by root includes the related information specified by location. Directory structure, the structure shown in the last part of the figure. During user access, the corresponding "/" must also correspond to the "/" in the location. The corresponding "/" in the picture have been marked with the same color, please pay attention! II. nginx alias alias configuration
1. Update the configuration file
The relevant configuration of the alias is as shown below, and the file system remains unchanged. Reload configuration2. Access without clearing cache
3 . Use parameter method to break through the cached results
4. Access the results after clearing the cache
5. Change the configuration file for comparison experiment
Reload the configuration file Clean browsing The server cache is then accessed as follows From the picture, we find that we can no longer access Access to c.html can be accessed. Why? ? ? Summary
From the above picture, we understand that the yellow "/" in location should correspond to the "/" in alias. Then there is the directory structure in the server. Then there is the situation during html access (relationship with location), which is similar to the situation with root above. Summary:
1. Access to the Location management server and user browser, mainly the specific part of the URL in the http request must correspond to the specific part of the location instruction. The need to correspond has been given in the two summary figures. Out! 2. Root and alias instructions mainly have directory correspondences that are different from location. 3. The last "/" of Root should correspond to the first "/" of location, and other directory structures are the same as the rest of location. Same 4. The last "/" of Alias must correspond to the last "/" of location
Copyright statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.
The above introduces how to use the nginx root, alias, and location instructions, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31