6

I have queries like /api/lang?lang=en which I want to serve with nginx as /server/i18n-angular/en.json. How can I do that?

I have the following directory structure:

/public/
/server/i18n-angular/en.json

I have the following configuration, but nginx says it is wrong to use index directive at that point.

server {
  root /public
  ...
  location /api/lang {
    if ($args ~* "\?lang=(.+)") {
      set $language $1;
      index ../server/i18n-angular/$language.json;
    }
  }
} 

What directive should I use instead of index?

Barney Szabolcs
  • 171
  • 1
  • 7

1 Answers1

6

I don't see that you need a separate location at all. A simple rewrite should do.

For instance:

server {
    rewrite /api/lang /server/i18n-angular/$arg_lang.json last;
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940