I want Nginx to return all files in the same directory for access below a specific path.

Asked 2 years ago, Updated 2 years ago, 64 views

I look forward to your kind cooperation.

We are investigating whether the following structures are possible.
If you have any ideas, please let me know.

  • Assume access to the following URL (read the prefix as http:// below)
    example.com/v1/index.html
    example.com/v1/aa/index.html
    example.com/v1/aa/bb/index.html
    example.com/v1/ab/index.html
    example.com/v1/ac/index.html

  • For access to the above URL (all access under v1), I would like to return index.html directly below /var/www/ as follows.
    /var/www/index.html

  • Even if it is *.css,*.jpg, I want to return the file directly below /var/www/
    /var/www/*.jpg
    /var/www/*.css

Assume access to the following URL (read prefix as http:// below)
example.com/v1/index.html
example.com/v1/aa/index.html
example.com/v1/aa/bb/index.html
example.com/v1/ab/index.html
example.com/v1/ac/index.html

For access to the above URL (all access under v1), I would like to return index.html directly below /var/www/ as follows.
/var/www/index.html

Even in the case of *.css,*.jpg, I want to return the file directly below /var/www/
/var/www/*.jpg
/var/www/*.css

Is this possible with nginx?
I look forward to your kind cooperation.

nginx

2022-09-30 19:45

1 Answers

I solved myself.
Thank you.

 location through /tier1/(.*)/(.*){
    alias/usr/share/nginx/html/$2;
    break;
}

location~/tier1/(.*){
    alias/usr/share/nginx/html/$1;
    break;
}


2022-09-30 19:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.