Score:0

Nginx - If IP then proxy_pass else return 403

ca flag

I am trying to proxy_pass users with certain IPs to http://server1 and certain other users to http://server2. I'd like to return 403 if the user doesn't match any IP. Here's what I have:

geo $userGroup1 {
        default 0;
        192.168.178.2 1;
}
geo $userGroup2 {
        default 0;
        192.168.178.3 1;
}

server {
        listen 80 default_server;
        listen [::]:80 default_server;
         
        server_tokens off;
        server_name _;

        index index.html index.htm index.nginx-debian.html;
        
        server_name _;

        location / {
            if ($userGroup1) {
                    proxy_pass http://server1 
            }
            if ($userGroup2) {
                    proxy_pass http://server2
            }
            
            # return 403 <-- returns 403 for all users
            
        }
}

How would my config need to be changed?

djdomi avatar
za flag
Does this answer your question? [Nginx - How to redirect users with certain IP to special page](https://serverfault.com/questions/380642/nginx-how-to-redirect-users-with-certain-ip-to-special-page)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.