0

nGINX サーバーを実行しています。着信要求からカスタム HTTP ヘッダーを読み取り、別のアプリケーション サーバーにリダイレクトしたいと考えています。私は同様の質問を検索しましたが、カスタムヘッダーの作成については見つかりましたが、読み方については見つかりませんでした..

ヘッダーがこれで設定されている場合 -> "version = Version 1.0" その後、別のアプリケーションをリダイレクトする必要があります (uwsgi_pass xxxx:80 など)。

「バージョン = バージョン 2.0」に設定されている場合は、(uwsgi_pass xxxx:99) にリダイレクトする必要があります。

nginx.conf ファイルで試しました

server{
        listen 80;
        server_name xyz.com;

        if ($http_version ~ 'Version 1.0') {
            proxy_pass http://192.168.0.116:99/calc;
        }

        if ($http_version ~ 'Version 2.0') {
                proxy_pass http://192.168.0.116:99;
        }


    location /hello {
        proxy_pass http://192.168.0.116:99/calc;
            }

        }   

nGINX を再起動するとエラーが発生します

nginx: [emerg] "proxy_pass" directive is not allowed here in /etc/nginx/nginx.conf:19
nginx: configuration file /etc/nginx/nginx.conf test failed
4

1 に答える 1

1

このフォームでカスタム ヘッダーを設定するとします。

version: Version 1.0

次に、次のように nginx を構成できます。

location / {
    if ($http_version ~ 'Version 1.0') {
        uwsgi_pass localhost:8888;
    }

    if ($http_version ~ 'Version 2.0') {
        uwsgi_pass localhost:9999;
    }
}

参照: http://wiki.nginx.org/HttpCoreModule#.24http_HEADER

于 2012-09-14T07:11:02.700 に答える