Securing Nginx Webserver
1 minute read •
Nginx default Configuration File
It is located in /etc/nginx/nginx.conf.
Disble Server information leak
To do this we’re gonna vim into /etc/nginx/nginx.conf.
# And uncomment "server_tokens off"
Disble Server Signature and Click Jacking Attack
# Add the config before "Virtual Hosts Config".
;
;
The proxy_hide_header disables Server Signature and the add_header disables “iframing” of our website prevententing Click Jacking Attacks.
Protect webpages with password
We’re gonna do this with htpasswd which is a part of apache2-utils.
# Then inside the "Virtual Hosts Config" section of the "/etc/nginx/nginx.conf" file or the seperate virtual hosts config file.
# For the authentication, inside "server" section we need to have the following config.
;
;
# And inside "location" section
;
So, the final config of the Virtual Hosts Config should look something like this. This is bare minumum sample config btw.
Done!