What You Will Do if You Use Nginx From Repository? Here is How To Change Nginx Server Header After Installation Which Reads Server: nginx. Yes, it is TRUE that we said before that changing server name in header response only possible while building from source. But actually there is a limited usage way to change nginx server header after installation.
Change Nginx Server Header After Installation : What The Hell The Limitation Is?
nginx is five worded thing, you have to use five words. If you do not limit your unique name within the 5 words, you will get Segmentation fault (core dumped). Thats a small limitation. Unfortunately the word server is not 5 worded.
Change Nginx Server Header After Installation : How it is possible?
Like awk, sed is very powerful tool. The command is simple, not very difficult :
---
1 | sed -i 's/nginx\r/CHaNG\r/' `which nginx` |
nginx to CHaNG. If I want to change from CHaNG to nginx, then it will be :
1 | sed -i 's/CHaNG\r/nginx\r/' `which nginx` |
Warning : BE CAREFUL ABOUT COPY-PASTING – the ‘ sign can change before s/ in the command and throw error! Copy-Paste in textedit or vim and check the punctuations first, then copy to ssh screen!
First after running, run :
1 | nginx -t |
then restart nginx :
1 | service nginx restart |
Like at this moment, after running curl -I
our web server appears to be Cloud :
Actually it is a bad idea to use a custom name. Because the hackers might get inspired to find out what kind of server it is! CloudFlare uses this kind of name – nginx-cloudflare
. But if you run :
1 | sed -i 's/nginx\r/nginx-cloudflare\r/' `which nginx` |
After running nginx -t
you’ll get Segmentation fault (core dumped). It is quite scary looking. You need to the opposite command to make the dog’s tail straight :
1 | sed -i 's/nginx-cloudflare\r/nginx\r/' `which nginx` |
Again read the read the previous guide on changing server name in header response and uncomment that server_tokens off
. The version number has character – like 1.7.1; you can use more 4 character to make it better. Actually we can not switch the Server:
part off, that is the problem.