This article is a mirror article of machine translation, please click here to jump to the original article.

View: 18400|Reply: 2

[Web] nginx try_files configuration in detail

[Copy link]
Posted on 11/3/2021 4:04:08 PM | | | |
try_files Try to read the file accessed by the user to the website directory, and return it directly if the first variable exists; There is no continued reading of the second variable, and if it exists, it returns directly; There is no jump directly to the third parameter.

try_files The configuration is as follows:


When the user requestshttp://localhost/example, the $uri here is /example.
try_files will try to find this file on your hard drive. If there is a file named /$root/example (where $root is the installation directory of the project code), send the contents of this file directly to the user.
Obviously, there is no file called example in the directory. Then look at $uri/, add a /, that is, see if there is a directory named /$root/example/.
If it can't find it again, it will fall back to the last option /index.php of try_files and initiate an internal "sub-request", which is equivalent to nginx initiating an HTTP request to the http://localhost/index.html

The test is as follows:



This configuration is generally used as a reverse proxy front-end interface setting (vue, angular), because when you click on the front-end page, the URL address of the browser will change, in fact, the browser does not refresh the page and access a new page.Refreshing the browser will report a 404 errorbecause, the path to access does not exist on the physical disk.

Solve the problem that the frontend (Vue) is deployed on Nginx and cannot be refreshed by F5

Documentation:The hyperlink login is visible.





Previous:Linux chown modifies the username and user group to which the folder belongs
Next:Use Pandoc to convert Markdown to Word documents in bulk under Windows
 Landlord| Posted on 5/28/2024 8:36:31 AM |
Angular deployment configuration:

 Landlord| Posted on 2/18/2025 9:10:29 AM |
Xiao Zhazha Posted on 2024-5-28 08:36
Angular deployment configuration:

Nginx (SPA application) Configure HTTP caching correctly

Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com