This question already has an answer here:
- What are the most commonly used and basic Apache htaccess redirects? 1 answer
- htaccess redirect non-www to www with SSL/HTTPS 3 answers
- redirect various http domains to certain https domain via htaccess 1 answer
- Forcing SSL and www in .htaccess 6 answers
- Mod Rewrite - directing HTTP/HTTPS traffic to the appropriate virtual hosts 2 answers
I have a non-encrypted service running separate to apache on 8080. I'd like to hide it and redirect all traffic to it via SSL.
I have successfully setup proxy/reverse proxy so all requests to www.example.com go to port 8080.
However, I can still directly access the service if I go to http://example.com:8080. And it goes via http, not https. I can't block that with the firewall, since the service includes some of the links in the form http://www.example.com:8080. I have tried adding a virtualhost on :8080 and listen on 8080 but that doesn't work (and also breaks the proxy on *:443).
Could anyone suggest what I am doing wrong? All services run on the same ip address.
<VirtualHost *:80> ServerName example.com ServerAlias www.example.com Redirect permanent / https://www.example.com/ </VirtualHost> <VirtualHost *:8080> ServerName example.com:8080 ServerAlias www.example.com:8080 Redirect permanent / https://www.swapsk.in:443/ </VirtualHost> NameVirtualHost *:443 <VirtualHost *:443> ServerName example.com ServerAlias www.example.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html SSLEngine on SSLCertificateFile /root/cert.crt SSLCertificateKeyFile /root/key.key SSLCACertificateFile /root/ca.ca-bundle ProxyRequests Off ProxyPreserveHost On AllowEncodedSlashes NoDecode <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass /phpmyadmin ! ProxyPassReverse /phpmyadmin ! ProxyPass / http://localhost:8080/ nocanon ProxyPassReverse / http://localhost:8080/ ProxyPassReverse / http://www.example.com/ RequestHeader set X-Forwarded-Proto "https" RequestHeader set X-Forwarded-Port "443" </VirtualHost>