I have installed my new website on an AWS EC2 instance and have an elastic IP. I have already enabled HTTPS for my site. At present, the domain loads with the website without any issue, but the IP points to the Apache default page. I followed several tutorials to point the IP address back to the HTTPS version of my site. But it’s not working. But if I use https://xx.xx.xx.xx I get a "Your connection is not private" warning.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteCond %{REMOTE_ADDR} ^xx.xx.xx.xx$
RewriteRule ^(.*)$ https://mynewwebsite.com/$1 [L,R=301]
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Vhost:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName mynewwebsite.com
ServerAlias www.mynewwebsite.com
DocumentRoot /var/www/html/wordpress
ErrorLog ${APACHE_LOG_DIR}/mynewwebsite.com_error.log
CustomLog ${APACHE_LOG_DIR}/mynewwebsite.com_access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/mynewwebsite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mynewwebsite.com/privkey.pem
</VirtualHost>
</IfModule>
2
Answers
The problem solved when I replaced ServerName with my IP instead of my server FQDN. I assume this method only works, if you have added the server and domain in /etc/hosts, which I have already added.
You have to define two VirtualHost with 443 ports.
One of this contains the same configuration for your application:
One for redirect without
ServerName
andServerAlias
equal to wildcard (*).This prevent to get the default page even if the user try to make a request with a FQDN different from your configuration.
Important!: You have to respect the order of configuration.
Salvo.