1

I cannot get apache container working using SSL and my correct working path.

I am running docker containers with the composer on mac os mojave.

I generated a cert using:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt

My docker-compose.yml:

  version: "3.2"
  services:
    php:
      build: 
        context: './php/'
        args:
         PHP_VERSION: ${PHP_VERSION}
      networks:
        - backend
      volumes:
        - ${PROJECT_ROOT}/:/var/www/html/
      container_name: php
    apache:
      build:
        context: './apache/'
        args:
         APACHE_VERSION: ${APACHE_VERSION}
      depends_on:
        - php
        - mysql 
      networks:
        - frontend
        - backend
      ports:
        - "3001:443"
      volumes:
        - ${PROJECT_ROOT}/:/var/www/html/
      container_name: apache
    mysql:
      image: mysql:${MYSQL_VERSION:-latest}
      restart: always
      ports:
        - "3306:3306"
      volumes:
        - ./mysql-data:/var/lib/mysql
      networks:
        - backend
      environment:
        MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
        MYSQL_DATABASE: "${DB_NAME}"
        MYSQL_USER: "${DB_USERNAME}"
        MYSQL_PASSWORD: "${DB_PASSWORD}"
      container_name: mysql
    phpmyadmin:
      image: phpmyadmin/phpmyadmin
      depends_on:
       - mysql 
      container_name: phpmyadmin
      environment:
       - PMA_ARBITRARY=1
       - PMA_HOST=mysql
      restart: always
      ports:
       - "8080:443"
      volumes:
       - /sessions
      networks:
       - frontend
       - backend
  networks:
    frontend:
    backend:
  volumes:
      data:

My Dockerfile of apache:

    ARG APACHE_VERSION=""
    FROM httpd:${APACHE_VERSION:+${APACHE_VERSION}-}alpine

    RUN apk update; \
        apk upgrade;

    COPY server.crt /etc/apache2/ssl/server.crt
    COPY server.key /etc/apache2/ssl/server.key
    COPY server.crt /usr/local/apache2/conf/server.crt
    COPY server.key /usr/local/apache2/conf/server.key

    # Copy apache vhost file to proxy php requests to php-fpm container
    COPY demo.apache.conf /usr/local/apache2/conf/demo.apache.conf
    RUN echo "Include /usr/local/apache2/conf/demo.apache.conf" \
        >> /usr/local/apache2/conf/httpd.conf

    RUN sed -i \
        -e 's/^#\(Include .*httpd-ssl.conf\)/\1/' \
        -e 's/^#\(LoadModule .*mod_ssl.so\)/\1/' \
        -e 's/^#\(LoadModule .*mod_socache_shmcb.so\)/\1/' \
        /usr/local/apache2/conf/httpd.conf

My demo.apache.conf file:

    ServerName localhost

    LoadModule deflate_module /usr/local/apache2/modules/mod_deflate.so
    LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
    LoadModule proxy_fcgi_module /usr/local/apache2/modules/mod_proxy_fcgi.so

    <VirtualHost *:443>
        ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://php:9000/var/www/html/$1

        SSLEngine on
        SSLCertificateFile "/etc/apache2/ssl/server.crt"
        SSLCertificateKeyFile "/etc/apache2/ssl/server.key"

        DocumentRoot "/var/www/html/"
        <Directory /var/www/html/>
            DirectoryIndex index.php
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

        # Send apache logs to stdout and stderr
        CustomLog /proc/self/fd/1 common
        ErrorLog /proc/self/fd/2
    </VirtualHost>

my .env file:

    PHP_VERSION=5.6
    MYSQL_VERSION=5.7
    APACHE_VERSION=2.4.32

    DB_ROOT_PASSWORD=rootpassword
    DB_NAME=dbtest
    DB_USERNAME=otherUser
    DB_PASSWORD=password

    PROJECT_ROOT=./public_html/show_timestamp/

I tried it with https://dev:3001/ but my browser is saying that my cert is invalid and shows nothing. I tried adding it to my security-policy like so:

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain server.crt

That didn't help either.

When I hit https://localhost:3001 on my browser it's saying that my cert is invalid, but shows "It's working" instead of my php-code.

It's all working fine with just using port 80 and leaving SSL and cert out.

What am I doing wrong here? Docker logs didn't say anything bad, all working ok.

please help! I am stuck at this for days.

Thank you very much and have a nice day.

Rob
  • 14,746
  • 28
  • 47
  • 65
user3332010
  • 147
  • 1
  • 11
  • @Rup How can I look for a file /etc/apache2/sites-available/default-ssl.conf or similar? What to do? – user3332010 Jul 23 '19 at 13:54
  • I've read the [httpd docker](https://hub.docker.com/_/httpd) page now and I think I was wrong, sorry. To get a shell to have a look around in the image, `docker exec -it /bin/bash` ([from here](https://stackoverflow.com/a/33060711/243245)). It might be worth reading through the config files that are already there. (or actually maybe `docker exec -it sh` for alpine) – Rup Jul 23 '19 at 13:56
  • Anyone else? I dont know how to proceed. – user3332010 Jul 23 '19 at 16:51

0 Answers0