My First NGINX Source Contribution: Proposing a Configurable Server Header

My First NGINX Source Contribution: Proposing a Configurable Server Header

I’ve recently been exploring the NGINX source code and working on a proposed feature to control the default Server response header. Through this project, I’ve learned about NGINX internals, C programming, HTTP protocols, automated testing, and the open-source contribution process.

I’m sharing my experience and implementation for feedback from the NGINX community.

1. Understanding the problem

When a web server responds to an HTTP request, it can include a Server response header identifying the server software.

For example:

HTTP/1.1 200 OK
Server: nginx/1.31.8

NGINX provides the server_tokens directive to control how much version information is exposed. When configured as:

server_tokens off;

the version number is hidden, but the default header can still be present:

Server: nginx

Some deployments require an option to suppress the default-generated Server header entirely. This is the behavior I wanted to explore.

2. My proposed solution

I implemented a proposed directive named server_header:

http {
    server_header off;

    server {
        listen 8080;

        location / {
            return 200 "Hello from NGINX";
        }
    }
}

The proposed directive accepts on or off and is available in the http, server, and location configuration contexts.

The intended behavior is:

  • server_header on; enables generation of the default Server header.

  • server_header off; suppresses generation of that default header.

  • If the directive is omitted, it defaults to on to preserve existing behavior.

The implementation covers HTTP/1, HTTP/2, and HTTP/3.

One limitation is important: this change suppresses the default-generated header. It does not remove a Server header explicitly supplied by another module.

3. Exploring the NGINX source code

I started by cloning the official NGINX repository and examining how response headers are generated.

The implementation involved these source files:

  • src/http/ngx_http_core_module.c — registering the directive and handling configuration inheritance.

  • src/http/ngx_http_core_module.h — adding the configuration field.

  • src/http/ngx_http_header_filter_module.c — handling HTTP/1 response headers.

  • src/http/v2/ngx_http_v2_filter_module.c — handling HTTP/2 response headers.

  • src/http/v3/ngx_http_v3_filter_module.c — handling HTTP/3 response headers.

An important detail was ensuring that header-length calculations and actual header generation remained consistent with the new setting.

This helped me understand how a seemingly small configuration feature can involve several components of a mature web server.

4. Building and testing

I built NGINX from source with HTTP/2 and HTTP/3 support enabled.

I also created automated tests in the separate nginx-tests repository. The tests cover default behavior, configuration inheritance, server-level overrides, location-level overrides, and protocol-specific response-header behavior.

The targeted regression run covered seven test files, including the new tests and existing server_tokens tests.

Result: 63 checks passed locally.

These are targeted test results, not a run of the entire NGINX test suite. They also do not guarantee upstream acceptance.

5. Submitting the contribution

After implementing and testing the changes, I created forks of the official repositories, committed the changes on feature branches, and opened two pull requests:

The proposal relates to NGINX ticket #936, which discusses suppressing the Server response header.

At the time of writing, both pull requests are open and awaiting review. This directive is a proposal and is not part of the official NGINX release.

6. What I learned

This project helped me understand the open-source contribution process beyond cloning a repository and editing code.

I learned how to navigate a large C codebase, trace protocol-specific header handling, configure and build NGINX with optional modules, write automated tests, manage separate source and test repositories, and submit changes for upstream review.

It also reinforced an important lesson: passing local tests is only one part of contributing to a mature project. Design choices, documentation, compatibility, and maintainer feedback are equally important.

Feedback welcome

I’d appreciate feedback from the NGINX community on the proposed directive, its design, and whether this is an appropriate approach to controlling the default Server response header.

Thank you to everyone who maintains and contributes to NGINX Open Source. This has been a valuable learning experience, and I look forward to learning from the review process.

Hi there,

I see that the PRs have had the “standard” auto-responses, but no obvious-to-me human intervention yet.

Also – I am not associated with the development, and am not providing a review of the code; this is intended as “friendly comments from the peanut gallery”. So please read it in that light.

First off – congratulations on doing the work; and thanks for sharing your experience. It looks like you have learned quite a bit about the mechanics of contributing, whether or not the patch (or a variant of it) is eventually incorporated into the public project.

Next – for the specific change here, you link to the nginx ticket 936, which in turn refers to a set of later tickets which were closed as “associated” or “duplicate”. Summarising those, the basic idea then seems to have been that there was no security benefit to the deploying user in hiding or altering the “Server: nginx” indication, and there was a (minor?) advertising benefit to the nginx project in not having it altered when using their binaries. So, essentially, if the deploying user wanted to hide the fact that they were using nginx from the good guys, they could do the work to patch their version of the source, or they could support “the project” by buying a licence for the associated non-oss product. (The deploying user will not hide the fact that they are using nginx from the bad guys. Hence “no security benefit”.)

It may or may not be the case that the project/product opinion on that has changed since those tickets were last updated.

For the specific design here – I confess that I first thought that it was “overkill” to allow the setting per-location; but I see that “server_tokens” is allowed per-location, so I guess it makes sense, for consistency. A new directive also felt unnecessary, when the current server_tokens directive could (in principle) be modified to allow an extra value to mean “none at all”. “server_tokens”, according to the documentation at Module ngx_http_core_module, handles the content of the Server: header but also the content in generated error pages. I don’t think that your design touches the auto-generated error page content? The directive is called server_header, so it probably should not affect the error page content – but if the deploying user is trying to hide the fact that they are using nginx, having that word appear anywhere in the output is probably a concern.

My suspicion is that this patch will not be accepted as-is into the nginx project. If the project decides that they want to support the deploying user easily removing the nginx-indication, then probably they will include something very like the change that is apparently in the non-oss source code that allows the “server_tokens string” form, which has special handling for an empty string.

But, of course, you can always run your locally-patched version if you have a use case that needs it; and now that you have published the patch, anyone else can use-or-adapt it if they have a use case that matters to them, for their own deployments.

So that’s all positive too.

Cheers,