0

I have these working directives:

     location /en/tools {
        alias /srv/nuxt/tools/dist/en/tools;
        try_files $uri $uri/ @cache;
     }
     location /ar/tools {
        alias /srv/nuxt/tools/dist/ar/tools;
        try_files $uri $uri/ @cache;
     }
     location /he/tools {
        alias /srv/nuxt/tools/dist/he/tools;
        try_files $uri $uri/ @cache;
     }

I have tried to combine them into one regex based directive but the server returns error 403:

location ~* ^/(en|ar|he)/tools/(.*) {
    alias /srv/nuxt/tools/dist;
    try_files $uri $uri/ @cache;
}
7
  • Don't. Use the separate location directives. May 16, 2019 at 7:46
  • 1
    You shouldn't be using alias for any of your location blocks. Use root /srv/nuxt/tools/dist;. Nginx processes prefix locations very efficiently. regular expressions need to be evaluated individually by a separate library. May 16, 2019 at 8:23
  • @MichaelHampton, would you kindly explain why is that better than using one regex based directive?
    – W.M.
    May 16, 2019 at 8:23
  • 1
    In general, yes. So if maximum performance is a design goal, the number of regular expressions should be minimised. May 16, 2019 at 8:39
  • 1
    @RichardSmith beat me to it. Yes, performance is the concern here. If you have any regex locations, then every request has to be checked against them using a regex match, in addition to the hash table lookup that the other locations use. It's usually a small difference but as your site grows the difference will grow as well. There are times you can't avoid a regex location, but this isn't one of them. See How nginx processes a request for all the gory details. May 16, 2019 at 18:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.