Local domain cannot be used with NGINX (Docker/Container)

Hello,

I am new to DietPi. I have Docker and Docker-compose installed and running. I already have PiHole running successfully as a container.

Now I wanted to get NGINX running as a web server in a container. That has also worked so far. But there is one thing I just can’t get right.

When I continue this tutorial (https://marcit.eu/en/2021/04/28/dockerize-webserver-nginx-php8/) and want to activate a local domain, I fail at the specification in the hosts file in the “etc” directory.

I have tried various IP entries to activate and use the local domain.

Here is my hosts file:

127.0.0.1 localhost
127.0.1.1 DietPi
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.178.1 fritz.box
192.168.178.42 phpfpm.local

The last line is the entry for the local domain. It is the IP of the Raspberry Pi in the local network. But changing the IP to “127.0.0.1” did not help either.

Following the entrys in my resolv.conf file:

  GNU nano 5.4                       resolv.conf                                
nameserver 1.1.1.1
nameserver 1.0.0.1

I cannot access the NGINX page via the local domain.

What do I have to specify where so that I can use the local domain and point it to the Docker environment ?
Is it possibly due to PiHole or the container network?

I would be very pleased to receive help!

Hi,

I guess your clients use PiHole? Correct? If yes, you need to add your local domain into PiHole as PiHole is doing your DNS resolution inside your network.

  1. login to PiHole
  2. Local DNS
  3. DNS records
  4. add your domain phpfpm.local and IP 192.168.178.42
  5. ADD

Maybe you need to restart the container.

But why you have installed PiHole and Nginx inside docker? This all could have been done without Docker using dietpi-software catalogue and you cold have saved system resources as there would be no Docker overhead.

I tried it but it is not working.

Why I installed these inside docker? I thought, if I install PiHole via the software catalogue, I could not use any other software anymore. So I could use Pihole and Nginx and other software on ONE Raspberry Pi with your software catalogue?

So I could use Pihole and Nginx and other software on ONE Raspberry Pi with your software catalogue?

That’s the basic idea of DietPi to have majority of software title working together. You just need to select Nginx as web server preference and PiHole will be installed using Nginx automatically.

Webserver Preference : [Nginx]

On Docker do you forward port 80 to your your PiHole container or to the Nginx container?
On your clients you could check DNS resolution by running nslookup phpfpm.local (on Windows) to check what IP address will be returned.

nslookup phpfpm.local
Server:         1.1.1.1
Address:        1.1.1.1#53

** server can't find phpfpm.local: NXDOMAIN

On which client did you executed this because this client is not using PiHole for DNS resolution. Or did you executed this on DietPi?

I executed it on DietPi!

This test to be done on a different client like a desktop computer. At least on the client you try to open that domain.

Okay, now I am using my Linux Laptop-Terminal to use nslookup. The following code-output was created:

nslookup phpfpm.local
Server:    192.168.178.42
Address:  192.168.178.42#53

Name:    phpfpm.local
Address: 192.168.178.42

When I am using the IP number and the Portnumber of the NGINX server (8080), I can see the “hello world” text.

But the local domain I can not using.

I guess you need to use phpfpm.local:8080

This is not working. Site was not found by browser.

did you tried to change port number on your container to have Nginx LISTEN on port 80 and move PiHole to something like 81?

BTW: this is not working as well? http://phpfpm.local:8080/

I did a test using a Nginx docker container and on my demo system I got Nginx welcome page correctly

:thinking: Maybe I have to reinstall a Nginx Container. Please Tell me which image do you have used.

I simply used the official container nginx

I installed a new nginx container and have done all the info of the workshop I linked to it in my first posting.

Now the terminal output told me the following:

web_1  | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
web_1  | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
web_1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
web_1  | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
web_1  | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
web_1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
web_1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
web_1  | /docker-entrypoint.sh: Configuration complete; ready for start up
web_1  | 2021/10/10 14:31:02 [notice] 1#1: using the "epoll" event method
web_1  | 2021/10/10 14:31:02 [notice] 1#1: nginx/1.21.3
web_1  | 2021/10/10 14:31:02 [notice] 1#1: built by gcc 8.3.0 (Debian 8.3.0-6) 
web_1  | 2021/10/10 14:31:02 [notice] 1#1: OS: Linux 5.10.60-v7l+
web_1  | 2021/10/10 14:31:02 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
web_1  | 2021/10/10 14:31:02 [notice] 1#1: start worker processes
web_1  | 2021/10/10 14:31:02 [notice] 1#1: start worker process 30
web_1  | 2021/10/10 14:31:02 [notice] 1#1: start worker process 31
web_1  | 2021/10/10 14:31:02 [notice] 1#1: start worker process 32
web_1  | 2021/10/10 14:31:02 [notice] 1#1: start worker process 33
web_1  | 2021/10/10 14:32:53 [error] 30#30: *1 "/var/www/html/index.html" is not found (2: No such file or directory), client: 192.168.178.44, server: phpfpm.local, request: "GET / HTTP/1.1", host: "192.168.178.42:8080"
web_1  | 192.168.178.44 - - [10/Oct/2021:14:32:53 +0000] "GET / HTTP/1.1" 404 153 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0"

Before I changed the docker-compose.yml file to the following:

web:
    image: nginx:latest
    ports:
        - "8080:80"
    volumes:
        - ./src:/src
        - ./default.conf:/etc/nginx/conf.d/default.conf

The following folder are existing: /var/www.

“html” folder was not found!

I don´t know what is wrong with the installation? Why was the “html” folder not created automatically?

Well the container is not going to create folder on the host system. You would need to ensure they exist before starting the contain. Something you would need to do yourself.

Still I think using docker is useless overhead. You could run Nginx together with Pihole directly on your DietPi system. Our install script would take care on everything to get both up and running without any user configuration needed. But as you prefer using docker, all configuration steps need to be done by yourself.

Could you please give me more information about the way your software is working , like you described in your last posting? Maybe any links?

What do you mean exactly? You mean our script dietpi-software? Basically it’s going to install request software from official sources and do all needed configuration steps to ensure compatibility between different apps. Basically you could have a look to our online docs. There we describe a little bit our scripts as well as software title. https://dietpi.com/docs/