Home  >  Q&A  >  body text

How nginx matches static resources

As long as there is a .jgp suffix in the URL, no matter what the path is, /a/1.jpg or a/f/1.jpg or a/f/d/1.jpg, no matter how the path is written, as long as the suffix is. jpg is matched by locationton, how to write this location?

漂亮男人漂亮男人2701 days ago862

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-05-27 17:47:04

    The matching suffix is ​​.jpg

    location ~ \.jpg$ {
        ...
    }

    The matching suffix is ​​.jpg, .gif, .png

    location ~ \.(jpg|gif|png)$ {
        ...
    }

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-27 17:47:04

    About configuring static directories:

    location ~* ^.+\.(ico|gif|jpg|jpeg|png|html|htm)$ {
        root         /data;
        access_log   off;
    }

    Place the static resources or directories in the /data directory, for example: /data/img/01.jpg; then the access address is: http://localhost/img/01.jpg

    Pay attention to the file permissions in the /data directory!

    reply
    0
  • Cancelreply