2016-06-28 6 views
0

nginxを使用して何をしようとしていますか?認証のバックエンドを呼び出すと、応答が成功したら私はWebサイト1にリダイレクトします.com)認証が失敗した場合は、私はwebsite2(facebookなど)にリダイレクトします。Nginxエラー - 開始nginx:nginx:未知の「状態」変数

server { 
    listen  80 default_server; 
    server_name _; 

    #charset koi8-r; 

    #access_log logs/host.access.log main; 

    location/{ 
     # root /usr/share/nginx/html; 
     # index index.html index.htm; 

     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $remote_addr; 
     proxy_set_header Host $host; 
     proxy_pass http://backend_ip_Address; 


     set $my_var 0; 
     if ($status = "200"){ 
      set $my_var 1; 
     } 

     #if($status = 4xx) { 
     # set $my_var 2; 
     #} 

     if ($my_var = 1){ 
      proxy_pass http://www.google.com; 
     } 

     if ($my_var = 2) { 
      proxy_pass http://www.facebook.com; 
     } 
    } 

    error_page 404    /404.html; 
    location = /404.html { 
     root /usr/share/nginx/html; 
    } 

    # redirect server error pages to the static page /50x.html 
    # 
    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root /usr/share/nginx/html; 
    } 
} 

私はsudoのサービスnginxの再起動を実行しようとしていたときに私が直面しています問題がある -

以下は私のnginx.conf-

user    nginx;               
worker_processes 1;                

error_log /var/log/nginx/error.log;            
pid  /var/run/nginx.pid;             

events {                   
    worker_connections 1024;             
}                    

http {                   
    include  /etc/nginx/mime.types;           
    default_type application/octet-stream;          

    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
        '[===>$status] $body_bytes_sent "$http_referer" '   
        '"$http_user_agent" "$http_x_forwarded_for"';    

    access_log /var/log/nginx/access.log main;         

    sendfile  on;               
    keepalive_timeout 65;              

    # Load config files from the /etc/nginx/conf.d directory      
    # The default server is in conf.d/default.conf        
    include /etc/nginx/conf.d/default.conf;          
} 

は、default.confファイルは以下の通りですnginx:[emerg]不明な "status"変数

nginx.conにも同じ$ statusがあります。 fログの設定で、301、200などのレスポンスコードを適切に記録していますが、同じステータス変数がdefault.confファイルで動作していません。私が間違ってやっていることについての助け?

ステータスをbody_bytes_sentヘッダーに置き換えようとしましたが、動作しています。

Google検索https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=nginx++unknown+%22status%22+variable関連する情報はhttps://www.drupal.org/node/2738983ですが、これを解決するための多くの助けはありません。

答えて

0

ステータス変数は、要求が処理され応答が返送される準備ができた後、非常に遅い段階で定義されます。

条件付きルーティングには使用できません。

通常、ロギングに使用されます。

ここでは、nginxのディレクティブの実行順序と位相について読むことができる: https://openresty.org/download/agentzh-nginx-tutorials-en.html

+0

はあなたの応答のためのアレクサンダーありがとうございます。私のユースケースは以下の通りです。 ユーザ認証情報(上記投稿のproxy_pass http:// backend_ip_Addressのもの)でnginxから認証モジュールを呼び出します。 認証が成功した場合(200)、データを取得するための別のサービスを呼び出します。 権限がない場合(301)この情報を発信者に送り返す必要があります。 どのように私はこれを達成することができますかに関する任意の提案。 – user220985

+0

http://nginx.org/en/docs/http/ngx_http_auth_request_module.html –

+0

TLDR:authの別の場所を設定し、保護された場所にauth_requestディレクティブを追加する必要があります。 –

関連する問題