banner
libxcnya.so

libxcnya.so

Nothing...
telegram
twitter
github
email

Using the Nginx module headers_more

Introduction#

The headers_more module is a very useful nginx extension that makes it easier for us to handle HTTP requests and response headers. With headers_more, we can easily add, modify, and delete request and response headers, which brings about a tremendous change to our website!

In our daily work, we often encounter situations where we need to dynamically set HTTP headers. Sometimes, we want to hide the server's version information, and other times we need to add some special headers for security purposes. headers_more is like a magic box that provides us with a series of directives to manipulate these headers in the nginx configuration.

Moreover, using the headers_more module can make our configuration files more clear and concise. We no longer need to write a bunch of complex if statements and rewrite rules to perform header operations. We simply need to call the directives provided by headers_more, and everything will be taken care of!

In summary, the headers_more module is a brilliant gem among nginx extensions, making our work more efficient and flexible. It's like a key that unlocks the infinite possibilities of HTTP headers and makes our website more powerful!

The above nonsense is generated by ChatGPT

Installation#

Go to the Baota panel's App Store and find Nginx, click Install, and select Compile and Install.

![1][1]

Then click Add Custom Module.

![2][2]

You can enter anything for the first two fields, but they must be in English and include underscores.
For the Module Parameters, enter:

--add-module=/www/server/ngx_modules/headers_more

For the Pre-Installation Script, enter:

mkdir /www/server/ngx_modules
cd /www/server/ngx_modules
wget https://github.com/openresty/headers-more-nginx-module/archive/refs/tags/v0.34.zip
unzip v0.34.zip
rm -rf v0.34.zip
mv headers-more-nginx-module-0.34 headers_more

Then click OK.

![3][3]

Check the custom module you just added and click Install.
Then wait for a long time.

Note: If your server's wget has the same SSL issue as mine, you may encounter the following situation:

4

Don't worry, open /etc/wgetrc with your favorite editor.
Then insert this line wherever you like:

check-certificate = off

Like this:

5

Save and exit, then come back and click Compile and Install again, and check your custom module.
If everything goes well, it will be installed successfully.

Configuration#

Effective for a single site#

Just open the settings of the site, find the pseudo-static section, and paste the following:

more_set_headers "Server: MiaoServer/114.514";

Of course, you can change it to something else. This is just an example.
Then save to complete the setup.

Effective globally#

Open the Nginx settings and find the configuration modification.

6

Paste the following below this position:

more_set_headers "Server: MiaoServer/114.514";

Then save.

Other commands#

Of course, there are more ways to use this. You can explore them yourself.

more_set_headers // Used to add, modify, and clear response headers.
more_clear_headers // Used to clear response headers.
more_set_input_headers // Used to add, modify, and clear request headers.
more_clear_input_headers // Used to clear request headers.

Effect#

Before modification:

root@M1ao:~# curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 31 Jul 2023 18:20:01 GMT
Content-Type: text/html
Content-Length: 138
Last-Modified: Sat, 22 Jul 2023 05:33:01 GMT
Connection: keep-alive
ETag: "64bb6a0d-8a"
Accept-Ranges: bytes

root@M1ao:~#

After modification:

root@M1ao:~# curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: MiaoServer/114.514
Date: Mon, 31 Jul 2023 18:21:12 GMT
Content-Type: text/html
Content-Length: 138
Last-Modified: Sat, 22 Jul 2023 05:33:01 GMT
Connection: keep-alive
ETag: "64bb6a0d-8a"
Accept-Ranges: bytes

root@M1ao:~#

This article is synchronized and updated to xLog by Mix Space.
The original link is https://blog.nekorua.com/posts/maintain/20.html


Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.