{"id":765,"date":"2020-05-21T07:20:52","date_gmt":"2020-05-21T07:20:52","guid":{"rendered":"http:\/\/ubiq.co\/tech-blog\/?p=765"},"modified":"2025-08-13T04:56:33","modified_gmt":"2025-08-13T04:56:33","slug":"block-ip-address-nginx","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/","title":{"rendered":"How to Block IP Address in NGINX"},"content":{"rendered":"<p>Sometimes you may need to block IP addresses to protect your website from malicious attacks such as DOS &amp; DDOS. Here&#8217;s how to easily block IP address in NGINX to restrict IP addresses or block access. You can use these steps for blocking\/allowing IP addresses in NGINX.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#How_to_Block_IP_Address_in_NGINX\" >How to Block IP Address in NGINX<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#1_Open_NGINX_configuration_file\" >1. Open NGINX configuration file<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#2_Block_IP_address_in_NGINX\" >2. Block IP address in NGINX<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#Block_IP_address_in_NGINX_for_website_or_domain\" >Block IP address in NGINX for website or domain<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#Block_IP_Address_in_NGINX_for_subdomain\" >Block IP Address in NGINX for subdomain<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#Block_IP_range_in_NGINX\" >Block IP range in NGINX<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#Block_IP_Address_in_NGINX_for_URL\" >Block IP Address in NGINX for URL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#Block_Multiple_IP_in_NGINX\" >Block Multiple IP in NGINX<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#3_Restart_NGINX\" >3. Restart NGINX<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Block_IP_Address_in_NGINX\"><\/span>How to Block IP Address in NGINX<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Here are the steps to block IP address in NGINX.<\/p>\n<p>You can easily block IP addresses, subnets and IP ranges using <em>deny<\/em> directive. Similarly, you can allow ip addresses, subnets and IP ranges using <em>allow<\/em> directive. You can place <em>deny<\/em> or <em>allow<\/em> directives in <em>http<\/em>, <em>server<\/em> or <em>location<\/em> context. You can even use a combination of <em>deny<\/em> and <em>allow<\/em> directives.<\/p>\n<p>We will look at each of these use cases separately.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"1_Open_NGINX_configuration_file\"><\/span>1. Open NGINX configuration file<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you are using NGINX&#8217;s main configuration file nginx.conf, without virtual hosts, then run the following command<\/p>\n<pre>$ sudo vi \/etc\/nginx\/nginx.conf\n<\/pre>\n<p>If you have configured separate virtual hosts for your website (e.g www.website.com), such as \/etc\/nginx\/sites-enabled\/website.conf then open its configuration with the following command<\/p>\n<pre>$ sudo vi\u00a0\/etc\/nginx\/sites-enabled\/website.conf<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"2_Block_IP_address_in_NGINX\"><\/span>2. Block IP address in NGINX<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>There are multiple ways to block IP address in NGINX. We will look at each of them. If you want to block IP 45.43.23.21 for domain or your entire website, you can add the following lines in your configuration file.<\/p>\n<pre><strong>deny<\/strong> 45.43.23.21;\n<\/pre>\n<p>The above lines will make NGINX deny IP 45.43.23.21.<\/p>\n<p>Bonus Read : <a href=\"http:\/\/ubiq.co\/tech-blog\/how-to-whitelist-ip-in-nginx\/\">How to Whitelist IP Address in NGINX<\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Block_IP_address_in_NGINX_for_website_or_domain\"><\/span>Block IP address in NGINX for website or domain<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Add the above lines in any of the <em>http<\/em>, server or <em>location<\/em> \/ blocks as shown below<\/p>\n<pre><strong>http<\/strong>{\n   ...\n   deny 45.43.23.21;\n   ...\n}\n\n<strong>server<\/strong>{\n    ...\n    deny 45.43.23.21;\n    ...\n}\n\n\n<strong>location \/<\/strong> {\n   deny 45.43.23.21;\n}\n<\/pre>\n<p>\u00a0<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Block_IP_Address_in_NGINX_for_subdomain\"><\/span>Block IP Address in NGINX for subdomain<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Let&#8217;s say you have two subdomains (<em>blog.website.com<\/em> and <em>articles.website.com<\/em>) with their NGINX config files at <em>\/etc\/nginx\/sites-enabled\/blog.conf<\/em> and\u00a0<em>\/etc\/nginx\/sites-enabled\/articles.conf<\/em><\/p>\n<p>If you want to block IP address in NGINX for only 1 subdomain (e.g blog.website.com) then place the above-mentioned line in blog.conf file of that subdomain<\/p>\n<pre>$ sudo vim\u00a0\/etc\/nginx\/sites-enabled\/blog.conf\n<\/pre>\n<pre>server {\n  server <strong>blog.website.com<\/strong>;\n  <strong>deny 45.43.23.21;<\/strong>\n}<\/pre>\n<p>If you want to block IP address in both subdomains, then add the line in both <em>blog.conf<\/em>\u00a0and <em>articles.conf<\/em> files.<\/p>\n<p>\u00a0<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Block_IP_range_in_NGINX\"><\/span>Block IP range in NGINX<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you want to allow an IP range such as 45.43.23.0 &#8211; 45.43.23.255, then use the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Classless_Inter-Domain_Routing#CIDR_notation\" target=\"_blank\" rel=\"noopener\">CIDR format<\/a> for your IP range, since NGINX accepts only IP addresses and CIDR formats. You can get the CIDR for your IP address range using <a href=\"https:\/\/www.ipaddressguide.com\/cidr\" target=\"_blank\" rel=\"noopener\">IP to CIDR tools<\/a>.<\/p>\n<pre>location \/ {\n  deny <strong>45.43.23.0\/24<\/strong>;\n}\n<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Block_IP_Address_in_NGINX_for_URL\"><\/span>Block IP Address in NGINX for URL<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you want to block IP for just one URL (e.g \/accounts\/login) then add the above <em>deny<\/em> directive in\u00a0<em>location<\/em> block of that URL.<\/p>\n<pre>location\u00a0<strong>\/accounts\/login<\/strong> {\n   deny 45.43.23.21;\n}\n<\/pre>\n<p>\u00a0<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Block_Multiple_IP_in_NGINX\"><\/span>Block Multiple IP in NGINX<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you want to block multiple IP addresses in NGINX to restrict access to multiple IP addresses, just add multiple <em>deny<\/em> directives as shown below, one for each IP<\/p>\n<pre><strong>deny<\/strong> 45.43.23.21;\n<strong>deny<\/strong> 44.23.13.10;\n<strong>allow all<\/strong>;<\/pre>\n<p>The above code will block IP addresses 45.43.23.21 &amp; 44.23.13.10, and allow others.<\/p>\n<p>You can also combine IP address and CIDR ranges together, as shown below<\/p>\n<pre><strong>deny<\/strong> 44.23.13.10;\n<strong>deny<\/strong> 45.43.23.0\/24;\n<strong>allow all<\/strong>;<\/pre>\n<p>\u00a0<\/p>\n<h2><span class=\"ez-toc-section\" id=\"3_Restart_NGINX\"><\/span>3. Restart NGINX<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Finally, run the following command to check syntax of your updated config file.<\/p>\n<pre>$ sudo nginx -t\n<\/pre>\n<p>If there are no errors, run the following command to restart NGINX server.<\/p>\n<pre>$ sudo service nginx reload #debian\/ubuntu\n$ systemctl restart nginx #redhat\/centos\n<\/pre>\n<p>That&#8217;s it! Now NGINX will block access to those IP addresses and ranges mentioned in your configuration file.<\/p>\n<p>By the way, if you want to create charts &amp; dashboards to monitor your business or website, you can try <a href=\"https:\/\/ubiq.co\">Ubiq<\/a>. We offer a 14-day free trial.<\/p>\n<p>Also read:<br \/><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-whitelist-ip-in-nginx\/\">How to Whitelist IP in NGINX<\/a><br \/><a href=\"https:\/\/ubiq.co\/tech-blog\/fix-504-gateway-timeout-error-nginx\/\">How to Fix 504 Gateway Timeout Error<\/a><br \/><a href=\"https:\/\/ubiq.co\/tech-blog\/fix-500-internal-server-error-nginx\/\">How to Fix 500 Internal Server Error in NGINX<\/a><\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>NGINX allows you to deny IP address, restrict IP address for allowing\/blocking access. Here&#8217;s how to block IP address in NGINX.<\/p>\n","protected":false},"author":1,"featured_media":769,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[61,60,59],"class_list":["post-765","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nginx","tag-block-access","tag-block-ip-addresses","tag-deny"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Block IP Address in NGINX - Ubiq BI<\/title>\n<meta name=\"description\" content=\"NGINX allows you to deny IP address, restrict IP address for allowing\/blocking access. Here&#039;s how to block IP address in NGINX.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Block IP Address in NGINX - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"NGINX allows you to deny IP address, restrict IP address for allowing\/blocking access. Here&#039;s how to block IP address in NGINX.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-21T07:20:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-13T04:56:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/05\/block-ip-address-in-nginx.png\" \/>\n\t<meta property=\"og:image:width\" content=\"805\" \/>\n\t<meta property=\"og:image:height\" content=\"488\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/block-ip-address-nginx\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/block-ip-address-nginx\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Block IP Address in NGINX\",\"datePublished\":\"2020-05-21T07:20:52+00:00\",\"dateModified\":\"2025-08-13T04:56:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/block-ip-address-nginx\\\/\"},\"wordCount\":593,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/block-ip-address-nginx\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/block-ip-address-in-nginx.png?fit=805%2C488&ssl=1\",\"keywords\":[\"block access\",\"block ip addresses\",\"deny\"],\"articleSection\":[\"Nginx\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/block-ip-address-nginx\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/block-ip-address-nginx\\\/\",\"name\":\"How to Block IP Address in NGINX - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/block-ip-address-nginx\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/block-ip-address-nginx\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/block-ip-address-in-nginx.png?fit=805%2C488&ssl=1\",\"datePublished\":\"2020-05-21T07:20:52+00:00\",\"dateModified\":\"2025-08-13T04:56:33+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"NGINX allows you to deny IP address, restrict IP address for allowing\\\/blocking access. Here's how to block IP address in NGINX.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/block-ip-address-nginx\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/block-ip-address-nginx\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/block-ip-address-nginx\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/block-ip-address-in-nginx.png?fit=805%2C488&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/block-ip-address-in-nginx.png?fit=805%2C488&ssl=1\",\"width\":805,\"height\":488,\"caption\":\"block ip address in nginx\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/block-ip-address-nginx\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Block IP Address in NGINX\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Block IP Address in NGINX - Ubiq BI","description":"NGINX allows you to deny IP address, restrict IP address for allowing\/blocking access. Here's how to block IP address in NGINX.","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:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/","og_locale":"en_US","og_type":"article","og_title":"How to Block IP Address in NGINX - Ubiq BI","og_description":"NGINX allows you to deny IP address, restrict IP address for allowing\/blocking access. Here's how to block IP address in NGINX.","og_url":"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2020-05-21T07:20:52+00:00","article_modified_time":"2025-08-13T04:56:33+00:00","og_image":[{"width":805,"height":488,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/05\/block-ip-address-in-nginx.png","type":"image\/png"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Block IP Address in NGINX","datePublished":"2020-05-21T07:20:52+00:00","dateModified":"2025-08-13T04:56:33+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/"},"wordCount":593,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/05\/block-ip-address-in-nginx.png?fit=805%2C488&ssl=1","keywords":["block access","block ip addresses","deny"],"articleSection":["Nginx"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/","url":"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/","name":"How to Block IP Address in NGINX - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/05\/block-ip-address-in-nginx.png?fit=805%2C488&ssl=1","datePublished":"2020-05-21T07:20:52+00:00","dateModified":"2025-08-13T04:56:33+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"NGINX allows you to deny IP address, restrict IP address for allowing\/blocking access. Here's how to block IP address in NGINX.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/05\/block-ip-address-in-nginx.png?fit=805%2C488&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/05\/block-ip-address-in-nginx.png?fit=805%2C488&ssl=1","width":805,"height":488,"caption":"block ip address in nginx"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/block-ip-address-nginx\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Block IP Address in NGINX"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2020\/05\/block-ip-address-in-nginx.png?fit=805%2C488&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-cl","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=765"}],"version-history":[{"count":10,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/765\/revisions"}],"predecessor-version":[{"id":9085,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/765\/revisions\/9085"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/769"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}