How to use the nginxroot, alias, and location commands

Source: Internet
Author: User
Tags root access
: This article describes how to use the nginxroot, alias, and location commands. if you are interested in the PHP Tutorial, refer to it. I. nginx root command

1. Nginx configuration

Related configurations include:

Configure the root directory to the "/wwwroot/html/" location

When using the virtual host method, the host name is test. you need to configure the host file of your pc and nginx of the server. conf file, add "include vhost/t. conf; "code. do not include Chinese quotation marks.

2. prepare some files. the file list is as follows:

For example, we listed the "directory structure and files" in the/wwwroot/html Directory. later we will conduct an experiment based on the directory structure.

3. access the page normally, as shown in figure

We can see that the access to/t/a.html is successful, that is, the "location/t/" configuration and root cooperation are normal.

4. access non-directory structure

For example, the root cause is "location/t/". According to this instruction, we must include "/t/deny" in our url, and we cannot configure it in our virtual environment.

5. Comparison of Root configurations

Figure, we configure the root directory to "/wwwroot/html/t/", and then reload the nginx configuration

The a.html file exists in this directory. The result is as follows:

The result cannot be displayed because the cache exists.

The test results are as follows:

From the perspective, the cache is no longer affected, but the page is still not found

Run the test again after the cache is cleared. The result is as follows:

The above is the result.

Summary

The above figure shows the nginx location configuration. pay special attention to "/t/". This information must be included in our access to access.

The second line is user access

The third line is the nginx root command. Note that the "/" in the green area must be one-to-one.

The following is the directory and file display of the linux file system. of course, the directory is a file under the/wwwroot/html/directory.

We can understand that the first "/" of the location command corresponds one to one with the last "/" of the root command. Then, in the specified root directory, including the related directory structure specified by location. 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 figure must have been identified in the same color. please note!

II. nginx alias configuration

1. update the configuration file For example, the file system remains unchanged.

Reload configuration

2. access without clearing the cache

3. Results of breaking through the cache using the parameter method

4. access results after cache cleaning

5. change the configuration file for comparative experiment

Reload the configuration file

Clear the browser cache and access the following

We can no longer access

C.html

Yes. Why ???

Summary

We learned that the yellow "/" in location must correspond to the "/" in alias.

Then there is the directory structure in the server.

In addition, the relationship between html access and location is similar to that of root access.

Summary:

1. Location management server and user browser access, mainly because the specific part of the url in the http request must correspond to the specific part of the location command, which must be shown in the two summary figures!

2. Root and alias commands have different directory mappings with different locations.

3. the last "/" of the Root user must correspond to the first "/" of the location. other directories must have the same structure as those in the location.

4. the last "/" of Alias must correspond to the last "/" of location.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above describes how to use the nginx root, alias, and location commands, including some content, and hope to help those who are interested in the PHP Tutorial.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.