This works on a Digital Ocean’s server managed by Laravel Forge. What this does:
- install the ngx_headers_more module
- edit Nginx configuration to have a custom value for the
server
header.
- Power off the server by connecting through
ssh
and runningsudo poweroff
. - Take a snapshot of the server in the Digital Ocean panel. If things goes wrong, it’ll help server restauration.
- Warning step:
- Starting step 4, instructions are largely inspired from a Stack Overflow / Server Fault answer.
- When prompt for choices like “replacing this config file” or “use this grub file”, don’t: always keep what’s currently working. You can review differences (the prompt tell you how), but the chance to not screw something are greater by keeping current things as is.
- Turn the server on again from the Digital Ocean panel.
sudo apt remove nginx
sudo apt autoremove
sudo apt purge nginx
sudo apt update
sudo apt upgrade
sudo apt install nginx
- Check Nginx is installed:
nginx -v
sudo apt install nginx-extras
- The module is now automatically loaded because the server is setup (by Forge or by default) that way:
/etc/nginx/nginx.conf
loads the whole/etc/nginx/modules-enabled
directory, where thenginx-extras
module has been installed. - Now we are going to edit the Nginx configuration of our website, from Forge (your site / bottom of the page / Files / Edit Nginx Configuration).
- In
server { …HERE… }
, add:
server_tokens off; # remove Nginx version
more_set_headers "Server: MyServerName"; # requires nginx-extras, see https://serverfault.com/questions/954708/install-more-set-headers-in-nginx-1-15-8/954724
Example:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
# various other stuff here…
# your custom Server name here.
server_tokens off; # remove Nginx version, probably useless along with next line.
more_set_headers "Server: Thanks meduzen for the tip!";
# other regular others
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
# still other stuff here…
}
- Save the configuration. Forge automatically reboots Nginx.