I'm having issues with a very simple apache2 configuration and for the life of me can't figure out why it's not working. Maybe it's because I haven't done proper apache2 configuration in a year or so, I'm so convinced this should work. Can someone have a look with me?
Let me explain what I'm trying to do:
I have a local setup where i go to for example 192.168.1.10/a or 192.168.1.10/b. When I use http:// infront, I want it to redirect to https.
These are also reachable through DNS using a.domain.com and b.domain.com. Same redirecting http:// to https://
There are two .conf files activated, A and B. Both are enabled using a2ensite, as is 000-default.conf (not default-ssl, that's off):
a.conf
Code: Select all
NameVirtualHost *:80
<VirtualHost *:80>
ServerName a.domain.com
Alias /a "/var/www/a"
DocumentRoot /var/www/a
Redirect permanent "/" "https://a.domain.com"
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*) https://%{HTTP_HOST}/%{REQUEST_URI} [R,L]
</VirtualHost>
<VirtualHost *:443>
ServerName a.domain.com
Alias /a "/var/www/a"
DocumentRoot /var/www/a
<Directory "/var/www/a/">
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
</Directory>
SSLEngine On
SSLCertificateFile /etc/ssl/localcerts/apache.pem
SSLCertificateKeyFile /etc/ssl/localcerts/apache.key
</VirtualHost>
Code: Select all
NameVirtualHost *:80
<VirtualHost *:80>
ServerName b.domain.com
Alias /b "/var/www/b"
DocumentRoot /var/www/b
Redirect permanent "/" "https://b.domain.com"
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*) https://%{HTTP_HOST}/%{REQUEST_URI} [R,L]
</VirtualHost>
<VirtualHost *:443>
ServerName b.domain.com
Alias /b "/var/www/b"
DocumentRoot /var/www/b
<Directory "/var/www/b/">
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
</Directory>
SSLEngine On
SSLCertificateFile /etc/ssl/localcerts/apache.pem
SSLCertificateKeyFile /etc/ssl/localcerts/apache.key
</VirtualHost>
The most important part is that it works when visiting the domain name, but I want to get it to work through internal IP too. After two days decided to ask for help
Can someone come up with an idea why this isn't working?
Or if you'd care to share how you would do this, please go ahead.
Using latest Debian on a fresh test server with updates. I purged apache2 + php and reinstalled them, so everything is vanilla.