The server does not render the pages on HTTPS protocol

My goal: Setup an Apache, PHP, and HTTPS development environment with Docker

I wrote the following code and everything works perfectly except the HTTPS protocol. With HTTP I have no problems but as soon as I add HTTPS the index.php page is no longer reachable.

Don’t read the code for tomcat and postgresql.

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/docker-compose.yaml

version: '3.8'

services:
  postgresql-postgis:
    build: ./postgresql-postgis
    image: image-postgresql-postgis-eb:v.1.0
    container_name: container-postgresql-postgis-eb
    ports:
      - 6001:5432
    volumes:
      - data-postgresql:/var/lib/postgresql
    environment:
      POSTGRES_USER: "eb"
      POSTGRES_PASS: "password"
      POSTGRES_DBNAME: "gis"
      ALLOW_IP_RANGE: "0.0.0.0/0"
    restart: always
    networks:
      - eb

  pgadmin:
    build: ./pgadmin
    image: image-pgadmin-eb:v.1.0
    container_name: container-pgadmin-eb
    ports:
      - 6002:80
    volumes:
      - ./pgadmin/servers.json:/pgadmin4/servers.json
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@gmail.com
      PGADMIN_DEFAULT_PASSWORD: password
    depends_on:
      - postgresql-postgis
    restart: always
    networks:
      - eb

  tomcat:
    build: ./tomcat
    image: image-tomcat-eb:v.1.0
    container_name: container-tomcat-eb
    ports:
      - 6003:8080
      - 7003:8443
    volumes:
      - ./https/localhost-rsa-cert.pem:/usr/local/tomcat/ssl/localhost-rsa-cert.pem
      - ./https/localhost-rsa-key.pem:/usr/local/tomcat/ssl/localhost-rsa-key.pem
      - ./https/server.xml:/usr/local/tomcat/conf/server.xml
    depends_on:
      - postgresql-postgis
      - pgadmin
    restart: on-failure
    networks:
      - eb

  mysql:
    build: ./mysql
    image: image-mysql-eb:v.1.0
    container_name: container-mysql-eb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: gis
      MYSQL_USER: eb
      MYSQL_PASSWORD: password
    ports:
      - 6004:3306
    volumes:
      - data-mysql:/var/lib/mysql
    networks:
      - eb

  phpmyadmin:
    build: ./phpmyadmin
    image: image-phpmyadmin-eb:v.1.0
    container_name: container-phpmyadmin-eb
    ports:
      - 6005:80
    restart: always
    environment:
      PMA_HOST: mysql
    depends_on:
      - mysql
    networks:
      - eb

  php:
    build: ./php
    image: image-php-eb:v.1.0
    container_name: container-php-eb
    ports:
      - 6006:80
      - 7006:443
    volumes:
      - ./https/localhost-rsa-cert.pem:/etc/apache2/ssl/localhost-rsa-cert.pem
      - ./https/localhost-rsa-key.pem:/etc/apache2/ssl/localhost-rsa-key.pem
      - ./https/000-default.conf:/etc/apache2/sites-available/000-default.conf
      - ./php/serverfile:/var/www/html
    depends_on:
      - mysql
      - phpmyadmin
    networks:
      - eb

volumes:
  data-postgresql:
  data-mysql:

networks:
  eb:

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/https/000-default.conf

<VirtualHost *:80>

  ServerAdmin admin@localhost
  DocumentRoot /var/www/html
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

<VirtualHost *:443>

  SSLEngine on
  SSLCertificateFile /etc/apache2/ssl/localhost-rsa-cert.pem
  SSLCertificateKeyFile /etc/apache2/ssl/localhost-rsa-key.pem

  ServerAdmin admin@localhost
  DocumentRoot /var/www/html
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/php/serverfile/index.php

