LoginSignup
4
4

More than 1 year has passed since last update.

nginxでリバースプロキシを実装するときのserver_nameディレクティブのメモ

Last updated at Posted at 2016-06-23

メモ

  • nginx.confのserverブロックでリクエストを振り分けるサーバを定義する
  • 複数のサーバにリクエストを振り分ける場合にどのサーバに振り分けるかの要因に用いられる
  • HTTPヘッダのHost値を見て判定される
  • 下記の順番で採用される
  • ワイルドカードや正規表現も使える
  • どれにもマッチしなかったらdefault_serverが指定されているサーバが採用される。それも無かったら一番上のブロックが採用される(らしい。検証の結果)
1. exact name
2. longest wildcard name starting with an asterisk, e.g. “*.example.org”
3. longest wildcard name ending with an asterisk, e.g. “mail.*”
4. first matching regular expression (in order of appearance in a configuration file)

検証

環境はその時の。

nginx.conf
server {
         listen 8082;
         server_name www.hoge.click;
         location / {
                proxy_pass http://10.0.2.124/index.click;
         }
}

server {
         listen 8082;
         server_name www.hoge.de;
         location / {
               proxy_pass http://10.0.2.124/index.de;
       }
 }

server {
        listen 8082 default_server;
        server_name localhost;
        location / {
               proxy_pass http://10.0.2.124/index.html;
        }
}

参考

Server names http://nginx.org/en/docs/http/server_names.html

4
4
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
4
4