Please give me some advice on the configuration of nginx as a static file server.
PHP中文网
PHP中文网 2017-05-16 17:15:20
0
1
385

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中文网

认证高级PHP讲师

reply all(1)
刘奇

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 ().

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template