Refresh display 404 after nginx proxy

Time:2021-4-21

phenomenon

Access to the page through the home page is normal, after refreshing 404 pages

reason

The reason is that there is only one web page development mode index.html The other path is the front-end route to jump. Nginx does not correspond to this path. Of course, it is 404.

Solution

location / {
    root   /usr/nginx/app/dist/;
    index  index.html;
    try_files  $uri $uri/ /index.html;
}

summary

Add try to configuration_ Try to read a file. U r I is a variable of n g i n x, which stores the user’s access address. For example, h t p: / / l o c a L H O S T: 8200 / C h o s e Si Z E, then URI is a variable of nginx, which stores the user’s access address. For examplehttp://localhost: 8200 / choosesize, then URI is a variable of nginx, which stores the user’s access address, such ashttp://localhost: 8200 / choosesize, then URI is / choosesize; u r I / means to visit a directory, for example, h t p: / / l o c a L H O S T: 8200 / C h o s e s I Z E / then URI / means to visit a directory, for examplehttp://localhost: 8200 / choosesize / so URI / represents the access to a directory, such ashttp://localhost: 8200 / choosesize / so URI / is / choosesize /; finally/ index.html It’s the address of our home page.
If the first one exists, it will return directly; if it does not exist, it will read the second one, if it exists, it will return; if it does not exist, it will fall back to try_ The last option for files/ index.html To initiate an internal “sub request”, which is equivalent to nginx initiating an HTTP requesthttp://localhost: eight thousand and two hundred / index . HTML, and then route to the / chooseSize

Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]