<!doctype html>
<html lang="it">
<head><title>Ciao Mondo!</title></head>
<body>
<h1>Ciao Mondo!</h1>
<?php echo "Ciao a tutti! Questo è un container Apache PHP!"; ?>
<h2>Pagine e servizi sul server:</h2>
<p><a href="http://localhost:6002/" target="_blank">Database PostgreSQL (pgAdmin)</a></p>
<p><a href="http://localhost:6003/esercitazione.1.maven/" target="_blank">Esercitazione 1 - protocollo http (Tomcat)</a></p>
<p><a href="http://localhost:6003/esercitazione.2.maven/" target="_blank">Esercitazione 2 - protocollo http (Tomcat)</a></p>
<p><a href="https://localhost:7003/esercitazione.1.maven/" target="_blank">Esercitazione 1 - protocollo https (Tomcat)</a></p>
<p><a href="https://localhost:7003/esercitazione.2.maven/" target="_blank">Esercitazione 2 - protocollo https (Tomcat)</a></p>
<p><a href="http://localhost:6005/" target="_blank">Database MySQL (phpMyAdmin)</a></p>
<p><a href="http://localhost:6006/index.php" target="_blank">Pagina corrente in php (Apache)</a></p>
<h2>Test di connessione al DB MySQL:</h2>
<?php
$host = 'mysql';
$user = 'eb';
$pass = 'password';
$conn = new mysqli($host, $user, $pass);
if ($conn->connect_error) {
    die("Connessione fallita: " . $conn->connect_error);
} else {
   echo "Connessione al DB MySQL eseguita con successo!";
}
?>
</body>
</html>

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/php/Dockerfile

FROM php:8.0-apache
LABEL Author="Nome Cognome"
RUN a2enmod ssl && a2enmod rewrite
RUN mkdir -p /etc/apache2/ssl
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
EXPOSE 80
EXPOSE 443
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN apt-get update && apt-get upgrade -y

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/phpmyadmin/Dockerfile

FROM phpmyadmin/phpmyadmin
LABEL Author="Nome Cognome"
EXPOSE 80

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/mysql/Dockerfile

FROM mysql
LABEL Author="Nome Cognome"
EXPOSE 3306
VOLUME create data-mysql

The following files with Tomcat work:
/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/https/localhost-rsa-cert.pem
/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/https/localhost-rsa-key.pem
The code I added that has problems is this:

LABEL Author="Nome Cognome"
RUN a2enmod ssl && a2enmod rewrite
RUN mkdir -p /etc/apache2/ssl
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
EXPOSE 443

Before I even try to really understand the question (I just scrolled down to see what it is about)

What is the above liine for? I mentioned in an other topic that this does not make sense.

You just created two empty folders to be a volume on the container’s root filesystem: /create and /data-mysql
Are you aware of that?

Thanks for the quick reply. I did not understand your previous comment, sorry. On my old class notes I had found “VOLUME create” as a single command. So I should just write “VOLUME data-mysql”? Is it also possible to save the data of these volumes in a folder next to the .yaml file?
I made the corrections you suggested but the problem persists.

The fact that you asked this

means that you didn’t understand what I suggested. Please, read the documentation.
You don’t even need to use that line at all, since you configure the volume from Docker compose. And that is the right way in your case.

Dockerfile: VOLUMES

So when you add the HTTPS configuration you can reach the index page on port 80 using HTTP? Please, be as specific as you can so we don’t need to read 152 lines (yes, I counted it) to figure out what you mean.

And always check the logs and error messages in the web browser and in the containers and share them.

2 Likes

First of all, thank you for your attention to my code. I have a hard time translating Docker documentation. I tried to remove the code from the Dockerfile and actually the volume still generates. I still don’t understand volumes: if I try to remove “volumes” from docker-compose.yaml, I always find an unnamed volume after typing “docker volume ls” and I don’t understand where it is generated. Another very serious problem I have is related to the management of volumes. I can’t move the volumes next to the docker-compose.yaml file. Regarding postgresql and mysql it is not a problem because with pgadmin and phpmyadmin I can recover the data. If the webapp saves images on the server I don’t know how to retrieve them. If I understand correctly, I don’t have this problem with php because in the folder “ServerDocker02/php/serverfile/” I find the images inserted by the client. I can also edit index.php and see the changes in the browser. With Tomcat I have a poke and this is a very serious problem.

