title: Nginx error -Starting nginx: nginx: emerg unknown "status" variable
body: <p>What I am trying to do using nginx is- to call a backend for authentication and if the response is successful I will redirect to website 1 (for example -google.com) and if authentication fail I will redirect to website2(facebook for example).</p>
  
  <p>Below is my nginx.conf-</p>
  
  <pre><code>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" '   
                    '[===&gt;$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;                                      
  }  
  </code></pre>
  
  <p>The default.conf file is as below - </p>
  
  <pre><code>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;
      } 
  }
  </code></pre>
  
  <p>The issue I am facing is when I am trying to execute sudo service nginx restart with this configuration I am getting below error-
  Starting nginx: nginx: [emerg] unknown "status" variable</p>
  
  <p>The same $status is also present in nginx.conf log configuration and it's logging the response code properly like 301, 200 etc. But the same status variable is not working in default.conf file. Any help on what I am doing wrong?</p>
  
  <p>I tried replacing status with body_bytes_sent header and it's works.</p>
  
  <p>By google search <a href="https://www.google.co.in/webhp?sourceid=chrome-instant&amp;ion=1&amp;espv=2&amp;ie=UTF-8#q=nginx%20%20unknown%20%22status%22%20variable" rel="nofollow">https://www.google.co.in/webhp?sourceid=chrome-instant&amp;ion=1&amp;espv=2&amp;ie=UTF-8#q=nginx++unknown+%22status%22+variable</a> only related information is <a href="https://www.drupal.org/node/2738983" rel="nofollow">https://www.drupal.org/node/2738983</a> but no much help to resolve this.</p>