英文:
get springboot to route to your subdomain as opposed to localhost
问题
假设我有一个域名 "example.com"。目前,我使用 Caddy 将 example.com 配置为代理,代理到运行在本地 8080 端口的 Spring Boot 应用程序。如何正确访问应用程序内的其他路由呢?例如,如果我访问 https://example.com/user,URL 将会是:example.com/user。但是,如果我从 Spring Boot 应用程序内部从 /user 路由到 /login(假设在控制器的用户路由末尾使用 return new RedirectView("/login")),它会将我重定向到 http:serverIpAddress:8080/login,我该如何使其路由到 https://example.com/login?
英文:
Let's say I have a domain "example.com". Right now, using caddy, I have configured example.com to be a proxy for a springboot application running on localhost 8080. How do you properly go to other routes within the application? For example, if I go to https://example.com/user, the url will be: example.com/user. but if I route from within the springboot app from there to /login (lets say using return new RedirectView("/login") at the end of the user route in the controller), it will redirect me instead to http:serverIpAdress:8080/login. How could I get this to route to https://example.com/login?
答案1
得分: 0
这并不是 Spring 的问题;需要正确配置 Caddy 如下:
subdomain {
proxy / ipAddress:port {
transparent
}
}
- 在 Caddyfile 中要注意空格。我最初尝试过这样,但不起作用,我认为原因是因为我创建文件的方式是这样的:subdomain {
proxy / ipAddress:port { transparent }} - 有点混淆,它确实起作用了,因为从许多地方我在互联网上看到的信息中,它们从 API 中删除了 transparent。
英文:
It is not an issue with Spring; Caddy needs to be configured properly as follows:
subdomain {
proxy / ipAddress:port {
transparent
}
}
- be careful with the spacing in the caddyfile. I had originally tried this and it did not work, and I believe the reason is because i created the file like this:subdomain {
proxy / ipAddress:port { transparent }} - little bit of confusion that it did work, as from many places I have seen on the internet it appeared they removed transparent from the api
专注分享java语言的经验与见解,让所有开发者获益!
评论