<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">figured it out<div><br></div><div>using lua-resty-http</div><div><br></div><div>i created a simple lua script which checks both uris and returns the correct url for the active one:</div><div><br></div><div><div>local http = require "resty.http"</div><div>local httpc = http.new()</div><div>local res1, err1 = httpc:request_uri("<a href="https://authelia1.domain.net">https://authelia1.domain.net</a>", {</div><div> method = "GET",</div><div> keepalive_timeout = 60000,</div><div> keepalive_pool = 10,</div><div> ssl_verify = false</div><div>})</div><div>if res1.status == 200 then</div><div> ngx.var.authelia_uri = '<a href="https://authelia1.domain.net">https://authelia1.domain.net</a>'</div><div>else</div><div> local res2, err2 = httpc:request_uri("<a href="https://authelia2.domain.net">https://authelia2.domain.net</a>", {</div><div> method = "GET",</div><div> keepalive_timeout = 60000,</div><div> keepalive_pool = 10,</div><div> ssl_verify = false</div><div> })</div><div> if res2.status == 200 then</div><div> ngx.var.authelia_uri = '<a href="https://authelia2.domain.net">https://authelia2.domain.net</a>'</div><div> end</div><div>end</div></div><div><br></div><div>then on my nginx config i have:</div><div><br></div><div>server {</div><div> location / {</div><div> set $authelia_uri "";<br></div><div> rewrite_by_lua_file /etc/nginx/health_check.lua;<br></div><div> add_header X-Authelia-Uri "$authelia_uri"; # just for debugging</div><div><br></div><div> auth_request /authelia;</div><div> error_page 401 =302 $authelia_uri/?rd=$target_url;<br></div><div> }<br></div><div> set upstream_authelia $authelia_uri/api/verify;</div><div>}</div><div><br></div><div>With this my app is protected with the active authelia server.</div><div><br></div><div>Not sure if the best setup but it works.</div><div><br></div><div>Thanks</div></div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 19, 2023 at 11:06 AM Dave Macias <<a href="mailto:davama@gmail.com">davama@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>Hope you are doing well.</div><div>We currently use Authelia to authenticate users but want to add a redundant Authelia server so that users can continue to access the content.</div><div><br></div><div>Put simply our current nginx config is:</div><div><br></div><div>server {</div><div> location / {</div><div> auth_request /authelia;<br></div><div> error_page 401 =302 <a href="https://authelia_cluster/?rd=$%7BDOLLAR%7Dtarget_url" target="_blank">https://authelia1.domain.net/?rd=$target_url</a>;<br></div><div> }<br></div><div> set upstream_authelia <a href="https://authealia1.domain.net/api/verify" target="_blank">https://authelia1.domain.net/api/verify</a>;</div><div> location /authelia {</div><div> internal;<br></div> proxy_pass $upstream_authelia;<br><div> }</div><div>}</div><div><br></div><div>Things I have tried:</div><div><br></div><div>With <a href="https://github.com/openresty/lua-resty-upstream-healthcheck" target="_blank">lua-resty-upstream-healthcheck</a> and the below upstream:<br></div><div><br></div><div>upstream authelia_cluster {<br> least_conn;<br> server <a href="http://authelia1.domain.net:443" target="_blank">authelia1.domain.net:443</a>;<br> server authelia2.domain:443 backup;<br> keepalive 60;<br>}<br></div><div><br></div><div>With this I am able to dynamically render content based on the available upstream authelia server but cannot translate that to authentication with `auth_request`.</div><div><br></div><div>location /test {</div><div> proxy_pass <a href="https://authelia_cluster/metrics" target="_blank">https://authelia_cluster/metrics</a>;</div><div>}<br><br>My guess as to most simplest solution is to dynamically set the upstream_authelia variable and the error_page setting based on the available upstream authelia_cluster server but I am not sure how.</div><div><br></div><div>Any input is much appreciated!<br><br>Best,</div><div>Dave</div><div><br></div><div><br></div></div>
</blockquote></div>