Run Apache server on Ubuntu [not dockerized] + WordPress in container + SSL + AWS

Given my domain mydomain.com, I want to access my WordPress container from http://test.mydomain.com and https://test.mydomain.com.

I purchased the domain mydomain.com on Route 53 and have an EC2 instance of AWS (IP: 123.123.123.123 and public IP: http://ec2-123-123-123-123.us-east-2.compute.amazonaws.com). I have Apache Server installed on that machine and I have WordPress running in a container. My goal is to access WordPress through http(s)://test.mydomain.com.

I will go in parts in the steps:

  1. In Route 53, create the test.mydomain.com subdomain with the address 123.123.123.123.

  2. In /var/www/wp-site/ my docker-compose.yml (WordPress running on port 12345 in the container and mapped to port 80 in host) file is hosted with one volume for DB and another for the site.

  3. In /etc/apache2/sites-available/ I created the file 001-wp_site.conf:

<VirtualHost *:80>
        ProxyPreserveHost On
        ServerName test.mydomain.com
        ServerAlias *.test.mydomain.com

        ProxyPass "/" "http://127.0.0.1:12345/"
        ProxyPassReverse "/" "http://127.0.0.1:12345/"

        ErrorLog ${APACHE_LOG_DIR}/wp-site/error.log
        CustomLog ${APACHE_LOG_DIR}/wp-site/access.log combined
</VirtualHost>

FIRST PROBLEM HERE: When I access to test.mydomain.com it redirects me to http://ec2-123-123-123-123.us-east-2.compute.amazonaws.com and I don’t know why.

  1. I tried to enable SSL on the site using certbot. After following the instructions, I updated the file 001-wp_site.conf to this:
<VirtualHost *:80>
        ProxyPreserveHost On
        ServerName test.mydomain.com
        ServerAlias *.test.mydomain.com

        ProxyPass "/" "http://127.0.0.1:12345/"
        ProxyPassReverse "/" "http://127.0.0.1:12345/"

        ErrorLog ${APACHE_LOG_DIR}/wp-site/error.log
        CustomLog ${APACHE_LOG_DIR}/wp-site/access.log combined
</VirtualHost>

<VirtualHost *:443>
        SSLEngine On
        ServerName test.mydomain.com
        ServerAlias *.test.mydomain.com

        ProxyPass "/" "http://127.0.0.1:12345/"
        ProxyPassReverse "/" "http://127.0.0.1:12345/"

        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/test.mydomain.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/test.mydomain.com/privkey.pem

        ErrorLog ${APACHE_LOG_DIR}/wp-site/error.log
        CustomLog ${APACHE_LOG_DIR}/wp-site/access.log combined
</VirtualHost>
# 

SECOND PROBLEM: Not only it keeps redirecting me to the EC2 public IP but HTTPS is not working.

Can you spot the problem here?

EXTRA
I am relatively new in Docker and I have two questions:

  1. Should I have Apache Server running in another container? Or running along in the same container as where WP and DB are located? Or is it better to not run it in containers?

  2. I understand that the volumes created are persistent, but in case I want to migrate the site to another machine, would it be enough to just copy the two volumes to the new machine?

Source: StackOverflow