more_set_headers is a powerful NGINX module that allows you to easily set response headers and override existing header values. It is also known as headers-more module. It works even if you are using NGINX as reverse proxy. In this article, we will look at how to install more_set_headers in NGINX.
How to Install more_set_headers in NGINX
Here are the steps to install more_set_headers in NGINX. We will look at two ways to install more_set_headers.
1. Install nginx-extras
Open terminal and run the following command to install more_set_headers as a part of nginx-extras module.
$ sudo apt install nginx-extras
If you get any dependency error, then you need to update your NGINX version. Here are the commands to re-install NGINX version.
Uninstall and remove NGINX
sudo apt remove nginx sudo apt autoremove sudo apt purge nginx
Update system and install NGINX
sudo apt update sudo apt upgrade sudo apt install nginx
Upgrade nginx to the latest stable
sudo apt install software-properties-common nginx=stable sudo add-apt-repository ppa:nginx/$nginx sudo apt update sudo apt dist-upgrade
Install nginx-extras
sudo apt install nginx-extras
2. Compile more_set_headers with NGINX
You can also install more_set_headers with NGINX during installation as shown below.
Download and unzip NGINX source code. Replace 1-17.8 with your choice of NGINX version.
sudo wget 'http://nginx.org/download/nginx-1.17.8.tar.gz' tar -xzvf nginx-1.17.8.tar.gz cd nginx-1.17.8/
Configure & install NGINX server.
./configure --prefix=/opt/nginx --add-module=/path/to/headers-more-nginx-module make make install
Open NGINX server configuration file in a text editor.
$ sudo vi /etc/nginx/nginx.conf
No matter which of the above methods you use to install NGINX, add the following line as your first line.
load_module /path/to/modules/ngx_http_headers_more_filter_module.so;
Test NGINX configuration
$ sudo nginx -t
Restart NGINX server to apply changes
$ sudo service nginx restart
Also read:
How to Modify Response Headers in NGINX
How to Get Data from URL in NodeJS
NGINX Location Blocks Precedence
How to Fix Errno 13 Permission Denied in Apache
How to Define & Use Variables in Apache