Using the ngx_http_addition_module in Nginx

nginx ngx_http_addition_module add_before_body
06 September 2025

What is the ngx_http_addition_module?


The ngx_http_addition_module in Nginx allows you to append HTML content during the processing of HTTP requests to the pages. This module works well for adding HTML code at specific locations in pages, especially when you need to display specific content before the body of the page is loaded.


By using this module, you can easily insert content into various sections of a web page. For example, you can place banners or advertisements before the main body's page load, which may help attract users or display specific information to them.


The method of using this module in the Nginx configuration file is relatively simple. You only need to add a directive to the Nginx configuration file itself and specify a path for the file you want to add as supplementary content. With this, you can easily add HTML content.


Before using this module, you must ensure that Nginx is compiled with this module. After that, you can proceed to add the necessary directives for including the content.


Nginx Code Example for Using the ngx_http_addition_module


location / {
add_before_body /path/to/your/file.html;
}

Line-by-Line Explanation of the Code


Line location / {

This line declares that the following configuration applies to all requests at the root site.


Line add_before_body /path/to/your/file.html;

This line specifies that the defined HTML file will be added before the main body of the page is rendered.


Line }

This line marks the end of the directives applicable to this location.


With this simple configuration, you can add your desired content before rendering each page. This capability can be used to show banner ads, notices, and many other cases. Just ensure to correctly specify the link to your HTML file.


FAQ

?

What is the ngx_http_addition_module and what is its use?

?

How can I use the ngx_http_addition_module?

?

Can I add more than one HTML file before the body is rendered?

?

Do I need to restart Nginx after making changes?

?

Is this module only for HTML pages?