2016-06-28 2 views
0

nginx를 사용하여 수행하려는 작업은 인증을위한 백엔드 호출이며 응답이 성공하면 웹 사이트 1로 리디렉션합니다 (예 : -google .com) 그리고 인증이 실패하면 나는 website2 (예를 들어 페이스 북)로 리다이렉트 할 것이다.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 시작 : 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 지시문을 추가해야합니다. –