Another mistake that I fear I have made regarding the version of the starting images. Regarding Tomcat / Java I’m sure I’m not wrong. My WebApps on Tomcat 10 not working, I can only use the penultimate version (Tomcat 9.x). Regarding the other images I chose at random (the first name given to me by Google). As for PostgreSQL, PostGIS, MySQL, pdAdmin, phpMyAdmin I need the latest versions.
As for Apache / PHP I would like to put the most updated version because I will write modern apps and I will install WordPress which is a very up-to-date CMS.

I am also in doubt whether to use nginx or apache. The ultimate goal is to have a server that starts tomcat or apache depending on the url. Example:
https://localhost:80/appjava > tomcat needs to start
https://localhost:80/wordpress > apache needs to start

However, I proceed in small steps because for me it is already too complex for my basic skills.

Below you can find the http version that works perfectly. When I add https the php service stops working. This fact sends my brain haywire and demoralizes me a lot.

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/https/000-default.conf

<VirtualHost *:80>

  ServerAdmin admin@localhost
  DocumentRoot /var/www/html
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

<VirtualHost *:443>

  SSLEngine on
  SSLCertificateFile /etc/apache2/ssl/localhost-rsa-cert.pem
  SSLCertificateKeyFile /etc/apache2/ssl/localhost-rsa-key.pem

  ServerAdmin admin@localhost
  DocumentRoot /var/www/html
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/https/localhost-rsa-cert.pem
/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/https/localhost-rsa-key.pem
/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/https/server.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation. The default
         SSLImplementation will depend on the presence of the APR/native
         library and the useOpenSSL attribute of the
         AprLifecycleListener.
         Either JSSE or OpenSSL style configuration may be used regardless of
         the SSLImplementation selected. JSSE style configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true">
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->
    <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
         This connector uses the APR/native implementation which always uses
         OpenSSL for TLS.
         Either JSSE or OpenSSL style configuration may be used. OpenSSL style
         configuration is used below.
    -->
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150" SSLEnabled="true" >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="ssl/localhost-rsa-key.pem"
                         certificateFile="ssl/localhost-rsa-cert.pem"
certificateKeyPassword="changeit"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/mysql/Dockerfile

FROM mysql
LABEL Author="Nome Cognome"
EXPOSE 3306

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/pgadmin/Dockerfile

FROM dpage/pgadmin4:latest
LABEL Author="Nome Cognome"
EXPOSE 80

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/pgadmin/servers.json

{
  "Servers": {
    "1": {
      "Group": "Server PostgreSQL e PostGIS",
      "Name": "Server 1",
      "Port": 5432,
      "Username": "eb",
      "Host": "postgresql-postgis",
      "SSLMode": "prefer",
      "MaintenanceDB": "postgres"
    }
  }
}

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/php/Dockerfile

FROM php:8.0-apache
LABEL Author="Nome Cognome"
EXPOSE 80
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN apt-get update && apt-get upgrade -y

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/phpmyadmin/Dockerfile

FROM phpmyadmin/phpmyadmin
LABEL Author="Nome Cognome"
EXPOSE 80

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/postgresql-postgis/Dockerfile

FROM kartoza/postgis:13.0
LABEL Author="Nome Cognome"
EXPOSE 5432

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/tomcat/Dockerfile

