4

I got my local nginx serve 3 sites with the respective configurations below. They worked well that way in my local LAN (see below also for the dnsmasq config) when requested with A or A.domain. Now I wanted one of those sites to be available from the internet via a dyndns domain like B.domain.ddns.net.

I configured my router to forwarded port 81 (to not accidentally mask the admin interface of the router) to port 80 of my local server and added the lines currently commented out in the examples below except the default_server line.

I entered http://B.domain.ddns.net:81 as URL. It didn't work.

I assumed that maybe the subdomain somehow doesn't work with the dyndns system, so I additionally set one site to default_server.

Now that made the site available from the internet, but suddenly one of the other sites is no longer available locally, neither with C nor C.domain, instead the default one is served.

Anybody know why this happens? Or why the dyndns domain does not match in the first place? Or how I can set the access log to show me the requested site WITH the domain string? Or maybe if there is a better way to serve just one site to the internet and the others locally?

Site A

server {
  listen 80;
  listen [::]:80;
  server_name A.domain, A; 
...

Site B

server {
   listen 80;
   # used this instead of previous line after specific domain below didn't work
   # listen 80 default_server;
   listen [::]:80;
   server_name B.domain, B;
   #used this instead of previous for external access
   # server_name B.domain, B, B.domain.ddns.net; 
...

Site C

server {
   listen 80;

   server_name C, C.domain;

dnsmasq-config

strict-order
local=/heimatsender/
expand-hosts
domain=heimatsender
log-queries
dhcp-range=192.168.1.100,192.168.1.200,255.255.255.0,168h
log-dhcp
dhcp-option=option:router,192.168.1.1
dhcp-hostsfile=/etc/dnsmasq-dhcphosts

dhcp-option=15,"domain"
dhcp-option=6,192.168.1.18

cname=A.domain,A
cname=A.domain.domain,A.domain
cname=Aalias,A
cname=Aalias.domain,A.domain
cname=C,A
cname=C.domain,A.domain
cname=B,A
cname=B.domain,A.domain

Update Removing the commas in the server_name field made the sites available from local LAN again. But from the internet, only domain.ddns.net:81 works to connect to the site configured as default server. B.domain.ddns.net:81 doesn't, although configured as a server_name. More help still welcome.

Chaos_99
  • 145
  • 8

1 Answers1

9

The server_name is an exact match, unless you use wildcards or regular expression syntax. See this document for details.

The domain B.domain.ddns.net does not match any of your existing server_name expressions, so the default server will be used instead.

If there is no listen directive with a default_server modifier, the first server block (with a matching IP:PORT) will be used. Without knowing the load order of your configuration, we don't know which one that was (possibly site C as it mysteriously stopped working). Use nginx -T to see the entire configuration as read by nginx.

There is no comma separator in the server_name directive. You site B statement should perhaps be:

server_name B.domain.ddns.net B.domain B;
Richard Smith
  • 11,859
  • 2
  • 18
  • 26
  • You could have lead with that final point. Although I don't know what exactly happens WITH the commas, it could explain why it didn't match even WITH `B.domain.ddns.net` in the `server_name` line. I'll try without the commas. – Chaos_99 Sep 28 '18 at 08:47
  • Removing the commas made the sites accessible from local LAN again. Thanks. – Chaos_99 Sep 28 '18 at 20:51