0
votes

I have a nginx server with basic auth

 location / {
      root   /var/www/mywebsite.com;
      index  index.html index.htm;
      auth_basic "Restricted";                                #For Basic Auth
      auth_basic_user_file /etc/nginx/.htpasswd;  #For Basic Auth
  }

The server is behind an HAProxy Load Balancer. is there a way that I can have the load balancer send the username and password to nginx to authenticate?

1
How should the configuration be if the authentication is for Nginx not HA? Or is it impossible to do it?jxStackOverflow

1 Answers

0
votes

I figured it out, two step answer.

Step 1 Base64 encode the username and password. Lets say the user is johndoe and the password is abc123.

$bash: echo -n johndoe:abc123 | openssl enc -a
Output: am9obmRvZTphYmMxMjM=

Step 2 is to add it to the backend of your HAProxy config

backend application-backend
    balance     roundrobin
    log             global
    option http-server-close  
    option forwardfor
    reqadd Authorization:\ Basic\ am9obmRvZTphYmMxMjM=