0

After hours and hours of efforts on research, I'm posting this. I'm trying to add a domain and its sub-domain on a single static IP created in LAMP instance in Amazon Lightsail, and add Let's Encrypt SSL certificate to both. Before adding SSL, I had my virtual hosts working properly. Files from correct directory were being served as defined in httpd-vhosts.conf. But, after running bitnami's bncert-tool to add SSL, https and www redirections, things got messed up.

A detailed explanation of issue:

  1. Created a static IP and attached it to my LAMP instance.
  2. Created A Records for @.example.com, www.example.com, app1.example.com, and www.app1.example.com. All resolving to the single static IP created earlier.
  3. Pulled repos to individual directories in htdocs (/opt/bitnami/apache2/htdocs). /opt/bitnami/apache2/htdocs/main for example.com and /opt/bitnami/apache2/htdocs/app1 for app1.example.com.
  4. Put below content in /opt/bitnami/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot "htdocs/main"
    ServerName realtypillar.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "htdocs/proutil"
    ServerName pro-util.realtypillar.com
</VirtualHost>
  1. Added statement 'Include "/opt/bitnami/apache2/conf/extra/httpd-vhosts.conf"' in "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf". (I was able to access http://example.com and http://app1.example.com displaying htdocs/main and `htdocs/app11 respectively)
  2. I ran sudo /opt/bitnami/bncert-tool. Entered example.com app1.example.com on Domain List prompt. Enabled http to https option, enabled non-www to www option, and disabled www to non-www option when prompted. Ran the process successfully with no warning or error message.
  3. Now, when I access example.com through browser, it redirects to https://www.example.com (which is correct), but shows me index.html from htdocs instead of htdocs/main as specified in vhost config. And when I access app1.example.com, it doesn't redirect to https nor adds www prefix in url. But it loads files from the correct directory i.e. htdocs/app1.

---EDIT---

Below are my httpd conf files for reference:

It would be of great help if someone points me out where I'm wrong?

1 Answers1

0

Bitnami Engineer here,

The Bitnami HTTPS configuration tool only updates the SSL configuration of the main virtual host (the one inside the /opt/bitnami/apache2/conf/bitnami/bitnami.conf file) so if you have custom virtual hosts, you will need to modify them manually using the SSL certificates the tool created. In your case, you will need to use this configuration in the httpd-vhosts.conf file you created

<VirtualHost *:80>
    DocumentRoot "/opt/bitnami/apache2/htdocs/main"
    ServerName realtypillar.com
    ServerAlias realtypillar.com www.realtypillar.com
    # BEGIN: Enable HTTP to HTTPS redirection
    RewriteEngine On
    RewriteRule ^/(.*) https://realtypillar.com/$1 [R,L]
    # END: Enable HTTP to HTTPS redirection
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/opt/bitnami/apache2/htdocs/proutil"
    ServerName pro-util.realtypillar.com
    ServerAlias pro-util.realtypillar.com www.pro-util.realtypillar.com
    # BEGIN: Enable HTTP to HTTPS redirection
    RewriteEngine On
    RewriteRule ^/(.*) https://pro-util.realtypillar.com/$1 [R,L]
    # END: Enable HTTP to HTTPS redirection
</VirtualHost>

<VirtualHost _default_:443>
    DocumentRoot "/opt/bitnami/apache2/htdocs/main"
    ServerName realtypillar.com
    ServerAlias realtypillar.com www.realtypillar.com
        # BEGIN: Enable www to non-www redirection
        RewriteEngine On
        RewriteCond %{HTTP_HOST} !^realtypillar.com$
        RewriteRule ^(.*)$ https://realtypillar.com$1 [R=permanent,L]
        # END: Enable www to non-www redirection
    <Directory "/opt/bitnami/apache2/htdocs/main">
        Options -Indexes +FollowSymLinks -MultiViews
        AllowOverride All
    </Directory>
    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apache2/conf/realtypillar.com.crt"
    SSLCertificateKeyFile "/opt/bitnami/apache2/conf/realtypillar.com.key"
</VirtualHost>

<VirtualHost _default_:443>
    DocumentRoot "/opt/bitnami/apache2/htdocs/proutil"
    ServerName pro-util.realtypillar.com
    ServerAlias pro-util.realtypillar.com www.pro-util.realtypillar.com
        # BEGIN: Enable www to non-www redirection
        RewriteEngine On
        RewriteCond %{HTTP_HOST} !^pro-util.realtypillar.com$
        RewriteRule ^(.*)$ https://pro-util.realtypillar.com$1 [R=permanent,L]
        # END: Enable www to non-www redirection
    <Directory "/opt/bitnami/apache2/htdocs/proutil">
        Options -Indexes +FollowSymLinks -MultiViews
        AllowOverride All
    </Directory>
    SSLEngine on
    SSLCertificateFile "/opt/bitnami/apache2/conf/realtypillar.com.crt"
    SSLCertificateKeyFile "/opt/bitnami/apache2/conf/realtypillar.com.key"
</VirtualHost>

Just for the record, we talked about all these changes in this thread of the Bitnami Community forum.

Jota Martos
  • 301
  • 1
  • 4