Search code examples
nginxurl-rewritingnginx-locationauto-versioningngx-http-rewrite-module

Configure Nginx to ignore a path in url


My website is at /root/website/, in it there is a folder static for static files, when the user visit: /static/dfd99a5/xxx.js, I wish to serve /root/website/static/xxx.js, how can I do this in nginx?


Solution

  • You can use the rewrite directive like so:

    location ~ ^(/static)/[0-9a-f]+(/.+)$ {
        rewrite ^ $1$2 break;
    }