Source of problem:

When doing a project to use nginx, originally configure nginx is a not too difficult thing, the result how can not access (404 is tears :().


server { ... Location / {// here it is,aliasFor root configuration, / must be used at the end, and Windows must also use /, otherwise an error will be reportedaliasD: / xc - nginx/nginx - 1.16.1 / HTML/xc - UI - PC - static - portal /; index index.html index.htm; }...Copy the code

But at first the source file added root, so I want to explore the difference between root and alias

server {
...
        location / {
            root   D:/xc-nginx/nginx-1.16.1/html/xc-ui-pc-static-portal;
            index  index.html index.htm;
        }
...Copy the code


Explore root and alias

Both root and alias are ways for Nginx to specify a file path


[root] Syntax: root path Default value: root HTML configuration segment: HTTP, server, location, if

[alias] Syntax: alias path Segment: location

Root = root = root +location = alias = alias = root = root +location = alias = location = alias

The root instance:

1
2
3

location  /ying/ {
root /www/root/html/;
}

If a request URI is/ying, a.h HTML, the web server will return on the server/WWW/root/HTML/ying, a.h HTML file.

Alias instances:

1
2
3

location   /ying/ {
alias /www/root/html/new_t/;
}

If the URI of a request is /ying/a.html, the Web server will return the/WWW /root/ HTML /new_t/a.html file on the server.


conclusion

When you encounter unfamiliar technology points, you should check the configuration in time after many times of toss and fail, so that the efficiency of solving problems will be higher.