{"id":8903,"date":"2018-08-08T16:22:30","date_gmt":"2018-08-08T23:22:30","guid":{"rendered":"http:\/\/blog.networkpresence.co\/?p=8903"},"modified":"2018-08-08T16:22:30","modified_gmt":"2018-08-08T23:22:30","slug":"suggestions-for-nginx-hardening-security","status":"publish","type":"post","link":"http:\/\/blog.networkpresence.co\/?p=8903","title":{"rendered":"Suggestions for Nginx Hardening\/Security"},"content":{"rendered":"<p>This is a quick brief listing of suggestions for Nginx web server hardening or security items to check.<\/p>\n<p>Firstly, lots of this is mentioned in the Nginx instance of the &#8216;Awesome&#8217; series of sites<br \/>\non GitHub specifically on Nginx Security.<br \/>\nSee https:\/\/github.com\/wallarm\/awesome-nginx-security<\/p>\n<p>a) Disable Nginx server_tokens<br \/>\n&#8211; set &#8220;server_tokens off&#8221; in nginx.conf<\/p>\n<p>b) Minimal error pages<br \/>\n&#8211; add &#8220;error_page 401 403 404 \/404.html;&#8221; to sites-enabled\/ files and &#8220;server&#8221; config sections<\/p>\n<p>c) Settings to control Buffer Overflow Attacks<\/p>\n<p>Note: Both client_header_buffer_size &#038; large_client_header_buffers will need to be higher than suggested below if your site uses very long URLs.<\/p>\n<p>client_body_buffer_size &#8211; default is 8 or 16k, can probably be much lower.<br \/>\neg: client_body_buffer_size 1k<\/p>\n<p>client_header_buffer_size &#8211; again, 1k is usually sufficient:<br \/>\neg: client_header_buffer_size 1k<\/p>\n<p>client_max_body_size &#8211; controls clients throwing too much data at the web server in<br \/>\n sessions.<br \/>\nNeeds to be more if the site uses the POST HTTP method for file uploads or such.<br \/>\neg: client_max_body_size 1k<\/p>\n<p>large_client_header_buffers &#8211; related to larger client_header_buffer_size if needed.<br \/>\neg: large_client_header_buffers 2 1k<\/p>\n<p>d) Disable any unwanted HTTP methods, relevant conf items eg: in nginx.conf or a sites-enabled\/ file for this are:<br \/>\neg: To ensure HEAD, DELETE, SEARCH, TRACE methods won&#8217;t work<br \/>\n# Only GET, Post, PUT are allowed<br \/>\n     if ($request_method !~ ^(GET|PUT|POST)$ ) {<br \/>\n         return 444;<br \/>\n     }<\/p>\n<p>e) Ensure no PHP or JVM version or path etc information is passed back to Nginx. ie: Don&#8217;t send out X-Powered-By &#038; Server headers to clients<\/p>\n<p>f) Check SSL Ciphers, Protocol &#038; other SSL specific settings<br \/>\n(i) set ssl_ciphers to:<br \/>\nssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;<\/p>\n<p>(ii) set: ssl_protocols TLSv1.3;<\/p>\n<p>Other good suggestions for Nginx at https:\/\/cipherli.st\/<br \/>\n(iii) set:<br \/>\nssl_prefer_server_ciphers on;<br \/>\nssl_session_cache shared:SSL:10m;<\/p>\n<p>(iv) create &#038; use a strong DH Parameters file with: (takes some time to run)<br \/>\nopenssl dhparam -out \/etc\/nginx\/ssl\/dhparam.pem 4096<\/p>\n<p>(v) configure above .pem file, set:<br \/>\nssl_dhparam \/etc\/ssl\/certs\/dhparam.pem;<\/p>\n<p>(vi) ensure you&#8217;re using valid\/correct X-Frame-Options,<br \/>\nStrict-Transport-Security and other &#8216;secure&#8217; headers<br \/>\neg:<br \/>\nadd_header X-Frame-Options SAMEORIGIN;<br \/>\nadd_header X-Content-Type-Options nosniff;<br \/>\nadd_header X-XSS-Protection &#8220;1; mode=block&#8221;;<br \/>\nadd_header Strict-Transport-Security &#8220;max-age=31536000; includeSubdomains;&#8221;;<\/p>\n<p>(vii) consider whether or not to implement OSCP Stapling, see https:\/\/raymii.org\/s\/tutorials\/OCSP_Stapling_on_nginx.html<\/p>\n<p>g) Do &#8220;apt-get update &#038;&#038; apt-get upgrade&#8221; and see what new Linux Packages are available for the Distro.<\/p>\n<p>h) Work through the checklist of https:\/\/www.nginx.com\/resources\/wiki\/start\/topics\/tutorials\/config_pitfalls\/<\/p>\n<p>i) Check on backend server or content generation (PHP, Tomcat, JVM, etc etc) settings, outside of Nginx itself.<\/p>\n<p>FYI,<br \/>\nRichard.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a quick brief listing of suggestions for Nginx web server hardening or security items to check. Firstly, lots of this is mentioned in the Nginx instance of the &#8216;Awesome&#8217; series of sites on GitHub specifically on Nginx Security. &hellip; <a href=\"http:\/\/blog.networkpresence.co\/?p=8903\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,70],"tags":[548,21,78],"class_list":["post-8903","post","type-post","status-publish","format-standard","hentry","category-network-presence","category-sales","tag-nginx","tag-security","tag-sysadmin"],"_links":{"self":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts\/8903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8903"}],"version-history":[{"count":1,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts\/8903\/revisions"}],"predecessor-version":[{"id":8904,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=\/wp\/v2\/posts\/8903\/revisions\/8904"}],"wp:attachment":[{"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8903"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.networkpresence.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}