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

🤗 How can I DO reverseproxy http(other server) to https(gofiber)? #1762

Closed
koreaidi0t opened this issue Feb 10, 2022 · 15 comments · Fixed by #1765
Closed

🤗 How can I DO reverseproxy http(other server) to https(gofiber)? #1762

koreaidi0t opened this issue Feb 10, 2022 · 15 comments · Fixed by #1765
Assignees

Comments

@koreaidi0t
Copy link

koreaidi0t commented Feb 10, 2022

Question description
How can DO reverseproxy?

package main

import (
	"crypto/tls"
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/proxy"
)


func main() {
	cer, err := tls.LoadX509KeyPair("certs/fullchain.crt", "certs/privkey.pem")
	if err != nil {
		panic(err)
	}
	config := &tls.Config{Certificates: []tls.Certificate{cer}}

	app := fiber.New()
	g := app.Group("/test")
	{
		g.All("/*", func(c *fiber.Ctx) error {
			url := "http://192.168.10.144:80"+c.Path()
			err := proxy.Do(c, url)
			if err != nil{
				panic(err)
			}
			return nil
		})
	}
	ln, err := tls.Listen("tcp", ":443", config)
	if err != nil {
		panic(err)
	}
	app.Listener(ln)
}

When running this code, I got following error.
panic: tls: first record does not look like a TLS handshake

Thanks for reading.

@welcome
Copy link

welcome bot commented Feb 10, 2022

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@koreaidi0t koreaidi0t changed the title 🤗 How can I DO reverseproxy https(gofiber) to http(other server)? 🤗 How can I DO reverseproxy http(other server) to https(gofiber)? Feb 10, 2022
@ReneWerner87
Copy link
Member

@koreaidi0t
have you tested the server and the tls configuration without the proxy middleware ? do you get the same error ?

@koreaidi0t
Copy link
Author

koreaidi0t commented Feb 10, 2022

@ReneWerner87

Yes. When I make target server https, it works sucessfully as I expect.

Thanks for comment!

@koreaidi0t koreaidi0t reopened this Feb 10, 2022
@ReneWerner87
Copy link
Member

ok, you(@koreaidi0t ) opened it again ?
anything else I can help ?

@koreaidi0t
Copy link
Author

@ReneWerner87
My fingers slipped.😢

Yes there is still problem. I'd like to forward HTTP server via HTTPS gofiber server. I don't want the target server to use HTTPS.

Thanks for your effort!

@ReneWerner87
Copy link
Member

image
https://github.com/gofiber/fiber/tree/master/middleware/proxy

have you tried this from the readme ?

@koreaidi0t
Copy link
Author

@ReneWerner87

Yes. I tried, but it doesn't work.
In my case, the target server is http server, not using any certs, so that solution could not help. 😭

@bigflood
Copy link
Contributor

My guess is that the proxy middleware is doing https to the http target.

@bigflood
Copy link
Contributor

proxy.Do does not change the scheme from https to http.

req.SetRequestURI(addr)

@koreaidi0t
Copy link
Author

@bigflood
Thanks.
I found that if I change the scheme to 'http', it overwrited to 'https' due to isTls variable in req is set true.
What can I do?

@bigflood
Copy link
Contributor

It doesn't seem possible.

@bigflood
Copy link
Contributor

Maybe, you can implement your own version of proxy.Do.

@koreaidi0t
Copy link
Author

@bigflood
It seems hard to change isTls var in req though. 😢

BTW thanks for your comments!

@bigflood
Copy link
Contributor

@ReneWerner87
May I work on this issue?

@ReneWerner87
Copy link
Member

Sure

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

Successfully merging a pull request may close this issue.

3 participants