rejetto forum

Redirect from 80 (HTTP) to 443 (HTTPS)?

eyespeak · 10 · 20988

0 Members and 1 Guest are viewing this topic.

Offline eyespeak

  • Occasional poster
  • *
    • Posts: 4
    • View Profile
Hi,

i have generated with Stunnel and Let´s Encrypt my own certificate without a SSL warning. Nice :-)

Now: how i can redirect alway all requests from port 80 to port 443?

Thanks a lot.


Offline bmartino1

  • Tireless poster
  • ****
    • Posts: 911
  • I'm only trying to help i mean no offense.
    • View Profile
    • My HFS Google Drive Shared Link
iptables /nat traffice to via port forwarding starting port 80 to ending pot 443.

or

have a port 80 webpage that redirects you to the https site.

https://stackoverflow.com/questions/5411538/redirect-from-an-html-page

html code:

Code: [Select]
<meta http-equiv="refresh" content="0; url=http://example.com/" />
Files I have snagged and share can be found on my google drive:

https://drive.google.com/drive/folders/1qb4INX2pzsjmMT06YEIQk9Nv5jMu33tC?usp=sharing


Offline LeoNeeson

  • Tireless poster
  • ****
    • Posts: 859
  • Status: On hiatus       (sporadically here)
    • View Profile
    • twitter.com/LeoNeeson
@eyespeak: I guess you own a domain, right?...
...or you are only using a DynDNS service (like No-IP)?

If you are using a domain, please say us what registrar are you using.
If you can give us more details, it would be more easy to help you. ;)
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
» Currently taking a break, until HFS v2.4 get his stable version.


Offline eyespeak

  • Occasional poster
  • *
    • Posts: 4
    • View Profile
Code: [Select]
<meta http-equiv="refresh" content="0; url=http://example.com/" />
Ok, it works but i have now a endless loop between http<>https. Not so good :)


Offline eyespeak

  • Occasional poster
  • *
    • Posts: 4
    • View Profile
@eyespeak: I guess you own a domain, right?...
...or you are only using a DynDNS service (like No-IP)?
Yes, own domain with subdomain. I connect with sub.domain.de

Quote
If you are using a domain, please say us what registrar are you using.
My router has an account from selfhost.de, and my provider a CNAME entry on this subdomain. It works fine.

But how can I now only connect to https? The only way so far ... Only NAT 443 to internal:
NOT Working http://sub.mydomain.de
Working https://sub.mydomain.de

But I want to redirect from http to https directly:
http to https
https stay https
« Last Edit: June 04, 2017, 09:06:54 AM by eyespeak »


Offline LeoNeeson

  • Tireless poster
  • ****
    • Posts: 859
  • Status: On hiatus       (sporadically here)
    • View Profile
    • twitter.com/LeoNeeson
I'm not familiar with SelfHost.de but you can try this code:
Quote
<html>

<head>
   <script language="JavaScript">
      if (window.location.href.indexOf('http://')==0)
        window.location=window.location.href.replace('http://','https://');
   </script>

</head>

<body>



</body>

</html>
Insert the code marked in red in the <head> section (source).
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
» Currently taking a break, until HFS v2.4 get his stable version.


Offline eyespeak

  • Occasional poster
  • *
    • Posts: 4
    • View Profile
I'm not familiar with SelfHost.de but you can try this code:Insert the code marked in red in the <head> section (source).
Fine, the snippet works!
Is there any other option without JavaScript?


Offline LeoNeeson

  • Tireless poster
  • ****
    • Posts: 859
  • Status: On hiatus       (sporadically here)
    • View Profile
    • twitter.com/LeoNeeson
Is there any other option without JavaScript?
Probably using Macros, but I don't know if can be done. You can find another solution, here and also here.
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
» Currently taking a break, until HFS v2.4 get his stable version.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2063
    • View Profile
Stunnel accepts only the ssl (HTTPS) request, if you want a http request to be redirected to https, a server listening on port 80 must redirect the url to the stunnel 443 port. You can run hfs listening only on address:port as 127.0.0.1:8443 with in stunnel a config like

[https]
accept = 0.0.0.0:443
connect = 127.0.0.1:8443
.....

you can use a second hfs stored in another folder ( not the same of the default server) to redirect request.
 this hfs must have his options saved to disk and hear port 80, no file in vfs and root template can be defined in diff template as
Quote
[=not found]
<!DOCTYPE HTML>
<html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="refresh" content="5; url=https://sub.mydomain.de{.get|url.}">
        <title>Page Redirection</title>
    </head>
    <body>
        You will be redirected automatically to<p>
https://sub.mydomain.de{.get|url.} in 5 second
    </body>
</html>

all request http on port 80 are redirected to stunnel on port 443
« Last Edit: June 05, 2017, 02:35:35 PM by Mars »


Offline bmartino1

  • Tireless poster
  • ****
    • Posts: 911
  • I'm only trying to help i mean no offense.
    • View Profile
    • My HFS Google Drive Shared Link
The 0 should be a 1. In meta refresh rate the info loop is due to the page not fully loading.

As Mars has posted it's 5 seconds​ before refresh
Files I have snagged and share can be found on my google drive:

https://drive.google.com/drive/folders/1qb4INX2pzsjmMT06YEIQk9Nv5jMu33tC?usp=sharing