rejetto forum

Software => HFS ~ HTTP File Server => router & port problems => Topic started by: eyespeak on June 02, 2017, 07:52:55 PM

Title: Redirect from 80 (HTTP) to 443 (HTTPS)?
Post by: eyespeak on June 02, 2017, 07:52:55 PM
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.
Title: Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
Post by: bmartino1 on June 03, 2017, 02:24:56 PM
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/" />
Title: Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
Post by: LeoNeeson on June 04, 2017, 05:00:53 AM
@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. ;)
Title: Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
Post by: eyespeak on June 04, 2017, 08:42:04 AM
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 :)
Title: Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
Post by: eyespeak on June 04, 2017, 08:53:33 AM
@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
Title: Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
Post by: LeoNeeson on June 04, 2017, 11:06:53 AM
I'm not familiar with SelfHost.de (http://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 (https://stackoverflow.com/a/4954784)).
Title: Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
Post by: eyespeak on June 04, 2017, 11:19:17 AM
I'm not familiar with SelfHost.de (http://selfhost.de/) but you can try this code:Insert the code marked in red in the <head> section (source (https://stackoverflow.com/a/4954784)).
Fine, the snippet works!
Is there any other option without JavaScript?
Title: Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
Post by: LeoNeeson on June 05, 2017, 06:35:48 AM
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 (http://www.rejetto.com/forum/router-port-problems/redirection-httpaaaaa-aaa-en-httpsaaaaa-aaa/msg1017656/#msg1017656) and also here (http://www.rejetto.com/forum/hfs-~-http-file-server/problem-with-downloading-and-accessing-server/msg1035500/#msg1035500).
Title: Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
Post by: Mars on June 05, 2017, 02:33:20 PM
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
Title: Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
Post by: bmartino1 on June 05, 2017, 10:12:38 PM
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