nginx / nginx/ngx-rust

Failures in config merge lead to silent nginx abort at startup

Open
#299 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
915
Forks
96
Avg merge
5d 22h
Merged PRs (30d)
6

Description

Describe the bug

If you write a module, which implements the impl Merge for ModuleConfig and returns return Err(MergeConfigError::NoValue);, nginx startup fails without any error message.

To Reproduce

Steps to reproduce the behavior:

  1. Build the project.
  2. Load awssig module into project
  3. Activate AWS signature mode in a location with awssigv4 on; only (no other locations)
  4. nginx fails to startup without any error message

Expected behavior

I expect to see at least an error message that the config merge failed.

I would suggest to enhance the interface so that self written modules, implementing the trait, are able to pass a string in the error to be able to describe the message actually.

Your environment

  • Version of fb8658099218f6d84b95da2bc79dec699288e358
  • Version of Rust: cargo 1.96.0 (30a34c682 2026-05-25)

Additional context

A possible fix. This introduced warnings in the build, but I guess you understand my wish much better:

Details

diff --git a/src/http/module.rs b/src/http/module.rs
index c19c61c..27fd8dd 100644
--- a/src/http/module.rs
+++ b/src/http/module.rs
@@ -6,6 +6,7 @@ use core::ptr;
 use crate::core::NGX_CONF_ERROR;
 use crate::core::*;
 use crate::ffi::*;
+use crate::ngx_conf_log_error;
 
 /// MergeConfigError - configuration cannot be merged with levels above.
 #[derive(Debug)]
@@ -118,7 +119,7 @@ pub trait HttpModule {
     /// Callers should provide valid non-null `ngx_conf_t` arguments. Implementers must
     /// guard against null inputs or risk runtime errors.
     unsafe extern "C" fn merge_srv_conf(
-        _cf: *mut ngx_conf_t,
+        cf: *mut ngx_conf_t,
         prev: *mut c_void,
         conf: *mut c_void,
     ) -> *mut c_char
@@ -131,7 +132,10 @@ pub trait HttpModule {
             let conf = &mut *(conf as *mut Self::ServerConf);
             match conf.merge(prev) {
                 Ok(_) => ptr::null_mut(),
-                Err(_) => NGX_CONF_ERROR as _,
+                Err(e) => {
+                    ngx_conf_log_error!(NGX_LOG_EMERG, cf, "failed to merge server configuration: {}", e);
+                    NGX_CONF_ERROR as _
+                }
             }
         }
     }
@@ -156,7 +160,7 @@ pub trait HttpModule {
     /// Callers should provide valid non-null `ngx_conf_t` arguments. Implementers must
     /// guard against null inputs or risk runtime errors.
     unsafe extern "C" fn merge_loc_conf(
-        _cf: *mut ngx_conf_t,
+        cf: *mut ngx_conf_t,
         prev: *mut c_void,
         conf: *mut c_void,
     ) -> *mut c_char
@@ -169,7 +173,10 @@ pub trait HttpModule {
             let conf = &mut *(conf as *mut Self::LocationConf);
             match conf.merge(prev) {
                 Ok(_) => ptr::null_mut(),
-                Err(_) => NGX_CONF_ERROR as _,
+                Err(e) => {
+                    ngx_conf_log_error!(NGX_LOG_EMERG, cf, "failed to merge location configuration: {}", e);
+                    NGX_CONF_ERROR as _
+                }
             }
         }
     }

There is still no error message passable via this interface, but this is my 2nd day really programming rust. I'm not yet aware what's the best solution to do the inheritance for this wish.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/http/module.rs, focusing on the MergeConfigError handling in merge_srv_conf and merge_loc_conf. Reproduce the awssigv4 configuration described in the issue, then verify that a failed merge produces an nginx startup error identifying the configuration failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
nginx, rust
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.