cloudfoundry / nginx-buildpack

Cloud Foundry buildpack that provides NGINX
Apache License 2.0
30 stars 66 forks source link

Using ngx_http_realip_module seems not to work out-of-the-box #21

Closed robachmann closed 4 years ago

robachmann commented 4 years ago

What version of Cloud Foundry and CF CLI are you using? (i.e. What is the output of running cf curl /v2/info && cf version? 2.141.0 6.47.2+d526c2cb3.2019-11-05

What version of the buildpack you are using? 1.1.1

If you were attempting to accomplish a task, what was it you were attempting to do? Filter IP addresses based on XFF header. Therefore, using the ngx_http_realip_module module.

What did you expect to happen? The docs state I should be able to simply insert the module name for built-in modules without including the necessary .so files: https://docs.cloudfoundry.org/buildpacks/nginx/index.html#loading-modules Reading the NginxRecipe, I see it is built with --with-http_realip_module.

I cloned this repo, used the fixtures/mainline example and just added this first line to the nginx.conf:

{{module "ngx_http_realip_module"}}

Unfortunately, the necessary file isn't found upon pushing the app.

What was the actual behavior?

$ cf push my-app
Pushing app my-app to org <org> / space <space> as <user>...
Getting app info...
Updating app with these attributes...
  name:                my-app
  path:                /home/<user>/nginx-buildpack/fixtures/mainline
  buildpacks:
    https://github.com/cloudfoundry/nginx-buildpack.git
  disk quota:          1G
  health check type:   port
  instances:           1
  memory:              1G
  stack:               cflinuxfs3
  routes:
     <omitted>

Updating app my-app...
Mapping routes...
Comparing local files to remote cache...
Packaging files to upload...
Uploading files...
 1.93 KiB / 1.93 KiB [==================================================================================] 100.00% 1s

Waiting for API to complete processing files...

Staging app and tracing logs...
   Cell 2d48f679-2212-4203-bb7b-61989d4a1853 creating container for instance dcbcfb87-be2e-45d2-a9d1-e397ab4161a5
   Cell 2d48f679-2212-4203-bb7b-61989d4a1853 successfully created container for instance dcbcfb87-be2e-45d2-a9d1-e397ab4161a5
   Downloading app package...
   Downloading build artifacts cache...
   Downloaded app package (1.7K)
   Downloaded build artifacts cache (2.3M)
   -----> Download go 1.12.4
   -----> Running go build supply
   /tmp/buildpackdownloads/adf6125a52c1a65c9523985b5a87ec38 ~
   -----> Nginx Buildpack version 1.1.1
   -----> Supplying nginx
   -----> Requested nginx version: mainline => 1.17.5
   -----> Installing nginx 1.17.5
          Copy [/tmp/cache/final/dependencies/a0ecd9f6b3ef6c7696ea543219c8f52882755c93e7c4e6c58d2283887c4eecc8/nginx-1.17.5-linux-x64-cflinuxfs3-fa554ae5.tgz]
   2019/11/18 06:42:19 [emerg] 431#0: dlopen() "/tmp/contents040357720/deps/0/nginx/nginx/modules/ngx_http_realip_module.so" failed (/tmp/contents040357720/deps/0/nginx/nginx/modules/ngx_http_realip_module.so: cannot open shared object file: No such file or directory) in /tmp/conf656370157/nginx.conf:1
   nginx: configuration file /tmp/conf656370157/nginx.conf test failed
          **ERROR** Could not validate nginx.conf: nginx.conf contains syntax errors: exit status 1
   Failed to compile droplet: Failed to run all supply scripts: exit status 14
   Exit status 223
   Cell 2d48f679-2212-4203-bb7b-61989d4a1853 stopping instance dcbcfb87-be2e-45d2-a9d1-e397ab4161a5
   Cell 2d48f679-2212-4203-bb7b-61989d4a1853 destroying container for instance dcbcfb87-be2e-45d2-a9d1-e397ab4161a5
   Cell 2d48f679-2212-4203-bb7b-61989d4a1853 successfully destroyed container for instance dcbcfb87-be2e-45d2-a9d1-e397ab4161a5
Error staging application: App staging failed in the buildpack compile phase
FAILED

Please confirm where necessary:

If I'm doing something wrong, please point me into the right direction. Thank you very much!

cf-gitbot commented 4 years ago

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/169805233

The labels on this github issue will be updated when the story is started.

ryanmoran commented 4 years ago

There is definitely some confusion in the wording used in the documentation. There are 2 kinds of "built-in" modules in this buildpack: 1) modules compiled into the nginx binary and always available (like ngx_http_realip_module), and 2) modules compiled as libraries and included in the buildpack that can be dynamically loaded at runtime (like ngx_stream_module).

We will add some clarification to the docs to outline this difference. As for a fix here, you shouldn't need to load the ngx_http_realip_module at all, just use it in your existing nginx.conf.

Cheers!

ryanmoran commented 4 years ago

Those updated docs are in https://github.com/cloudfoundry/docs-buildpacks/pull/255.

With that update, I will consider this issue closed unless there is a further problem.

robachmann commented 4 years ago

Thank you so much for clearing things up, @ryanmoran :-)