Howto use nginx config adapter

Hi,

I saw a project https://github.com/caddyserver/nginx-adapter and tried to build it.

So I installed go 1.13 and downloaded caddy source from https://github.com/caddyserver/caddy/releases/tag/v2.0.0-beta.13

And now, I want to follow instructions written nginx-adapter project.

  1. Entered caddy source directory
  2. Executed “go get github.com/caddyserver/nginx-adapter
  3. But how can I add below line
_ "github.com/caddyserver/nginx-adapter"

into “list of imports”? I don’t get it at all.
4. And how can I get a build result? (when I execute “go build”, it is done in a second without returning a message, and I don’t know the destination folder.)

Please help!

Hi there! Actually, the nginx-adapter is still work-in-progress. If you glance at the code in the repo, you’ll see it doesn’t handle rewrites yet, which I assume you’ll need based on your other thread. I’d say let’s focus on solving the issue you’re facing there.

1 Like

Ha, I got it.

But, the main reason I am asking for is based on my curiosity.

Is there’s a working solution?

The nginx adapter isn’t a command, so go build will only compile it to check for errors, not create an executable file. It’s a Caddy plugin, so you add that import as described here: https://caddyserver.com/docs/extending-caddy (near the beginning). Literally just add it to the list of imports. Making your own main is recommended.

Then compile your own main (or a modified Caddy main, if you added the import into Caddy’s main package instead of your own) and you will get a binary with that plugin.

So I figured out :slight_smile:

  1. in terminal, enter : git clone -b v2 “https://github.com/caddyserver/caddy.git
  2. enter to the directory, and : go get github.com/caddyserver/nginx-adapter
  3. add “_ “github.com/caddyserver/nginx-adapter”” line to “list of imports” which located as …/modules/standard/import.go
  4. then enter the directory …/cmd/caddy and execute “go build”
  5. then I get a working caddy executable with nginx config adapter module is plugged in

Finally I understood how it works. thanks.

2 Likes

Great! Glad you figured it out.

No need to do it in that file, in fact you can do it without modifying Caddy’s source code. Instructions here: https://github.com/caddyserver/caddy/tree/v2#building-with-plugins

But yeah, that process is the right idea.

1 Like