search

Home  >  Q&A  >  body text

Please give me some advice on the configuration of nginx as a static file server.

I originally had such a url in the system, which was used to fetch a picture

http://localhost:8080/fs/sys_a1234567.jpg

The physical path of this picture is:

/opt/fs/a/1/a1234567.jpg

I want to complete static file processing through nginx, instead of using my 8080 port to get pictures. It should be to configure a location and then point the root to /opt/fs. But how do I split the first two digits of the image name, a 1, as the directory name? How can nginx find this file after it is split?

PHP中文网PHP中文网2751 days ago373

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-05-16 17:17:20

    You need url rewrite, the example is as follows (not tested):

    location /{
        rewrite /fs/sys_((.)(.)[^.]*.jpg) /// break;
        root /opt/fs;
    }
    

    $1,$2, $3 means referencing the content in the previous ().

    reply
    0
  • Cancelreply