Nginx : Security configuration tips

Updated: 04/01/2021

System Security

To check the security of you web server, I advise you to download the package nikto (or nikto_console) :

nikto -h https://mywebserver.domainnet/ -ssl

1. Basic security

The best way to protect your web server is to leak the minimum data possible to the attacker : version number of Nginx, PHP, OS, etc..

# Display "Server" header
curl -ksv 2>&1 >/dev/null | grep Server

2. Strict Transport Security (HSTS)

This security makes it possible to declare to an HTTP client that your web server allows HTTPs.

3. Other protections

Data leak via Header ETag
Anti-clickjacking X-Frame-Options


The following parts are made to explain and provide answers about SSL / TLS security. The most well known and current attacks are summarized below where the emphasis has been on countermeasures. To test the SSL / TLS security of your web server, try online and free Qualys SSL Labs.

1. SSL and TLS encryption protocols

When we talk about “SSL”, it’s actually SSL / TLS. It must be known that SSL has been abandoned since 1999 and that its latest version, SSLv3, dates from 1996.
Since then, TLS has taken over the torch and released three versions: TLSv1.0, TLSv1.1 and TLSv1.2.

# Does your server support SSLv3 ?
echo -n | openssl s_client -connect -ssl3 >/dev/null 2>&1; echo $?
# TLS1.0, TLS1.1, etc.
echo -n | openssl s_client -connect -tls1 >/dev/null 2>&1; echo $?
echo -n | openssl s_client -connect -tls1_1 >/dev/null 2>&1; echo $?
echo -n | openssl s_client -connect -tls1_2 >/dev/null 2>&1; echo $?
echo -n | openssl s_client -connect -tls1_3 >/dev/null 2>&1; echo $?

2. Cipher Suite

The encryption algorithms break down into 4 types:
- Key exchange
- Authentication
- Block encryption
- Message Authentication

3. HTTP Request Smuggling Vulnerability

During the summer of 2019, an old vulnerability appeared again on almost all web servers. I am assuming you are using Nginx, if you are using a version lower than 1.18.0 you are vulnerable.

# Display nginx version under Debian/Ubuntu
dpkg -l | grep nginx

4. BEAST attack and RC4

This attack exists ONLY IF TLSv1.0 is active.

# Does your server support TLSv1.1 and not RC4 ?
echo -n | openssl s_client -connect -cipher DHE-RSA-CAMELLIA128-SHA -tls1_1 >/dev/null 2>&1; echo $?
# Does your server support TLSv1.0 ?
echo -n | openssl s_client -connect -tls1 >/dev/null 2>&1; echo $?

5. FREAK attack (Factoring RSA-EXPORT Keys)

To be protected against this attack, you must disable encryption keys in the Export library.
Same SSLCipherSuite configuration as before, checking that it contains !EXP.

# Does your server support EXP ?
echo -n | openssl s_client -connect -cipher EXP-EDH-RSA-DES-CBC-SHA >/dev/null 2>&1; echo $?

6. Logjam attack

This attack makes it possible to lower the cryptography level of the TLS exchange. To be protected against this, it is better to only allow the TLSv1.0, TLSv1.1 and TLSv1.2 protocols.

# Generate 4096-bits DH group
openssl dhparam -out /etc/ssl/certs/dhparam.pem 4096
# Check DH group
openssl dh -in /etc/ssl/certs/dhparam.pem -text

7. Heartbleed

You are subject to this flaw if your version of openssl is too old. In this case, if the server uses a version 1.0.1 with any patch before “g”.

# Display openssl version under Debian/Ubuntu
dpkg -l openssl



[1] Nginx ETag Inode Information Leakage :
[2] Clickjacking :
[3] Qualys SSL Labs — SSL Server Test :
[4] Wikipedia — POODLE :
[5] Wikipedia — Cipher suite :
[6] Wikipedia — BEAST Attack :
[7] Chrome Stable Release :
[8] Bug 665814 — (CVE-2011–3389) Rizzo/Duong chosen plaintext attack (BEAST) on SSL/TLS 1.0 :
[9] Bulletin de securite Microsoft MS12–006 :
[10] Killing RC4: The Long Goodbye :
[11] Wikipedia — FREAK :
[12] Wikipedia — Logjam :
[13] Wikipedia — HeartBleed :
[14] Wikipedia — CRIME :

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store