0

Good morning friends, I have the following docker-compose.yml file with which I install a reverse proxy and a LAMP stack with the phpmyadmin service.

Note: I have practically created it from scratch and have added new functionalities to it, it may not be perfect.

version: "3.8"

services:
  reverse-proxy:
    env_file:
      - .env
    container_name: Proxy-Server
    image: jwilder/nginx-proxy:alpine
    restart: always
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - /etc/nginx/certs
    ports:
      - "${LH_HOST_MACHINE_UNSECURE_HOST_PORT:-80}:80"
      - "${LH_HOST_MACHINE_SECURE_HOST_PORT:-443}:443"
    depends_on:
      - webserver
      - phpmyadmin
    networks:
      - lamp-network
    extra_hosts:
      - "${LH_WEB_SERVER_DOMAIN}:127.0.0.1"
      - "${LH_PHPMYADMIN_DOMAIN}:127.0.0.1"
    environment:
      - TRUST_DOWNSTREAM_PROXY=true
      - ENABLE_WEBSOCKETS=true
    labels:
      - "lh2.setup.description=Proxy Server"
      - "lh2.setup.role=reverse-proxy"
  webserver:
    env_file:
      - .env
    container_name: ${LH_SYSTEM_NAME}-Web-Server
    build:
      context: ./bin/${LH_PHP_ENVIRONMENT}
    restart: always
    expose:
      - 80
      - 443
    networks:
      - lamp-network
    depends_on:
      - database
    volumes:
      - ${LH_PROJECT_ROOT}:/var/www/html:rw
      - ${LH_PROJECT_ROOT}${LH_DOCUMENT_ROOT}:/var/www/html/public:rw
      - ${LH_VHOSTS_DIR}:/etc/apache2/sites-enabled
      - ${LH_PHP_INI}:/usr/local/etc/php/php.ini
      - ${LH_LOG_DIR}:/var/log/apache2
      - ${LH_LOG_CRON}:/var/log/cron
    environment:
      LH_WEB_MASTER: ${LH_WEB_MASTER}
      VIRTUAL_HOST: ${LH_WEB_SERVER_DOMAIN}
      LH_APACHE_DOCUMENT_ROOT: ${LH_APACHE_DOCUMENT_ROOT}
      LH_DOCUMENT_ROOT: ${LH_DOCUMENT_ROOT}
      HOST_MACHINE_MYSQL_PORT: ${LH_HOST_MACHINE_MYSQL_PORT}
      MYSQL_DATABASE: ${LH_MYSQL_DATABASE}
      MYSQL_ROOT_PASSWORD: ${LH_MYSQL_ROOT_PASSWORD}
      MYSQL_USER: ${LH_MYSQL_USER}
      MYSQL_PASSWORD: ${LH_MYSQL_PASSWORD}
    extra_hosts:
      - "host.docker.internal:host-gateway"
    labels:
      - "lh2.setup.description=Web Server"
      - "lh2.setup.role=webserver"
  database:
    env_file:
      - .env
    build:
      context: ./bin/${LH_DATABASE}
    container_name: ${LH_SYSTEM_NAME}-${LH_DATABASE}
    restart: always
    networks:
      - lamp-network
    ports:
      - "127.0.0.1:${LH_HOST_MACHINE_MYSQL_PORT}:${LH_HOST_MACHINE_MYSQL_PORT}"
    volumes:
      - ${LH_MYSQL_INITDB_DIR}:/docker-entrypoint-initdb.d
      - ${LH_MYSQL_DATA_DIR}:/var/lib/mysql
      - ${LH_MYSQL_LOG_DIR}:/var/log/mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${LH_MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${LH_MYSQL_DATABASE}
      MYSQL_USER: ${LH_MYSQL_USER}
      MYSQL_PASSWORD: ${LH_MYSQL_PASSWORD}
    labels:
      - "lh2.setup.description=Database Server"
      - "lh2.setup.role=database"
  phpmyadmin:
    env_file:
      - .env
    container_name: ${LH_SYSTEM_NAME}-phpmyadmin
    image: phpmyadmin/phpmyadmin
    restart: always
    depends_on:
      - database
    environment:
      VIRTUAL_HOST: ${LH_PHPMYADMIN_DOMAIN}
      PMA_HOST: database
      PMA_PORT: 3306
      PMA_USER: root
      PMA_PASSWORD: ${LH_MYSQL_ROOT_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${LH_MYSQL_ROOT_PASSWORD}
      MYSQL_USER: ${LH_MYSQL_USER}
      MYSQL_PASSWORD: ${LH_MYSQL_PASSWORD}
      UPLOAD_LIMIT: ${LH_UPLOAD_LIMIT}
      MEMORY_LIMIT: ${LH_MEMORY_LIMIT}
    volumes:
      - /sessions
      - ${LH_PHP_INI}:/usr/local/etc/php/conf.d/php-phpmyadmin.ini
    networks:
      - lamp-network
    labels:
      - "lh2.setup.description=phpMyAdmin"
      - "lh2.setup.role=phpmyadmin"
networks:
  lamp-network:
    driver: bridge

All of this works perfectly on my local Windows 11 computer, but now I would like to integrate websocket functionality, I understand that for that, I must use an SSL certificate, which is why I am enabling port 443, but I cannot find an example or in the documentation what things do to me missing or what should I add to:

  1. What changes should I make in my hosts file, currently it was necessary to add this line to redirect the http requests:
# Developer Area Docker
127.0.0.1 lh-2.dock lh-2.pma.dock
# End of section
  1. How to generate the SSL certificate using the yml file, I imagine that there must be some service image that does it and does not require altering the image of my proxy, other than incorporating or sharing volumes between containers.

I'm lost here because I don't even know where to start.

  1. I should modify in my yml file, reverse_proxy service to redirect wss:// requests to the webserver service container.

Here I am even more lost because I don't even know where to start.

  1. What should I modify in my webserver / LAMP service to capture what the reverse proxy sent it.

Here I am even more lost because I don't even know where to start. If more information is required, let me know so I can add it.

0

You must log in to answer this question.

Browse other questions tagged .