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 *:8080>
    ServerName example.com:8080
    ServerAlias www.example.com:8080
    Redirect permanent / https://www.swapsk.in:443/

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
    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"


marked as duplicate by Simon Hayter May 5 '17 at 15:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Do an URL rewrite - so that requests to anywhere on http are redirected to the same address/port on https:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

Not the answer you're looking for? Browse other questions tagged or ask your own question.