1

My goal was to ssh into the EC2 instance and configure the server to reroute traffic to serve the domain with "www" if it wasnt typed in the url.

i connected to the site via ssh and went into the bitnami.conf file:

sudo nano /opt/bitnami/apache2/conf/bitnami/bitnami.conf

in the bitnami.conf file, underneath the lines:

<VirtualHost _default_:80>
  DocumentRoot "/opt/bitnami/apache2/htdocs"

i added the following:

RewriteEngine On
RewriteCond %{HTTP_HOST} !www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

i saved and exited the file. I then restarted the server using the command:

sudo /opt/bitnami/ctlscript.sh restart apache

the command returned:

Unmonitored apache
Syntax OK
/opt/bitnami/apache2/scripts/ctl.sh : httpd stopped
Syntax OK
/opt/bitnami/apache2/scripts/ctl.sh : httpd started at port 80
Monitored apache

now my site is no longer able to be reached.

tstreets
  • 35
  • 1
  • 5
  • what were you trying to accomplish with the above change? – avigil Mar 30 '18 at 05:47
  • when a user types in the domain without the "www" in the url it automatically sends them to the url with "www" added to it. I was following a tutorial on how migrate a domain from google domains to aws – tstreets Mar 30 '18 at 05:52
  • Possible duplicate of [apache redirect from non www to www](https://stackoverflow.com/questions/1100343/apache-redirect-from-non-www-to-www) – avigil Mar 30 '18 at 05:54
  • unfortunately that didnt work. My site is still not able to be reached when i made the changes. i get redirected to my internet providers search page – tstreets Mar 30 '18 at 06:05
  • Have you tried following this guide? https://docs.bitnami.com/aws/components/apache/#how-to-redirect-wwwmyappexamplecom-to-myappexamplecom – Javier Salmeron Mar 30 '18 at 08:01
  • Before the change, was the site displayed properly if you typed with www... in address bar? – Dusan Bajic Mar 30 '18 at 08:04

1 Answers1

0

I got a very similar outcome when I tried to do the exact reverse behaviour to yours, i.e. to redirect from www.domain.name to domain.name only. The Apache error shown in the Apache error_log file was:

Certificate and private key localhost:443:0 from /opt/bitnami/apache2/conf/server.crt and /opt/bitnami/apache2/conf/server.key do not match
AH00016: Configuration Failed

I could verify this mismatch using the openssl utility. Anyway, just the timestamps of these two keys were not logically sequenced. What struck me was that the initial configuration worked, with the proper certificate CN! And I didn't touch eny of these settings. It's as if server.crt, which was now back to wwW.example.com (literally), had been overwritten. However...Backing out my changes didn't fix the problem.

The method I used when the problem arose: To restart Apache I was using sudo /opt/bitnami/ctlscript.sh restart, as per documentation referenced in one of the comments.

My solution I edited /opt/bitnami/apache2/conf/bitnami/bitnami.conf, I deactivated the VH that was pointing referring to the 443 port, including the Listen line. I restarted (started really, since it was down) Apache2, and this time I could observe some threads listening onto port 80. Bizarrely enough...despite no process seemed to listen to port 443, I was able to request https://domain.name/ perfect! And it had the proper SSL certificate attached to it.

My theory is that bitnami works as an overloading configuration: it supersedes if activated, or lets an above configuration win if not. But I don't know where this "higher level" configuration is actually sitting. Maybe it's related to the CloudFront / Load Balancer configuration? t.b.c.

To this day I don't know what provoked the fact that suddenly, the :443 configuration was pointing to the mock SSL cert was the one being used, just because I added a redirector in the VH, and rolled it back out...

Fabien Haddadi
  • 1,814
  • 17
  • 22