Sigma Pic
Sigma Pic

Reputation: 141

Nginx Proxy Manager fails to resolve localhost ip

Issue

My home server was working perfectly until yesterday.

I have an Nginx Proxy Manager to manage SSL (Let's Encrypt) with a duckdns domain that forward the requests to my home assistant that is hosted on the same server : NPM redirect to localhost.

Starting from yesterday evening, when I connect to the home server from outside, I get a "502 Bad Gateway openresty". I didn't change anything to the setup (maybe a reboot).

When I look a the logs, I have:

localhost could not be resolved (3: Host not found), client: 192.168.0.254 failed (111: Connection refused) while resolving, resolver: 127.0.0.1:53

Here is my docker compose file. Netwrok is host mode.

  nginx-proxy-manager:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    network_mode: host
    volumes:
      - /home/sigma/Server/nginx_proxy_man/data:/data
      - /home/sigma/Server/nginx_proxy_man/letsencrypt:/etc/letsencrypt

Here is my NPM redirection config extracted from NPM files:

server {
  set $forward_scheme http;
  set $server         "localhost";
  set $port           8123;

  listen 80;
listen [::]:80;

listen 443 ssl http2;
listen [::]:443 ssl http2;


  server_name domain.duckdns.org;


  # Let's Encrypt SSL
  include conf.d/include/letsencrypt-acme-challenge.conf;
  include conf.d/include/ssl-ciphers.conf;
  ssl_certificate /etc/letsencrypt/live/npm-2/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/npm-2/privkey.pem;

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_http_version 1.1;

  access_log /data/logs/proxy-host-1_access.log proxy;
  error_log /data/logs/proxy-host-1_error.log warn;

  location / {

    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_connection;
    proxy_http_version 1.1;

    # Proxy!
    include conf.d/include/proxy.conf;
  }

  # Custom
  include /data/nginx/custom/server_proxy[.]conf;
}

What I tried

I tried to replace localhost by 127.0.0.1 in NPM configuration and it works. It works because I solve the issue for him, localhost don't need to be resolved anymore => no issue

I checked my /etc/hosts file (that I didn't change) and it seems good for me :

127.0.0.1       localhost
127.0.1.1       sigma-server

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters 

Question

Do you know what happened suddenly.

What can I check to solve the issue properly ?

Upvotes: 4

Views: 2376

Answers (1)

This error may have been because the local DNS server is not present in the ip "127.0.0.1". (An update changed this probably.)

This may be checked with the file "/etc/resolv.conf". If it has the line "nameserver 127.0.0.53" then you need to adjust Nginx to use "resolver 127.0.0.53;" under "http" instead of the default "127.0.0.1".

This error is trackable through checking the output of "netstat -plnt" and making sure the local DNS server is the same that appears in the error message of Nginx (the "resolver: 127.0.0.1:53" part). In my case I saw this:

tcp  0   0 127.0.0.53:53    0.0.0.0:*   LISTEN   556/systemd-resolve

That meant that my resolve parameter in Nginx didn't match the real DNS. Another solution is configuring systemd-resolve to listen to the ip 127.0.0.1.

Upvotes: 0

Related Questions