How to SSL with Apache2 mutiple port on One Ubuntu Serve within lots dockers?

Mario tsai
Oct 27, 2023

Three docker reflect port1(frontend), port2(backend), port3(other small website)

<VirtualHost *:80>
ServerName domain1.com
ServerAlias www.domain1.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain1\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain1.com$1 [L,R=301]
</VirtualHost>

<VirtualHost *:80>
ServerName domain2.com.tw
ServerAlias www.domain2.com.tw
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain2\.com\.tw$ [NC]
RewriteRule ^(.*)$ https://www.domain2.com.tw$1 [L,R=301]
</VirtualHost>

<VirtualHost *:443>
ServerName domain1.com
ServerAlias www.domain1.com
ProxyRequests off
<Proxy *>
Order allow,deny
Allow from all
</Proxy>

# Proxy
ProxyPass /admin http://ip1.ip1.ip1.ip1:port1/
ProxyPassReverse /admin http://ip1.ip1.ip1.ip1:port1/
ProxyPass / http://ip1.ip1.ip1.ip1:port2/
ProxyPassReverse / http://ip1.ip1.ip1.ip1:port2/
ProxyPreserveHost on

# SSL
SSLEngine on
SSLCertificateFile /etc/ssl/certs/certificate.crt
SSLCertificateKeyFile /etc/ssl/private/private.key
SSLCertificateChainFile /etc/ssl/certs/ca_bundle.crt
</VirtualHost>

<VirtualHost *:443>
ServerName domain2.com.tw
ServerAlias www.domain2.com.tw
ProxyRequests off
<Proxy *>
Order allow,deny
Allow from all
</Proxy>

# Proxy
ProxyPass / http://ip1.ip1.ip1.ip1:port3/
ProxyPassReverse / http://ip1.ip1.ip1.ip1:port3/
ProxyPreserveHost on

# SSL
SSLEngine on
SSLCertificateFile /etc/ssl/certs/certificate2.crt
SSLCertificateKeyFile /etc/ssl/private/private2.key
SSLCertificateChainFile /etc/ssl/certs/ca_bundle2.crt

</VirtualHost>

--

--

Mario tsai

Major in physical education. Football referee. And high interest in looking the world through the numbers.