How to convert the map and custom log configuration in the following Nginx HTTP configuration block to the corresponding configuration of Caddy and add it to my configuration?
thanks for the reply. I know that Caddy uses trusted_proxies configuration to achieve the map configuration of Nginx, but I still want to get your help: Caddy uses the map configuration to implement the map configuration of Nginx. The reasons are as follows:
The map configuration of the Nginx above is very convenient. There is no need to consider the IP range of the credible proxy server and the possible manual configuration.
Nginx also has the http_realip_module module similar to trusted_proxies, which does not affect the use of the map configuration to implement the http_realip_module function.
Compared tests, choose according to the test.
The following is an example of unsuccessful map configuration (there is no self -defined log):
Just totally forget about map, it doesn’t apply for what you’re trying to do. It’s not a transferable concept for this.
All you need to do like I said is configure trusted_proxies (see the docs I linked), then Caddy automatically parses X-Forwarded-For and makes it available in your access logs as client_ip.
Remember that you need to use the log directive inside your site for access logs to be enabled. The log global option does not enable access logs, it configures Caddy’s runtime logs.
Thanks for the reply again, but I am so disappointed! Finally, let me ask: Even if Caddy uses JSON to configure map, it cannot implement the map configuration of Nginx as above?
Caddy does have the map directive, but what I’m trying to say is there’s no reason for you to try to port that nginx config to Caddy because Caddy has a different mechanism (trusted_proxies) to do the same thing (i.e. parsing X-Forwarded-For), in a much better, properly-integrated way.