The nginxconf.Adapter implements the caddyconfig.Adapter interface, allowing Caddy to ingest NGINX configuration files directly. It converts NGINX directives into Caddy's JSON configuration format.
To use the adapter, call the Adapt method. You can optionally provide a filename in the options map to ensure that any warnings generated include the correct file path for debugging.
import (
"github.com/caddyserver/caddyserver/nginx-adapter/nginxconf"
)
// ...
adapter := nginxconf.Adapter{}
// body is the []byte content of the nginx.conf
// options can include "filename" to provide context for warnings
options := map[string]interface{}{
"filename": "/etc/nginx/nginx.conf",
}
caddyJSON, warnings, err := adapter.Adapt(body, options)
if err != nil {
// handle error
}
// caddyJSON is now ready to be used as Caddy configuration