Nginx configuration problem, solve!

here is my nginx configuration

server{
    listen       80;
        server_name  t1.xxx.com;
        
      location / {
            root /t001/html;
            index index.html index.htm;
      }
  
    location ^~ /c/ {
            root /t001/car/;
        }
  
      access_log  off;
}

I want to browse t1.xxx.com/c/1551059250.jpg
and return t001/car/1551059250.jpg

Why did I return 404 from the above? Ask your friends for advice! Thank you!

Jul.10,2022

in the case of using root, the file will be judged with the prefix / t001/car/c/1551059250.jpg. The actual search is / t001/car/c/1551059250.jpg , which can be changed to alias

.
location ^~ /c/ {
    alias /t001/car/;
    try_files $uri /index.html;
}
Menu