0

tl;dr can the nginx server_name be different depending upon the client connecting IP address?

I have a nginx server that serves HTTP + HTTPS traffic to the local network and the public Internet. I want the server_name value to be different for local network clients and public Internet clients. Local network clients are in the CIDR range 192.168.1.0/24.

The pseudo-code logic is:

if $client_IP in 192.168.1.0/24 then
    server_name = www.local
else
    server_name = www.my-website.com
endif

Is this possible?

JamesThomasMoon
  • 6,169
  • 7
  • 37
  • 63
  • 1
    You can try with [map directive](https://nginx.org/en/docs/http/ngx_http_map_module.html) – Vins Mar 06 '23 at 23:30
  • The [`geo`](http://nginx.org/en/docs/http/ngx_http_geo_module.html#geo) module provides exactly what I want (not to be confused with `geoip`, `geoip2`). Unfortunately, the `geo` module is not available as an _apt_ package for my CPU architecture _armhf_. I could compile it manually, but it is a fair amount of work and has the usual drawbacks of mixing manual compile+intall with apt-managed installs. :-/ – JamesThomasMoon Mar 08 '23 at 01:09
  • related posts: [_How to install a module on nginx?_](https://stackoverflow.com/a/59993747/471376), [_How can i check if $remote_addr IP is NOT in CIDR range in nginx?_](https://serverfault.com/a/743417/116615). – JamesThomasMoon Mar 08 '23 at 01:13

0 Answers0