Unfortunately the only way to change the server header in nginx is to actually recompile it from source. Luckily this is quite easy.
First, download the latest version of nginx (0.7.61 at the time of writing) :
1 2 3 |
|
Changing the server string
The server header is in a file called ngx_http_header_filter_module.c :
1
|
|
Edit the following line (currently line 48 in version 0.7.61) :
1
|
|
… and change the nginx in ‘Server: nginx’ to whatever you want:
1
|
|
Next, edit src/core/nginx.h :
1
|
|
Edit the following line (currently line 13 in version 0.7.61) :
1
|
|
… and change the server string to whatever you want:
1
|
|
Changing the version number
You might also want to change the version number to confuse attackers, or just for fun :) Edit src/core/nginx.h :
1
|
|
Edit the following line (currently line 12 in version 0.7.61) :
1
|
|
… and change the version to whatever you want:
1
|
|
You can stop nginx from displaying the version entirely if you want, by including the server_tokens directive in your nginx.conf :
1
|
|
Compiling
You can set the prefix as appropriate - I keep it in /opt/ on Ubuntu.
1 2 3 |
|
After this, use .bashrc or similar to add /opt/nginx-0.7.61/sbin to your path, then you can start your new nginx install using :
1
|
|
To stop it, use ‘-s’ to send the stop signal :
1
|
|
Results
If you check the reponse headers, you should see your custom server string :
1 2 3 4 5 6 7 8 9 10 11 12 |
|