title: How to send basic auth for nginx and bearer token for API auth
body: <p>I am trying to use a reverse proxy on nginx along with basic auth. My API has a design in such a way where some rest calls are open and some require a bearer token. I see an older post where someone gives an idea to use a separate variable in a request and send it to API. but i want that if the variable not available in query then don't send bearer token to API.
  Here is my configuration:</p>
  <pre><code>location / {
                  
                   auth_basic &quot;Restricted Content&quot;;
                   auth_basic_user_file /etc/nginx/.htpasswd;
                  
                   proxy_http_version 1.1;
                   proxy_pass_request_headers on;
                   proxy_set_header Host $host;
                   proxy_set_header X-Real-IP $remote_addr;
                   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                   proxy_set_header Accept-Encoding &quot;&quot;;
                   proxy_set_header Authorization &quot;Bearer $arg_token&quot;;
                   proxy_pass_header  Authorization;
   
                   #proxy_redirect off;
                   proxy_pass https://192.168.0.37/myapi/;
                   #proxy_set_header Host $host;
                   proxy_redirect default;
                    
          }
  </code></pre>
  <p>So i cant send the request to nginx service:</p>
  <p>http://my-server-ip/api/v1/customer?id=12345&amp;token=0pyLQi6CcHtoEJojPTt48qEnqDo/8NGc
  but i want that when i need to access a open api URL then no need to send any token in the request but with above setup i must need to send token even empty string as my api can ignore this token</p>
  <pre><code>http://my-server-ip/api/v1/allcustomers?token=''
  </code></pre>
  <p>Is it possible to avoide sending of empty token and solve this within nginx config that if no token found in request then add empty bearer token?</p>