Nginx's difference between Root and alias

Source: Internet
Author: User
This article mainly describes the nginx about the root and alias of the difference, has a certain reference value, now share to everyone, the need for friends can refer to

Conclusion

Configure Demo:

Location XXX {    root yyy}

Browser access to XXX, the actual access is yyy/xxx
Browser access to xxx/abc.html, the actual access is yyy/xxx/abc.html
Browser access to xxx/ccc/abc.html, the actual access is yyy/xxx/ccc/abc.html

Conclusion: The root attribute will add the root value (this is YYY) before the Access Path (locaition)

Configure Demo:

Locaiton xxx {    # alias must be/end, otherwise invalid    alias yyy/}

Browser access to XXX, the actual access is YYY
Browser access to xxx/abc.html, the actual access is yyy/abc.html
Browser access to xxx/ccc/abc.html, the actual access is yyy/ccc/abc.html

Conclusion: The alias attribute will replace the value of alias (this is yyy) with the part that matches the access path (this is XXX)

Example

NGINX directory structure is as follows:

nginx/    -html/        -index.html    -logs/        -access.log    -conf/        -nginx.conf

1) This configuration, Http://localhost:8086/access.log, can see the nginx/logs/access.log, but do not expect to be able to access the HTML directory of documents

server {    listen       8086;    server_name  localhost;    Location/{        root   logs;    }}

2) This configuration, access to Http://localhost:8086/log/access.log, can see Nginx/logs/access.log;
Visit http://localhost:8086/to see nginx/html/index.html

server {    listen       8086;    server_name  localhost;    Location/{        root   html;        Index  index.html index.htm;    }    # configured to location/log/or Location/log can    location/log/{        # cannot be written logs, must have/end        alias logs/;        # The following configuration is useless, but it is convenient for you to enter localhost:8086/log/after you can see all the files under the nginx/logs/directory        autoindex on;    }}

3) This configuration, access to Http://localhost:8086/logs/access.log, can see Nginx/logs/access.log;
Visit http://localhost:8086/to see nginx/html/index.html

server {    listen       8086;    server_name  localhost;    # http://localhost:8086/access is    # nginx/html/  (then automatically shows index.html or index.htm if one of these two files exists)    # Wordy Comments: nginx/ HTML (HTML is the value of root)/(/is the location value) location    /{        root   html        ; Index  index.html index.htm;    }    # http://localhost:8086/logs/Access #    nginx/./logs/    # is the value of root, logs is the value of location    # Please compare to the 4th error configuration, Deep understanding of the root property    location/logs/{        # written./can also        root;    }}

4) Wrong configuration

server {    listen       8086;    server_name  localhost;    Location/{        root   html;        Index  index.html index.htm;    }    # This configuration is wrong, please compare it with the third configuration    # key: The root attribute will add the root value to the final path before the    # is: Http://localhost:8086/logs/access.log access:    # Nginx/logs/logs/access.log    # because: nginx/logs (root value)/logs (value of locaition)/access.log,    location/logs /{        root/logs/;    }}

Excerpt: Https://www.cnblogs.com/zhang ... This passage:
The root property specifies the value to be added to the final path, so the location of the access becomes the value of the root value/locaiton. And I don't want to add the URI of the access to the path. So you need to use the Alias property, which discards the URI and accesses the location specified by alias directly.

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.