I have a ubuntu 16.04 server. It runs nginx webserver for the frontend part. Also the backend application runs in the same server.

Now the requirement is to add header to incoming http requests. And we need to add header to the request coming from specific sources (IPs) only.

For Example:

users hit the following URL:


As soon as the server receives this request, we need to change it to:


How can we achieve this in ubuntu?As I searched I have found that HAproxy and nginx itself can be used to add header or is there any other better alternative.


Header means we need to add the first line to file.

sed -i 'li header content' filename.

header conent can be anything as per your requirement.

It would be helpful if you post sample input and output required

  • hello @Praveen Kumar BS I have edited the question by adding an example. hope this will explain the requirement. – Samin Munankarmi Feb 27 '18 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.