FROM tomcat:9.0.63-jdk11
LABEL Author="Nome Cognome"
EXPOSE 8080
EXPOSE 8443
COPY ./serverfile/*.war /usr/local/tomcat/webapps/
CMD ["catalina.sh", "run"]

/home/gi/Dropbox/SERVER/DOCKER-LINUX/ServerDocker02/docker-compose.yaml

version: '3.8'

services:
  postgresql-postgis:
    build: ./postgresql-postgis
    image: image-postgresql-postgis-eb:v.1.0
    container_name: container-postgresql-postgis-eb
    ports:
      - 6001:5432
    volumes:
      - data-postgresql:/var/lib/postgresql
    environment:
      POSTGRES_USER: "eb"
      POSTGRES_PASS: "password"
      POSTGRES_DBNAME: "gis"
      ALLOW_IP_RANGE: "0.0.0.0/0"
    restart: always
    networks:
      - eb

  pgadmin:
    build: ./pgadmin
    image: image-pgadmin-eb:v.1.0
    container_name: container-pgadmin-eb
    ports:
      - 6002:80
    volumes:
      - ./pgadmin/servers.json:/pgadmin4/servers.json
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@gmail.com
      PGADMIN_DEFAULT_PASSWORD: password
    depends_on:
      - postgresql-postgis
    restart: always
    networks:
      - eb

  tomcat:
    build: ./tomcat
    image: image-tomcat-eb:v.1.0
    container_name: container-tomcat-eb
    ports:
      - 6003:8080
      - 7003:8443
    volumes:
      - ./https/localhost-rsa-cert.pem:/usr/local/tomcat/ssl/localhost-rsa-cert.pem
      - ./https/localhost-rsa-key.pem:/usr/local/tomcat/ssl/localhost-rsa-key.pem
      - ./https/server.xml:/usr/local/tomcat/conf/server.xml
    depends_on:
      - postgresql-postgis
      - pgadmin
    restart: on-failure
    networks:
      - eb

  mysql:
    build: ./mysql
    image: image-mysql-eb:v.1.0
    container_name: container-mysql-eb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: gis
      MYSQL_USER: eb
      MYSQL_PASSWORD: password
    ports:
      - 6004:3306
    volumes:
      - data-mysql:/var/lib/mysql
    networks:
      - eb

  phpmyadmin:
    build: ./phpmyadmin
    image: image-phpmyadmin-eb:v.1.0
    container_name: container-phpmyadmin-eb
    ports:
      - 6005:80
    restart: always
    environment:
      PMA_HOST: mysql
    depends_on:
      - mysql
    networks:
      - eb

  php:
    build: ./php
    image: image-php-eb:v.1.0
    container_name: container-php-eb
    ports:
      - 6006:80
    volumes:
      - ./php/serverfile:/var/www/html
    depends_on:
      - mysql
      - phpmyadmin
    networks:
      - eb

volumes:
  data-postgresql:
  data-mysql:

networks:
  eb:

Regarding the beginning of your post that is something I will not answer here, since It is completely off topic and I see that you need so much to learn about volumes, I don’t want to discuss it here nor do I have time to do that. It is my fault, since I mentioned it, I know. Do not try to solve everything in one step. If you don’t learn the basics, you will never understand our help either when you ask about something that really requires to understand the basics. If you don’t understand the volumes, stop and learn it. There are so many sources I can’t count them. Just out of curiosity: how much you read from the training that @meyay suggested to you? I share it again: Introduction to Containers

If you prefer videos, just go to the main page of that training site: https://container.training and find one. Like this: 404 volumes - YouTube
But that’s all I can write about volumes here.

As for the rest of your post, you shared a lof of code again instead of just focusing on what the difference is between the working and non-working solution. Since you still don’t say more than

I don’t understand your question more than I understood before. Sharing code can be important but it worth nothing without detailed explanation of what you consider non-working. Tell us about your problem as if we didn’t see what you saw on the screen and we didn’t know which change caused that error because we didn’t.

As always, I hope someone else will understand, but without a deeper examination of your code, I don’t think.

1 Like

Ok, I try to reformulate but I am not interested in the volumes but in making the site work with https.