0

Is there a way to redirect all website requests that come to my server from port 80 to port 443 without needing Apache to listen on port 80? Thus freeing port 80 for other use. I'm thinking like some sort of local proxy that detects if the incoming request is for a site and if so, just point it at the https site on port 443. If not, let it stroll on through to whatever else is running on port 80. Thanks.

3
  • Well, you can run a different httpd (nginx, etc) on that port that redirects to apache on port 443. However, that blocks the port again and gains you nothing. Jul 31, 2018 at 13:34
  • 1
    What "other use" are you looking to use port 80 for?
    – ceejayoz
    Jul 31, 2018 at 13:44
  • @ceejayoz a mix of OpenVPN and Stunnel. Jul 31, 2018 at 13:53

2 Answers 2

0

What you are looking for, seems to me, is a Protocol Multiplexer and what I could find useful to try with is sslh:

https://github.com/yrutschle/sslh

It's very easy to install and configure, and can detect certain applications by analyzing first data packet and can perform port forwarding.

Check the following link for an example:

https://www.eigenmagic.com/2017/08/21/how-to-share-one-port-number-https-ssh-and-openvpn/

I haven't tested it myself and also won't recommend something like this for an productive environment though.

-1

You need something on the port 80 which understand plain HTTP, otherwise the browser which connects there just will be refused or ignored (depends on your firewall).

You have to configure your Apache to listen on port 80 as well, and redirect all the request come to this port (eg: having different VirtualHosts on port 80 and port 443)

You can use the rewrite module for your HTTP request on port 80:

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://your.server.com%{REQUEST_URI} 

This redirects all the request to the same URL, but with https:// (and optionally to another server).E.g.:

http://your.server.com/foo/bar -> https://your.server.com/foo/bar

If you want save the port 80 for other usage you can fine tune the rewrite rule to rewrite only certain requests and serve the rest or rewrite the rest to another service. But obviously you have to decide what listens on the port 80, Apache or another service.

See more in the Apache mod_rewire documentation.

1

You must log in to answer this question.

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