Detailed explanation of the best configuration for Nginx to improve security and performance

Detailed explanation of the best configuration for Nginx to improve security and performance

It mainly shows how to configure X-Frame-Options, X-XSS-Protection, X-Content-Type-Options, Strict-Transport-Security, https and other security configurations in Nginx.

Nginx.conf is configured as follows

# Do not display the Nginx version number on error pages or in the server header server_tokens off;

#Do not allow pages to be displayed from frames or iframes, which can avoid clickjacking
# http://en.wikipedia.org/wiki/Clickjacking
# If you allow [i]frames, you can use SAMEORIGIN or set your allowed urls in ALLOW-FROM
# https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options
add_header X-Frame-Options SAMEORIGIN;

#When your website is user-provided content such as a blog forum, use the X-Content-Type-Options: nosniff header,
# This is to disable content type sniffing in some browsers # https://www.owasp.org/index.php/List_of_useful_HTTP_headers
# Currently supports IE > 8 and above http://blogs.msdn.com/b/ie/archive/2008/09/02/ie8-security-part-vi-beta-2-update.aspx
# http://msdn.microsoft.com/en-us/library/ie/gg622941(v=vs.85).aspx
#Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=471020
add_header X-Content-Type-Options nosniff;

# Prevent cross-site scripting (XSS), which is currently supported by most browsers. # It is activated by default. If it is disabled by the user, you can use this configuration to activate it.
# https://www.owasp.org/index.php/List_of_useful_HTTP_headers
add_header X-XSS-Protection "1; mode=block";

#Activate Content Security Policy (CSP), which is supported by most browsers. #Tell the browser that scripts can only be downloaded from this domain and the URLs you explicitly specify.
# http://www.html5rocks.com/en/tutorials/security/content-security-policy/#inline-code-considered-harmful
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://ssl.google-analytics.com https://assets.zendesk.com https://connect.facebook.net; img-src 'self' https://ssl.google-analytics.com https://s-static.ak.facebook.com https://assets.zendesk.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://assets.zendesk.com; font-src 'self' https://themes.googleusercontent.com; frame-src https://assets.zendesk.com https://www.facebook.com https://s-static.ak.facebook.com https://tautt.zendesk.com; object-src 'none'";

server {
listen 443 ssl default deferred;
server_name .forgott.com;

ssl_certificate /etc/nginx/ssl/star_forgott_com.crt;
ssl_certificate_key /etc/nginx/ssl/star_forgott_com.key;

#Enable session re-use to improve https performance# http://vincent.bernat.im/en/blog/2011-ssl-session-reuse-rfc5077.html
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 5m;

# Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
ssl_dhparam /etc/nginx/ssl/dhparam.pem;

#Activate server-side protection from BEAST attacks# http://blog.ivanristic.com/2013/09/is-beast-still-a-threat.html
ssl_prefer_server_ciphers on;
# Disable SSLv3 (activated by default since nginx 0.8.19) http://en.wikipedia.org/wiki/Secure_Sockets_Layer#SSL_3.0
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# Choosing Ciphers for Confidentiality and Compatibility # http://blog.ivanristic.com/2013/08/configuring-apache-nginx-and-openssl-for-forward-secrecy.html
ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";

# Activate OCSP stapling (mechanism by which a site can convey certificate revocation information to visitors in a privacy-preserving, scalable manner)
# http://blog.mozilla.org/security/2013/07/29/ocsp-stapling-in-firefox/
resolver 8.8.8.8;
ssl_stapling on;
ssl_trusted_certificate /etc/nginx/ssl/star_forgott_com.crt;

# Configure and activate HSTS (HTTP Strict Transport Security) https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security
#Avoid SSL stripping https://en.wikipedia.org/wiki/SSL_stripping#SSL_stripping
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";

# ... the rest of your configuration
}

# redirect all http traffic to https
server {
listen 80;
server_name .forgott.com;
return 301 https://$host$request_uri;
}

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to increase your web performance by 3 times by turning on a parameter in Nginx
  • Using X-Sendfile header in Nginx to improve PHP file download performance (for large file downloads)
  • Django uses celery and NGINX to generate static pages to achieve performance optimization
  • Nginx+Tomcat high performance load balancing cluster construction tutorial
  • How to build a high-performance load balancing cluster with Nginx+Tomcat
  • Speed ​​up nginx performance: enable gzip and cache
  • Nginx server configuration performance optimization solution
  • Some suggestions for improving Nginx performance

<<:  Detailed explanation of the method of comparing dates in MySQL

>>:  Explain TypeScript mapped types and better literal type inference

Recommend

Comprehensive summary of MYSQL tables

Table of contents 1. Create a table 1.1. Basic sy...

CSS achieves highly adaptive full screen

When writing my own demo, I want to use display:f...

Design Theory: Textual Expression and Usability

<br />In text design, we usually focus on th...

404 error occurs when accessing the homepage of tomcat started in Docker mode

Scenario: When starting tomcat in docker (version...

Implementing WeChat tap animation effect based on CSS3 animation attribute

Seeing the recent popular WeChat tap function, I ...

CentOS 6.4 MySQL 5.7.18 installation and configuration method graphic tutorial

The specific steps of installing mysql5.7.18 unde...

Ubuntu compiles kernel modules, and the content is reflected in the system log

Table of contents 1.Linux login interface 2. Writ...

Nginx operation and maintenance domain name verification method example

When configuring the interface domain name, each ...

How to set up the terminal to run applications after Ubuntu starts

1. Enter start in the menu bar and click startup ...

Analysis of MySQL lock wait and deadlock problems

Table of contents Preface: 1. Understand lock wai...

Mysql | Detailed explanation of fuzzy query using wildcards (like,%,_)

Wildcard categories: %Percent wildcard: indicates...

Solve the problem of garbled data in MySQL database migration

Under the instructions of my leader, I took over ...