Home > Backend Development > PHP Tutorial > How to use nginx root, alias, and location instructions

How to use nginx root, alias, and location instructions

WBOY
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:How to use nginx root, alias, and location instructionsBy 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 marks

2 . Prepare some files. The file list is as follows

How to use nginx root, alias, and location instructionsAs 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

How to use nginx root, alias, and location instructionsThrough 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 normal

4. Access the non-directory structure

How to use nginx root, alias, and location instructionsAs 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

How to use nginx root, alias, and location instructionsAs shown above, we configure the root directory to "/wwwroot/html/t/", and then reload the nginx configuration How to use nginx root, alias, and location instructionsAccess the a.html file, this file It really exists in this directory, and the results are as followsHow to use nginx root, alias, and location instructionsDue 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: How to use nginx root, alias, and location instructionsFrom 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 followsHow to use nginx root, alias, and location instructionsThe above is the above situation .

Summary

How to use nginx root, alias, and location instructionsThe 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. How to use nginx root, alias, and location instructionsReload configurationHow to use nginx root, alias, and location instructions

2. Access without clearing cache

How to use nginx root, alias, and location instructions

3 . Use parameter method to break through the cached results

How to use nginx root, alias, and location instructions

4. Access the results after clearing the cache

How to use nginx root, alias, and location instructions

5. Change the configuration file for comparison experiment

How to use nginx root, alias, and location instructionsReload the configuration file Clean browsing The server cache is then accessed as follows How to use nginx root, alias, and location instructions From the picture, we find that we can no longer access Access to c.htmlHow to use nginx root, alias, and location instructions can be accessed. Why? ? ?

Summary

How to use nginx root, alias, and location instructionsFrom 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.

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template