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:
- Created a static IP and attached it to my LAMP instance.
- Created A Records for
@.example.com
,www.example.com
,app1.example.com
, andwww.app1.example.com
. All resolving to the single static IP created earlier. - Pulled repos to individual directories in htdocs (
/opt/bitnami/apache2/htdocs
)./opt/bitnami/apache2/htdocs/main
forexample.com
and/opt/bitnami/apache2/htdocs/app1
forapp1.example.com
. - 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>
- 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
andhttp://app1.example.com
displayinghtdocs/main
and `htdocs/app11 respectively) - I ran
sudo /opt/bitnami/bncert-tool
. Enteredexample.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. - Now, when I access example.com through browser, it redirects to
https://www.example.com
(which is correct), but shows me index.html fromhtdocs
instead ofhtdocs/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:
- /opt/bitnami/apache2/conf/httpd.conf: https://pastebin.com/Vng1HAYY
- /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf: https://pastebin.com/4KsY42At
- /opt/bitnami/apache2/conf/bitnami/bitnami.conf: https://pastebin.com/S0xtgkNx
It would be of great help if someone points me out where I'm wrong?