0

Here is my setup:

I have a Ubuntu 20.04.2 LTS machine running in VMware (vSphere client).

On this machine, I have a local Drupal website running in Docker using Wodby Docker4Drupal https://github.com/wodby/docker4drupal

The website can be accessed on the Ubuntu machine on http://drupal.localhost:8000.

The Ubuntu machine has an IP of 192.168.10.100 which I can ping from my local Windows machine which is on the same LAN (Windows computer IP address is 192.168.10.97).

Is there any way that I could access the Drupal website directly from the browser on a computer that is on the same LAN (ie. my Windows machine)?

I have tried to access http://192.168.10.100:8000 but I get a 404 page not found message. On port 80 I get ERR_CONNECTION_REFUSED. Any idea?

I shall also mention that on the Ubuntu VM, I also get the same 404 page not found if I try to reach http://0.0.0.0:8000 or http://127.0.0.1:8000 or http://localhost:8000. Only the hostname configured within the project resolves to the Drupal website (http://drupal.localhost:8000).


Here is the docker-compose.yml I am using.

version: "3.7"

services:
  mariadb:
    image: wodby/mariadb:$MARIADB_TAG
    container_name: "${PROJECT_NAME}_mariadb"
    stop_grace_period: 30s
    environment:
      MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
      MYSQL_DATABASE: $DB_NAME
      MYSQL_USER: $DB_USER
      MYSQL_PASSWORD: $DB_PASSWORD
    volumes:
      - d4d-db-data:/var/lib/mysql # Use bind mount

  php:
    image: wodby/drupal-php:$PHP_TAG
    container_name: "${PROJECT_NAME}_php"
    environment:
      PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025
    volumes:
    - ./web:/var/www/html:cached

  crond:
    image: wodby/drupal-php:$PHP_TAG
    container_name: "${PROJECT_NAME}_crond"
    environment:
      CRONTAB: "0 * * * * drush -r /var/www/html/web cron"
    command: sudo -E LD_PRELOAD=/usr/lib/preloadable_libiconv.so crond -f -d 0
    volumes:
    - ./web:/var/www/html:cached

  nginx:
    image: wodby/nginx:$NGINX_TAG
    container_name: "${PROJECT_NAME}_nginx"
    depends_on:
    - php
    environment:
      NGINX_STATIC_OPEN_FILE_CACHE: "off"
      NGINX_ERROR_LOG_LEVEL: debug
      NGINX_BACKEND_HOST: php
      NGINX_SERVER_ROOT: /var/www/html/web
      NGINX_VHOST_PRESET: $NGINX_VHOST_PRESET
    #      NGINX_DRUPAL_FILE_PROXY_URL: http://example.com
    volumes:
    - ./web:/var/www/html:cached
    labels:
    - "traefik.http.routers.${PROJECT_NAME}_nginx.rule=Host(`${PROJECT_BASE_URL}`)"

  mailhog:
    image: mailhog/mailhog
    container_name: "${PROJECT_NAME}_mailhog"
    labels:
    - "traefik.http.services.${PROJECT_NAME}_mailhog.loadbalancer.server.port=8025"
    - "traefik.http.routers.${PROJECT_NAME}_mailhog.rule=Host(`mailhog.${PROJECT_BASE_URL}`)"

  traefik:
    image: traefik:v2.0
    container_name: "${PROJECT_NAME}_traefik"
    command: --api.insecure=true --providers.docker
    ports:
    - '8000:80'
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

volumes:
  d4d-db-data:
1

If you are using the docker-compose file from that github repo it's using traefik and should correctly expose port 8000, that should default to 0.0.0.0:8000. Maybe Ubuntu firewall is blocking incoming TCP port 8000. That could explain why it works on drupal.localhost:8000 which most likely resolves to 127.0.0.1 but not from 192.* LAN.

Check Ubuntu firewall:

$ sudo ufw status

Make sure incoming TCP 8000 is allowed from anywhere, or at least for your LAN ip range. If not, you can open it with:

$ sudo ufw allow from any to any port 8000 proto tcp
5
  • sudo ufw status returns Status: inactive.
    – MrUpsidown
    May 10 at 6:33
  • I shall also mention that indeed, I am using Traefik with the default ports configuration: '8000:80' and that I also get the same 404 page not found when I try to open 0.0.0.0:8000 or localhost:8000 or 127.0.0.1:8000. I can only reach the website by using the hostname that I have configured in the project (drupal.localhost:8000).
    – MrUpsidown
    May 10 at 6:55
  • have you tried adding this to your DNS: 192.168.10.100 Drupal.localhost If you don't have a DNS server on your LAN you can add it to the host file on a client you're using. For linux it's /etc/hosts and windows it's probably C:\Windows\System32\drivers\etc\hosts
    – wowbagger
    May 10 at 11:19
  • uhmm... why would I do that? I am not trying to access Drupal.localhost from the distant machine, only the IP.
    – MrUpsidown
    May 10 at 11:21
  • "Is there any way that I could access the Drupal website directly from the browser on a computer that is on the same LAN (ie. my Windows machine)?" sounded exactly like that but hey, glad it works! Check doc.traefik.io/traefik/routing/routers/#rule for more information on Host Headers.
    – wowbagger
    May 10 at 19:50
0

It turned out it was only a setting in Traefik. I had to add a second router http rule for the nginx container in my docker-compose.yml:

- "traefik.http.routers.${PROJECT_NAME}_nginx_lan.rule=Host(`192.168.10.100`)"

So the full nginx section now looks like that:

  nginx:
    image: wodby/nginx:$NGINX_TAG
    container_name: "${PROJECT_NAME}_nginx"
    depends_on:
    - php
    environment:
      NGINX_STATIC_OPEN_FILE_CACHE: "off"
      NGINX_ERROR_LOG_LEVEL: debug
      NGINX_BACKEND_HOST: php
      NGINX_SERVER_ROOT: /var/www/html/web
      NGINX_VHOST_PRESET: $NGINX_VHOST_PRESET
    #      NGINX_DRUPAL_FILE_PROXY_URL: http://example.com
    volumes:
    - ./web:/var/www/html:cached
    labels:
    - "traefik.http.routers.${PROJECT_NAME}_nginx.rule=Host(`${PROJECT_BASE_URL}`)"
    - "traefik.http.routers.${PROJECT_NAME}_nginx_lan.rule=Host(`192.168.10.100`)"

It works fine. I can now access my Drupal website at http://192.168.10.100:8000 from any other device on the same LAN.

In my case, PROJECT_BASE_URL and PROJECT_NAME are configured in an .env file and correspond to drupal.localhost and drupal respectively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.