0

I am pretty computer savvy, but not with setting up web servers. I have a domain name that has an SSL certificate, so that https://example.org works and http://example.org redirects there. BUT, http://[the bare IP address] returns an insecure http version of example.org (same content). My goal is to have http://[bare IP] redirect to https://example.org. I believe we have an "elastic IP" i.e. a static IP that points to some EC2 instance.

I am running a bitnami wordpress ... "thingy" (instance? service? dunno the right term), on Ubuntu, on an AWS EC2 instance. I have tried various things in /opt/bitnami/apache2/conf/httpd.conf to redirect the IP, all have failed. I won't post what I've tried since it's from random webpages and "voodoo" (just type this and hope), to no luck. I'd rather start fresh and do it "the right way."

I gather one has to restart the apache service for changes to httpd.conf to take effect, and I've been doing this. I also turned on heavy error logging, and know where the logs are, but can't make much sense of them.

Explicit steps along the lines of "edit this file with these lines, restart apache, refresh http://[bare IP] in Firefox, the lock w/ the red slash left of the address should now have no slash" are greatly appreciated.

Here is the only content I manually added to httpd.conf (to answer a comment), and with actual Ip addr and domain name changed:

<VirtualHost *:80>
  RewriteEngine on
  RewriteCond %{REMOTE_ADDR} ^N1\.N2\.N3\.N4$
  RewriteRule ^(.*)$ https://testing.example.org/$1 [R=301,L]
</VirtualHost>
3
  • Your Apache virtual host config would be helpful, especially the misbehaving rewrite rules. Also, do you have only one virtual host enabled? Dec 1, 2019 at 19:15
  • Thanks, added to post. Also the above code is the only <VirtualHost> block in httpd.conf.
    – D Strozzi
    Dec 1, 2019 at 19:24
  • 1
    Distros like to split up httpd.conf in many files, which include each other. A request using an IP address is directed to the default virtual host: i.e. the first found in the config. I suspect there is still another VirtualHost config in /etc/apache2/sites-enabled. Either apachectl -S or apache2ctl -S should find it. Dec 1, 2019 at 19:37

1 Answer 1

6

Bitnami developer here,

You can configure Apache to only accept requests to a single domain name by adding the following configuration to the /opt/bitnami/apache2/conf/bitnami/bitnami.conf in a fresh new instance:

  • Add the next lines right below <VirtualHost _default_:80>:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^(.*)$ https://example.com$1 [R=permanent,L]
  • Add the next lines right below <VirtualHost _default_:443>:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com$
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^(.*)$ https://example.com$1 [R=permanent,L]

After that, restart the Apache service with

sudo /opt/bitnami/ctlscript.sh restart apache

Remember to replace example.com with your actual domain name.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .