I don't want anyone to be able to detect that I'm using NGINX or even Ubuntu from the internet. There are tools out there (such as BuiltWith) which scan servers to detect what tools they're using. Also, some cracking tools might help with deteting. What's the best / closest to that I can get to hiding all this info from the outside?
You can stop it outputting the version of Nginx and OS by adding
to a
http
,server
, orlocation
context.Or if you want to remove the Server header completely, you need to compile Nginx with the Headers More module in, as the header is hard coded in the Nginx source, and this module allows changing any http headers.
However, there are many hidden ways servers perform by accident via their implementation which may help identify the system. e.g. How it responds to a bad SSL request. I don't see a practical way of preventing this.
Some of the things I might suggest:
If you have installed nginx using apt-get in Debian or Ubuntu, you might need to install the package nginx-extras to set or clear "Server" header
Once this is done, you can add the lines below in nginx.conf (usually /etc/nginx/nginx.conf):
To clear the "Server" header altogether:
To Set a custom string as "Server"
@Martin F. Yes it does. You will have to compile it from source and change what's needed before compiling the source.
I assume you downloaded the last stable version you decompressed it and you know where the files are. If that's the case, do the following:
Then look for line 48 if I recall correctly.
Replace nginx with MyWhateverServerNameIWant e.g.
Then
look for the line
change "nginx/" to "MyWhateverServerNameIWant/" so it will read
Finally if you want also change the version number
look for the line #define NGINX_VERSION "1.0.4"
and change "1.0.4" for whatever version you want. For example it will read
Hope it helps. Nevertheless. Securing a server goes far beyond not showing what's running. PHP is by nature insecure, and so is linux. Off course linux can be pretty secure if all needed measures are taken in order to achieve a decent security. As far as PHP is concerned I would recommend using Suoshin to help harden the security of your code.
1) Install
nginx-extras
package alongsidenginx
:2) Open
nginx.conf
and add following lines insidehttp
block:3) Restart
nginx
After a lot of time working out how to do a custom flavor of nginx on ubuntu I realized you can use the lua module for this.
On ubuntu 14.04 if you install the
nginx-extras
package you can remove the server header by using:header_filter_by_lua 'ngx.header["server"] = nil';
Throw this in the http block and every request will be lacking a
Server
header.If it doesn't work run
nginx -V
to verify that you have the lua module compiled into your copy of nginx. If not, there is likely an alternate package you can use to get it.Instead of the header_filter_by_lua it is recommended to use the new directive header_filter_by_lua_block which inlines the Lua source directly between curly braces (
{}
). With this it is not needed to escape special characters.header_filter_by_lua_block { ngx.header["server"] = nil }
https://github.com/openresty/lua-nginx-module#header_filter_by_lua_block
Just want to point out that even though the server header is removed from response, the name of the server (nginx or openresty e.g.) is still clearly visible in the html error response that the server sends in case of an error.
Anyone can very easily get this response by e.g. sending a header that is too long. Nginx will return a 400 Bad Request, that does not contain a server header (if fixed), but the html itself will show it:
P.S. I don't know how to get rid of this one as well, really the html itself will give it away, so there should be a way perhaps to not generate these at all?
First and foremost: Why using an extra module as Headers More Nginx? Only to hide the server header. If a few lines, simple patch can reach the same solution for you.
As using an extra module could result in instability (how well has it been tested with your environment? With your other modules etc.) or insecurity (is this module regularly updated with bug and/or security related fixes?)
Secondly. This thread describes as reply 279389 how you can adjust the Nginx code to change the server header. Problem is that they have forgotten HTTP/2. In short, nothing will change. The server header will still be visible.
Less is more is better. Ok I admit, I have also been looking for a good solution for a long time. But finally found:
Nginx server header removal patch
I am finally redeemed from that annoying Nginx server header.
Run this bash function in nginx source code folder. In nginx-$version, not in src/.
Based on this answer.
Use below methods in source; to eliminate nginx string from error messages
then re-compile