root对应为前端项目dist包部署位置,proxy_pass 为对应的后端服务,在通过浏览器访问时,进行刷新或访问不到在的路径时会直接跳到Nginx的404页面。

 
  1. location / {
  2. root /home/xxx/dist;
  3. index index.html index.htm;
  4. try_files $uri $uri/ /index.html;
 

try_files含义

 
  1. try_files $uri $uri/ /index.html
  2. try_files -尝试访问对应的资源,在第一个资源访问不到时,访问第二个资源,以次向后
  3. $uri Nginx地址变量,即为访问的地址
  4. 若访问url http://www.xxx.com/index.html 则 $uri 为 /index.html
  5. $uri/ 表示一个目录,请求访问的目录,Nginx try_files可自行判断访问目的的类型 是为文件还是目录
  6. 若访问url http://www.xxx.com/user/class/ 则 $uri/ 为 /user/class/
  7. 所以以上配置的规则为 $uri $uri/ 均不是对应资源时 则返回 /index.html 页面

相关文章:

  • 2021-10-20
  • 2021-07-14
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2021-08-18
猜你喜欢
  • 2021-12-25
  • 2021-10-03
  • 2021-06-21
  • 2021-11-02
  • 2021-06-09
  • 2021-06-30
相关资源
相似解决方案