Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect 80 to 443 in case for dynamic IP #3278

Open
Somritag opened this issue Nov 15, 2024 · 3 comments
Open

Redirect 80 to 443 in case for dynamic IP #3278

Somritag opened this issue Nov 15, 2024 · 3 comments

Comments

@Somritag
Copy link

Hi Andy ,

I wanted to have a redirect from port 80 to 443 implemented for dynamic IPs of the server.
Initially tried with minimal example with two separate mounts for port 80 and port 443, with .origin as the redirect location.
But this happens while we set the context. Is there any better way to address this scenario.

I have upgraded to latest stable version on Livwebsocketv3.4stable as per your suggestion. We are using it on FreeRTOS.
Attaching the image of the current configuration.
image
THanks,
Som

@lws-team
Copy link
Member

I am not sure what you are asking, from what you have written.

@Somritag
Copy link
Author

Trying to rephrase my question, want to redirect any incoming http request to https. Server IP might not be the same always. As of now I was using static IP to test the redirection. Not Using the domain name in info.vhost_name.

In the case where IP might vary based on the network configuration, what will be the best way to handle the http->https redirection.

Thanks !

@lws-team
Copy link
Member

Isn't the problem that in your case, you are not sure in the code where to redirect to, in terms of https://xxx/yyy, you don't really know where to tell it to go for xxx? In this case the http server doesn't have a well-known location like a DNS name it can use.

You can try fish the information that got it to port 80 on the right box, out of another header that was sent by the browser as part of the :80 request, eg, HOST or AUTHORITY.

You can serve on port 80 the redirect using eg 302 and Location: <left side of whatever it said on Host:>:443. You'd need that vhost to use a custom protocol to dig out the host and serve Location.

Another alternative is just serve a JS redirect which uses the original window.location.href modified to use https:// and no port, ie, to do the redirection at the client side. You can do this with a mount since it just serves a snippet of canned JS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants