2

The title pretty much sums it up, we have a very simple virtual host setup in nginx protected by basic auth, so it looks like that:

server {
listen       portnumber;
server_name  *.domain.com;
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
 }
}

When I visiting say aaa.domain.com, or domain.com or any of it's subdomains it will ask for the authentication credentials if I didnt previously authenticated on this (sub)domain, so the question is: can I share authentication session between all the domains of the same virtual host in nginx, so if I successfully authenticated on one of them I wont be asked to type the login and password on any other again while the session is valid?

Maybe it is possible to (re)implement basic auth in some scripting language supported by nginx, could you please give any advice on an implementation then?

Thanks

Artem Zhirkov
  • 47
  • 1
  • 7
  • 1
    With HTTP Basic Auth, it is impossible. The alternative is HTTP digest auth. See similiar question on Apache [Using Apache's mod_auth across multiple sub-domains for single sign-on?](http://stackoverflow.com/q/339244/3604386) and [Apache .htaccess trick to authenticate only once for all subdomains?](http://serverfault.com/q/62868/218590) – masegaloeh Dec 17 '14 at 09:33
  • There is no session to be shared in basic auth - just the browser that remembers to send credentials with every request for some URLs. – Jarek Przygódzki Jul 17 '17 at 07:04

0 Answers0