1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Nginxでリバースプロキシする時のメモ(前方一致)

Last updated at Posted at 2020-08-31

目的

いつも混乱するのでメモ
前方一致についてだけ
(正規表現を含む場合はまた少し違ってくる)

location /hogeにすると、/hogeも/hoge/hogeもマッチする

upstream foo {
    server example.com:80 ;
}
server {

    ...

    location /hoge {           # /hogeも/hoge/hogeもマッチ
        proxy_pass http://foo  # passを含まない場合、前方一致したパスも含め結合
    }
}

location /hoge/にすると、/hogeにはマッチしない

upstream foo {
    server example.com:80 ;
}
server {

    ...

    location /hoge/ {          # /hoge/hogeにはマッチ
        proxy_pass http://foo/ # パスを含むと、前方一致したパスは省略されて結合
    }
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?