2016-06-17 8 views
1

私たちはいくつかのJSON Web APIを提供しています。ユーザーは、WebページにAPIキーを作成し、そのキーをHTTPヘッダー属性として使用できます。しかし、私たちは試用のための鍵なしでアクセスすることができます。この場合、nginxの設定をどのようにセットアップできますか?nginx:httpヘッダーに基づくlimit_req

sample request 

curl -H 'x-api-key:xxxx' https://api.xxx.com/xxx 

は、我々は両方の(1)及び(2)

(1) Without 'x-api-key' http header -> limit_req setting (e.g 10 request per sec) 

(2) With 'x-api-key' http header -> no limitation. 

アップデート1

これは、ほぼ同じ質問を設定する必要があります。

Rate limit in nginx based on http header

答えて

1

(奇妙に見えます。)この設定が理想的であるかどうか確認してください、私はこの方法を発見し、それが働いていたが、まだありません。私はあなたに私に何か示唆を与えることができて感謝します。

map $http_x_api_key $limit { 
    ""  $binary_remote_addr; 
    default  ""; 
} 

limit_req_zone $limit zone=limit_req_by_ip:10m rate=1r/s; 
limit_req_log_level error; 
limit_req_status 503; 

location/{ 
    limit_req zone=limit_req_by_ip burst=10 nodelay; 
} 
関連する問題