2016-01-27 23 views
6

server_nameにワイルドカードを使用しています。私はxyz.example.comnginx設定で特定のサブドメインserver_nameを除外する方法

以外foo.comに(* .example.comのように構成)example.comのすべてのサブドメインをリダイレクトしたい

server { 
     listen   80; 
     server_name  *.example.com; 
     location/{ 
      proxy_pass  http://$1.foo.com; 
     } 
} 

を次のように私は設定を持っている私はxyz.example.com

に来るすべての要求を変更したくありません

答えて

4

少なくとも2つのサーバーブロックが必要です。また、nginxは、要求を処理するために特定のサーバーブロックを選択します。詳細は、this documentを参照してください。

次のようなxyz.example.com用サーバブロックが必要になります。

server { 
    listen  80; 
    server_name xyz.example.com; 

    location/{ 
     proxy_pass http://$1.foo.com; 
    } 
} 

その後default_serverまたはワイルドカードサーバー、などのいずれか:

server { 
    listen 80; 
    server_name *.example.com; 
    return http://foo.com/; 
} 

または:

server { 
    listen 80 default_server; 
    return http://foo.com/; 
} 
+0

ありがとう@リチャードこれは私のために働いています。 –

関連する問題