1

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?

2
  • I think you'll find more people to answer this kind of question on serverfault.. Commented Mar 16, 2015 at 18:28
  • thx, I'll put it up there Commented Mar 16, 2015 at 18:32

2 Answers 2

1
location /api/lang {
    alias /server/i18n-angular;
    rewrite ^ /$arg_lang.json;
}
Sign up to request clarification or add additional context in comments.

1 Comment

That's a pretty elegant solution!
0

"index" specifies index file for displaying a folder, so it's not what you need.

You require "rewrite" instead:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.