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 defaultServerheader. -
server_header off;suppresses generation of that default header. -
If the directive is omitted, it defaults to
onto 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:
-
Source implementation: HTTP: add server_header directive by TibinAbraham · Pull Request #1850 · nginx/nginx · GitHub
-
Automated tests: Tests: add coverage for server_header directive by TibinAbraham · Pull Request #143 · nginx/nginx-tests · GitHub
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.