A. Nginx root Command
1. Nginx Configuration
related configurations such as:
by configuring the root directory to the "/wwwroot/html/" location
in the virtual host method, the host name is test, you need to configure your own PC's host file, in addition to configure the server's nginx.conf file, add "include vhost/t.conf;" Code, take care not to bring Chinese quotation marks
2. Prepare some documents, the file list is as follows
For example, we will list "directory Structure and Files" under the/wwwroot/html directory, and we will experiment with this directory structure.
3. Normal access page, display as
we can understand that access to/t/a.html success, that is, the "location/t/" configuration and root mate is normal
4. Accessing a non-directory structure
such as access results, we cannot access c.html, why, in fact, the problem is not root, is "location/t/", according to this instruction, we must include "/t/" in our URL, otherwise invalid, and we have no other configuration in the virtual host, Therefore cannot access c.html
5. Root comparison configuration
figure, we configure the root directory to "/wwwroot/html/t/", then reload the Nginx configuration
access the a.html file, this file is real in this directory, the results are as follows
results cannot be truly indicated due to a cache presence
with special parameters to break through the cache for testing, the results are as follows:
from the look, there has been no slow effect, but still no page found
clean up the cache and test again, the results are as follows
The result above is the above situation.
Summary
The top of the figure is the configuration of Nginx location, paying special attention to "/t/", we must carry this information in the visit in order to access.
the second line is the user's access
The third line is nginx root command, pay special attention to the green area "/" must be one by one corresponding.
The bottom is the Linux file system directory and file display, of course, the directory is the/wwwroot/html/directory files.
from what we can understand: the first "/" of the location instruction is one by one corresponding to the last "/" of the root command, and then, in the specified directory of root, includes the associated directory structure specified by location, and the structure shown in the last part of the diagram.
in user access, the corresponding "/" must also correspond to the "/" in the location. The corresponding "/" in the picture should have been identified with the same color, please note!
Two Nginx Alias aliases Configuration
1. Update the configuration file
The associated configuration of the alias, such as the file system unchanged.
Reload Configuration
2. Do not clean up the cache in the case of access
3. Using parametric method to break through the results of the cache
4. Clean up the cache after accessing the results
5. Change the configuration file for comparison experiments
Reload the configuration file
clean up the browser cache and access the following
found out we couldn't access
Visit c.html
can be accessed. Why???
Summary
from what we learned, the yellow "/" in location corresponds to "/" in Alias.
Then there is the directory structure in the server.
Then there is the case of HTML access (the same location relationship), similar to the above root.
Summary:
1. Location Management Server and user browser access, mainly in the HTTP request URL in the specific part of the location command to correspond to specific parts, need to correspond in two summary of the figure has been given!
2. Root and alias directives are mainly directory correspondence with location different
3. The last "/" of root must correspond to the first "/" of the location, the other directory structure is the same as the rest of the location
4. The last "/" of alias corresponds to the last "/" of the location.
Copyright notice: This article is the original blogger article, not allowed to be reproduced without the Bo master.
Above describes the Nginx root, alias, location instructions to use, including aspects of the content, I hope to be interested in PHP tutorial friends helpful.