Help us understand the problem. What is going on with this article?

nginx `location ~` 正規表現でマッチした部分文字列を回収して使う方法

More than 1 year has passed since last update.

方法

location ~ ^/packages/(?<author>[a-z]+)/(?<name>[a-z]+)/?$
{
  proxy_pass http://127.0.0.1:5984/packages/_design/main/_view/main?key="$author/$name";
}
  1. (?<symbol_name>regex_pattern) で hit させ、
  2. $symbol_name 変数で取り出せる。

だそく

  • とあるサーバーシステムでバックエンドに CouchDB を置いて nginx からリバースプロクシーして一部の機能はほぼ直接一般公開、一部の機能は別に認証システムを経由、といった実装を行う事になり、表向きにはユーザー(アプリケーション)フレンドリーなURLで使用しやすいよう nginx の regex パターンでバックエンドにクエリーする目的で使用する機会があった。
    • ちなみにそのような運用では当然ながら if ( $request_method !~ ^(GET) ) など併用して意図しないユーザーからの DELETE や PUT や POST を防止したり、クエリーをプロクシー段階で破棄するなどのわりと器用な記述も nginx では手間なく簡単にできて便利。

参考

usagi
LOVE 🍣 🍵 🌶️ 🍎 🍟 🥖 🧀 LANG 🇯🇵 🇺🇸 TECH C++ C# Software | IoT Hardware | Civil Engineering
https://usagi.network
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした