Fetching Correct IP Address And Host
Description
- This doc demonstrates how to get correct IP address and host when soul serves behind nginx reverse proxy.
- After fetched real IP and host, you can match them with plugins and selectors.
Default Implementation
-
The embedded implementation in soul is :
org.dromara.soul.web.forwarde.ForwardedRemoteAddressResolver。 -
You need to config
X-Forwarded-Forinnginxfirst to get correct IP address and host.
Implement through a Plugin
- Declare a new class named "A" and implements
org.dromara.soul.plugin.api.RemoteAddressResolver.
public interface RemoteAddressResolver {
/**
* Resolve inet socket address.
*
* @param exchange the exchange
* @return the inet socket address
*/
default InetSocketAddress resolve(ServerWebExchange exchange) {
return exchange.getRequest().getRemoteAddress();
}
}
- Register defined class as a Spring Bean.
@Bean
public SignService a() {
return new A
}