Score:0

mapping the external WAN address to a Nginx variable

br flag
aag

I have an Nginx webserver within a LAN which is being addressed from the internet by NAT. The variable $server_addrcontains the internal LAN address of the server. Is there a way to map the external (internet-exposed) IP address of the webserver to an Nginx variable?

us flag
What is the actual problem you are trying to solve?
aag avatar
br flag
aag
The WAN domain has a dynamic IP. It rarely changes, but it does change. I would like Nginx to serve dynamically depending on whether the client is accessing the server from the LAN (in which case the client's remote address will be the external WAN address).
djdomi avatar
za flag
Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow.
aag avatar
br flag
aag
Dynamic DNS is a reality in many businesses as well. But it is easier for a camel to pass through the eye of a needle than to ask a question that will not elicit some patronizing comments by the self-appointed conoscendi.
Score:1
us flag

nginx binds to all interfaces by default, it does not care about the interface IP addresses. So, it serves to any IP address, whether request comes via WAN or LAN.

You need to set up a dynamic DNS for your domain. Your server would contain a daemon that updates the new external IP to the dynamic DNS provider. Then all clients would use the dynamic DNS name to connect to the server.

Another alternative is to set up a DNS server in LAN, which would resolve the server's domain name to the LAN IP address, and then make LAN clients use that DNS server.

Score:1
br flag
aag

I have solved the issue with a cronjob to update a mapping file for the external IP address:

#!/usr/bin/env bash
# enumerate authorized networks
cat > /etc/nginx/current_ip.conf <<EOF
geo \$mysite_geo {
 default        "no";
 127.0.0.1      "yes";  # network which should have access
 10.10.0.0/16   "yes";  # network which should have access
 EOF

((echo "   " && (dig +short example.com | grep '^[.0-9]*$')) \
 && echo "\"yes\"; }  # current dynamic ip") |xargs -d'\n' \
 >> /etc/nginx/current_ip.conf
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.