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.