Search code examples
nginxproxypass

can I use both http auth and sso login in single port using nginx


I have a single application available through 2 ports. One for users with sso login and other for api users using a httpAuth method. Can I use a conditional method to make both accessible through same port.

SSO Login - proxy pass

server {
    listen 80;
    location ~ ^/(web|search|data)/(.*) {
        access_by_lua_file '/opt/sso/nginx-lua-sso/sso_impl.lua';
    }
}

HTTP Login - proxy pass

server {
    listen 8080;
    location ~  ^/(web|search|data)/(.*)  {
        auth_basic "Restricted Content";
        auth_basic_user_file /opt/httpauth/conf/data/.htpasswd;
    }
}

Solution

  • You could use satisfy any directive

    location ~  ^/(web|search|data)/(.*)  {
        satisfy any;
    
        auth_basic "Restricted Content";
        auth_basic_user_file /opt/httpauth/conf/data/.htpasswd;
    
        access_by_lua_file '/opt/sso/nginx-lua-sso/sso_impl.lua';
    }