{"id":420,"date":"2026-06-14T16:25:53","date_gmt":"2026-06-14T16:25:53","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=420"},"modified":"2026-06-14T16:25:53","modified_gmt":"2026-06-14T16:25:53","slug":"how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/","title":{"rendered":"How to Secure Nginx on VPS: Firewall, SSL, and Rate Limiting Setup"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Nginx powers over 30% of all websites, and its popularity makes it a frequent target for automated attacks, brute force logins, and DDoS attempts. Securing Nginx on your VPS isn&#8217;t optional &#8212; it&#8217;s the minimum baseline for running any production workload. This guide walks through the three most impactful security layers: firewall rules, SSL\/TLS hardening, and rate limiting configurations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We assume you have root access to a Linux VPS running Nginx. If you haven&#8217;t picked a provider yet, compare options on our <a href=\"https:\/\/virtualserversvps.com\/#providers\">VPS comparison table<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Firewall: Lock Down Everything Except Ports 80 and 443<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Start with a default-deny firewall policy. UFW (Uncomplicated Firewall) is the simplest option on Ubuntu:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw default deny incoming\nsudo ufw default allow outgoing\nsudo ufw allow ssh\nsudo ufw allow 80\/tcp\nsudo ufw allow 443\/tcp\nsudo ufw enable<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This allows SSH management and web traffic only. If your application needs additional ports (e.g., 8080 for a Node.js app, 3306 for MySQL from a specific IP), add them individually rather than opening wide ranges.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For tighter control, restrict SSH to your office or home IP:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow from 203.0.113.50 to any port 22<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced: Nginx-Specific iptables Rules<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For high-traffic servers, bypass UFW and write direct iptables rules. Limit connection rates to prevent SYN floods:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>iptables -A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 100 --connlimit-mask 32 -j DROP\niptables -A INPUT -p tcp --syn --dport 443 -m connlimit --connlimit-above 100 --connlimit-mask 32 -j DROP<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These rules drop connections from any single IP that exceeds 100 concurrent connections to ports 80 or 443. Adjust the threshold based on your traffic profile.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. SSL\/TLS: Move Beyond Default Certificates<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s Encrypt provides free, automated certificates, but the default configuration leaves security on the table. Hardening your TLS setup blocks downgrade attacks and ensures modern clients connect with strong ciphers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Generate a Strong DH Parameter<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Diffie-Hellman key exchange strength depends on the parameter size. Generate a 4096-bit DH group (this takes a few minutes on a VPS):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo openssl dhparam -out \/etc\/ssl\/certs\/dhparam.pem 4096<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Hardened Nginx SSL Configuration<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Replace your <code>server<\/code> block SSL settings with these:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssl_protocols TLSv1.2 TLSv1.3;\nssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;\nssl_prefer_server_ciphers off;\nssl_ecdh_curve secp384r1;\nssl_dhparam \/etc\/ssl\/certs\/dhparam.pem;\nssl_session_cache shared:SSL:10m;\nssl_session_timeout 10m;\nssl_session_tickets off;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This configuration: enforces TLS 1.2 and 1.3 only, uses AEAD ciphers (GCM mode), disables session tickets (prevents ticket-based decryption attacks), and sets a secure ECDH curve. Test your setup at <a href=\"https:\/\/www.ssllabs.com\/ssltest\/\" target=\"_blank\" rel=\"noreferrer noopener\">SSL Labs<\/a> &#8212; aim for an A+ rating.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Enable HSTS and Security Headers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add these headers to your Nginx config to prevent downgrade attacks and content injection:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_header Strict-Transport-Security \"max-age=63072000; includeSubDomains; preload\" always;\nadd_header X-Content-Type-Options \"nosniff\" always;\nadd_header X-Frame-Options \"SAMEORIGIN\" always;\nadd_header X-XSS-Protection \"1; mode=block\" always;\nadd_header Referrer-Policy \"strict-origin-when-cross-origin\" always;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">HSTS tells browsers to always connect via HTTPS for the next two years. Submit your domain to the <a href=\"https:\/\/hstspreload.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">HSTS preload list<\/a> for baked-in protection in Chrome, Firefox, and Safari.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Rate Limiting: Stop Brute Force and DDoS at the Nginx Layer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Nginx has a built-in rate limiting module that tracks requests by IP and throttles clients exceeding a threshold. This stops brute force login attempts, XML-RPC attacks on WordPress, and resource-exhaustion DDoS.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Rate Limiting for All Requests<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In your <code>http<\/code> block, define a limit zone:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>limit_req_zone $binary_remote_addr zone=basic:10m rate=30r\/s;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then apply it in your <code>server<\/code> or <code>location<\/code> blocks:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>limit_req zone=basic burst=50 nodelay;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This allows 30 requests per second per IP, with a burst capacity of 50 before queuing or dropping. Adjust the rate based on your site&#8217;s typical traffic patterns.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Login Page Hardening<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Apply stricter limits to login endpoints. For WordPress, target <code>wp-login.php<\/code> and <code>xmlrpc.php<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>location \/wp-login.php {\n    limit_req zone=login:10m rate=3r\/m;\n    limit_conn login_conn 5;\n    # ... rest of config\n}\n\nlocation \/xmlrpc.php {\n    deny all;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This limits login attempts to 3 per minute per IP and blocks the notoriously insecure XML-RPC endpoint entirely (unless you specifically need it for the Jetpack app or mobile clients).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Connection Limiting<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Complement rate limiting with connection limits per IP:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>limit_conn_zone $binary_remote_addr zone=addr:10m;\n\nserver {\n    limit_conn addr 10;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This limits each IP to 10 concurrent connections. Combined with rate limiting, it effectively mitigates most layer 7 DDoS attacks targeting your VPS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Putting It All Together<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A complete Nginx security configuration combines all three layers. Start with the firewall to control access at the network level, then harden SSL\/TLS to protect data in transit, and finish with rate limiting to defend the application layer. Test every change in a staging environment before applying to production.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a managed VPS that includes pre-configured security, consider <a href=\"https:\/\/cloudways.com\/en\/?id=2010927&amp;data1=virtualserversvps\" target=\"_blank\" rel=\"noreferrer noopener sponsored\">Cloudways ($14\/month)<\/a> with built-in firewall and automated SSL. Budget-conscious users can start with <a href=\"https:\/\/interserver.net\/vps?id=1067805&amp;sid=virtualserversvps\" target=\"_blank\" rel=\"noreferrer noopener sponsored\">InterServer ($3\/month)<\/a> and apply these hardening steps manually. Browse all providers on our <a href=\"https:\/\/virtualserversvps.com\/#providers\">VPS comparison table<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nginx powers over 30% of all websites, and its popularity makes it a frequent target for automated attacks, brute force logins, and DDoS attempts. Securing Nginx on your VPS isn&#8217;t&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-420","post","type-post","status-publish","format-standard","hentry","category-vps-guides-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Secure Nginx on VPS: Firewall, SSL, and Rate Limiting Setup - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Secure Nginx on VPS: Firewall, SSL, and Rate Limiting Setup\" \/>\n<meta property=\"og:description\" content=\"How to Secure Nginx on VPS: Firewall, SSL, and Rate Limiting Setup\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-06-14T16:25:53+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/\",\"name\":\"How to Secure Nginx on VPS: Firewall, SSL, and Rate Limiting Setup - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-06-14T16:25:53+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Secure Nginx on VPS: Firewall, SSL, and Rate Limiting Setup\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Secure Nginx on VPS: Firewall, SSL, and Rate Limiting Setup - Virtual Servers VPS Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/","og_locale":"en_US","og_type":"article","og_title":"How to Secure Nginx on VPS: Firewall, SSL, and Rate Limiting Setup","og_description":"How to Secure Nginx on VPS: Firewall, SSL, and Rate Limiting Setup","og_url":"https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-06-14T16:25:53+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/","url":"https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/","name":"How to Secure Nginx on VPS: Firewall, SSL, and Rate Limiting Setup - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-06-14T16:25:53+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/how-to-secure-nginx-on-vps-firewall-ssl-rate-limiting\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Secure Nginx on VPS: Firewall, SSL, and Rate Limiting Setup"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/420","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=420"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/420\/revisions"}],"predecessor-version":[{"id":423,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/420\/revisions\/423"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}