{"id":5965,"date":"2019-07-08T07:10:21","date_gmt":"2019-07-08T07:10:21","guid":{"rendered":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?p=5965"},"modified":"2019-07-08T07:10:21","modified_gmt":"2019-07-08T07:10:21","slug":"block-ips-with-nginx","status":"publish","type":"post","link":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/","title":{"rendered":"How to Block IPs with Nginx?"},"content":{"rendered":"<p><strong>Check the below steps to block an IP address:<\/strong><\/p>\n<p>1. Create a file with the name access.conf in this \/nginx\/example.com directory.<\/p>\n<p>2. Add the contents from the below sections.<\/p>\n<p>3. Remember to reload Nginx for the changes to take effect.<\/p>\n<p><strong>Command for Blocking an IP from Hitting Your Site:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">location \/ {\r\ndeny 1.2.3.4;\r\n}<\/pre>\n<p>This command blocks the IP address of 1.2.3.4 so that no one with this IP address is able to access your site entirely.<\/p>\n<p><strong>Command for Blocking an IP from Hitting a Subdirectory<\/strong><\/p>\n<pre class=\"lang:default decode:true \">location \/subdirectory\/ {\r\ndeny 1.2.3.4;\r\n}<\/pre>\n<p><strong>Command to Allow a Single IP while Blocking All Others<\/strong><\/p>\n<p>In case you want to block access to all IPs but allow a specific IP to still access your site, use the below command:<\/p>\n<pre class=\"lang:default decode:true \">location \/ {\r\nallow 9.8.7.6;\r\ndeny all;\r\n}<\/pre>\n<p>This command is helpful if you&#8217;re working on your site and want just you to view it and not others.<\/p>\n<h3>Combining Rules<\/h3>\n<p>It is also possible to create and combine multiple sets of these rules in your access.conf file:<\/p>\n<pre class=\"lang:default decode:true \">location \/subdir {\r\nallow 1.2.3.4;\r\ndeny all;\r\n}\r\n\r\nlocation \/ {\r\ndeny all;\r\n}<\/pre>\n<p>With the above command only the IP address 1.2.3.4 will be allowed to browse the subdirectory named \/subdir. All other IPs will be blocked from everywhere in your site.<\/p>\n<p>This way you can block IPs with Nginx.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Check the below steps to block an IP address: 1. Create a file with the name access.conf in this \/nginx\/example.com directory. 2. Add the contents from the below sections. 3. Remember to reload Nginx for the changes to take effect. Command for Blocking an IP from Hitting Your Site: location \/ { deny 1.2.3.4; } [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[846,847,848],"class_list":["post-5965","post","type-post","status-publish","format-standard","placeholder-for-hentry","category-howtos","tag-block-ips","tag-block-ips-with-nginx","tag-nginx"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Learn to Block IPs with Nginx using Simple Commands<\/title>\n<meta name=\"description\" content=\"Do you know you can block IPs with Nginx too? The article reveals simple commands to block IPs with 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:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn to Block IPs with Nginx using Simple Commands\" \/>\n<meta property=\"og:description\" content=\"Do you know you can block IPs with Nginx too? The article reveals simple commands to block IPs with Nginx.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Hosting FAQs by MilesWeb\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-08T07:10:21+00:00\" \/>\n<meta name=\"author\" content=\"Pallavi Godse\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pallavi Godse\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/\",\"name\":\"Learn to Block IPs with Nginx using Simple Commands\",\"isPartOf\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website\"},\"datePublished\":\"2019-07-08T07:10:21+00:00\",\"author\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/7e3952607fa9eb4e82fea9f7cad9c945\"},\"description\":\"Do you know you can block IPs with Nginx too? The article reveals simple commands to block IPs with Nginx.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Block IPs with Nginx?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/\",\"name\":\"Web Hosting FAQs by MilesWeb\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/7e3952607fa9eb4e82fea9f7cad9c945\",\"name\":\"Pallavi Godse\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eefc9695ea2b2c6e143c9c9919701aaa?s=96&d=blank&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eefc9695ea2b2c6e143c9c9919701aaa?s=96&d=blank&r=g\",\"caption\":\"Pallavi Godse\"},\"description\":\"Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/author\/pallavi\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learn to Block IPs with Nginx using Simple Commands","description":"Do you know you can block IPs with Nginx too? The article reveals simple commands to block IPs with 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:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/","og_locale":"en_GB","og_type":"article","og_title":"Learn to Block IPs with Nginx using Simple Commands","og_description":"Do you know you can block IPs with Nginx too? The article reveals simple commands to block IPs with Nginx.","og_url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/","og_site_name":"Web Hosting FAQs by MilesWeb","article_published_time":"2019-07-08T07:10:21+00:00","author":"Pallavi Godse","twitter_misc":{"Written by":"Pallavi Godse","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/","name":"Learn to Block IPs with Nginx using Simple Commands","isPartOf":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website"},"datePublished":"2019-07-08T07:10:21+00:00","author":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/7e3952607fa9eb4e82fea9f7cad9c945"},"description":"Do you know you can block IPs with Nginx too? The article reveals simple commands to block IPs with Nginx.","breadcrumb":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/block-ips-with-nginx\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/"},{"@type":"ListItem","position":2,"name":"How to Block IPs with Nginx?"}]},{"@type":"WebSite","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/","name":"Web Hosting FAQs by MilesWeb","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/7e3952607fa9eb4e82fea9f7cad9c945","name":"Pallavi Godse","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/eefc9695ea2b2c6e143c9c9919701aaa?s=96&d=blank&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eefc9695ea2b2c6e143c9c9919701aaa?s=96&d=blank&r=g","caption":"Pallavi Godse"},"description":"Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/author\/pallavi\/"}]}},"views":741,"_links":{"self":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/5965","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/comments?post=5965"}],"version-history":[{"count":1,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/5965\/revisions"}],"predecessor-version":[{"id":5966,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/5965\/revisions\/5966"}],"wp:attachment":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/media?parent=5965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/categories?post=5965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/tags?post=5965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}