Skip to content

rror while implementing multiple wordpress sites via docker compose using nginx as reverse proxy and letsencrypt #781

@rosnk

Description

@rosnk

Background: i want to host 2 wordpress domain on server using docker-compose, nginx as reverse proxy and letsencrypt.

Error msg:

"/var/www/html/.well-known/acme-challenge/UeDp_W5Er5ZjEzn7vV-n69O0L2r6NFhzzs3J9CXtasM" failed (2: No such file or directory), client: 23.178.112.106, server: "

currently my docker-compose file looks as follows:

services:

  db:  
    image: mysql:5.7
    container_name: db
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: "db"
      MYSQL_USER: "user"
      MYSQL_PASSWORD: "password"
      MYSQL_RANDOM_ROOT_PASSWORD: "1"
    volumes: 
      - ./db:/var/lib/mysql
      - ./schema/blooms_sg/:/docker-entrypoint-initdb.d
    command: '--default-authentication-plugin=mysql_native_password'
    networks:
      - app-network

// this is the first wordpress container whose database will be 'db container above'
  wordpress_abc_sg:
    depends_on: 
      - db
    image: wordpress
    container_name: wordpress
    ports:
      - 9000:80
    expose:
      - "9000"
    restart: unless-stopped
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: "user"
      WORDPRESS_DB_PASSWORD: "password"
      WORDPRESS_DB_NAME: "db"
    volumes:
      - ./wordpress_abc_sg:/var/www/html
    networks:
      - app-network


// this is second database for another domain
  db_my:
    image: mysql:5.7
    container_name: db_my
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: "db_my"
      MYSQL_USER: "user"
      MYSQL_PASSWORD: "password"
      MYSQL_RANDOM_ROOT_PASSWORD: "1"
    volumes: 
      - ./db_my:/var/lib/mysql
      - ./schema/blooms_my/:/docker-entrypoint-initdb.d
    command: '--default-authentication-plugin=mysql_native_password'
    networks:
      - app-network

//this is second wordpress site and its database is above container "db_my"
  wordpress_abc_my:
    depends_on: 
      - db_my
    image: wordpress
    container_name: wordpress_abc_my
    ports:
      - 9001:80
    expose:
      - "9001"
    restart: unless-stopped
    environment:
      WORDPRESS_DB_HOST: db_my
      WORDPRESS_DB_USER: "user"
      WORDPRESS_DB_PASSWORD: "password"
      WORDPRESS_DB_NAME: "db_my"
    volumes:
      - ./wordpress_abc_my:/var/www/html
    networks:
      - app-network

  nginx-proxy:
    depends_on:
      - wordpress_abc_my
      - wordpress_abc_sg
    image: nginx:1.15.12-alpine
    container_name: nginx-proxy
    restart: unless-stopped
    ports:
      - "80:80"
    volumes:
      - ./wordpress_abc_sg:/var/www/html/wordpress_abc_sg
      - ./wordpress_abc_my:/var/www/html/wordpress_abc_my
      - ./nginx-conf:/etc/nginx/conf.d
      - certbot-etc:/etc/letsencrypt
    networks:
      - app-network

  certbot:
    depends_on:
      - nginx-proxy
    image: certbot/certbot
    container_name: certbot
    volumes:
      - certbot-etc:/etc/letsencrypt
      - ./wordpress_abc_sg:/var/www/html/wordpress_abc_sg
      - ./wordpress_abc_my:/var/www/html/wordpress_abc_my
    command: certonly --webroot --webroot-path=/var/www/html --email [email protected] --agree-tos --no-eff-email --staging -d abc.my -d www.abc.my -d abc.sg -d www.abc.sg

volumes:
  certbot-etc:
  wordpress_abc_my:
  wordpress_abc_sg:
  db:
  db_my:

networks:
  app-network:
    driver: bridge  

My nginx.conf looks like following:

server {
        listen 80;
        listen [::]:80;

        server_name blooms.sg www.blooms.sg;

        index index.php index.html index.htm;

        root /var/www/html/wordpress_abc_sg;

        location ~ /.well-known/acme-challenge {
                allow all;
                root /var/www/html/wordpress_abc_sg;
        }

        location / {
                try_files $uri $uri/ /index.php$is_args$args;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass wordpress_abc_sg:9000;
                fastcgi_index index.php;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_path_info;
        }

        location ~ /\.ht {
                deny all;
        }
        
        location = /favicon.ico { 
                log_not_found off; access_log off; 
        }
        location = /robots.txt { 
                log_not_found off; access_log off; allow all; 
        }
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
                expires max;
                log_not_found off;
        }
}



server {
        listen 80;
        listen [::]:80;

        server_name blooms.my www.blooms.my;

        index index.php index.html index.htm;

        root /var/www/html/wordpress_abc_my;

        location ~ /.well-known/acme-challenge {
                allow all;
                root /var/www/html/wordpress_abc_my;
        }

        location / {
                try_files $uri $uri/ /index.php$is_args$args;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass wordpress_abc_my:9001;
                fastcgi_index index.php;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_path_info;
        }

        location ~ /\.ht {
                deny all;
        }
        
        location = /favicon.ico { 
                log_not_found off; access_log off; 
        }
        location = /robots.txt { 
                log_not_found off; access_log off; allow all; 
        }
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
                expires max;
                log_not_found off;
        }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions