{"id":3031,"date":"2025-03-28T17:49:51","date_gmt":"2025-03-28T17:49:51","guid":{"rendered":"https:\/\/designersgate.com\/blog\/?p=3031"},"modified":"2025-03-28T17:49:51","modified_gmt":"2025-03-28T17:49:51","slug":"blocking-direct-access-to-specific-file-types","status":"publish","type":"post","link":"https:\/\/designersgate.com\/blog\/blocking-direct-access-to-specific-file-types\/","title":{"rendered":"Blocking Direct Access to Specific File Types"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>As a developer, there are certain files you do not want to expose via HTTP access protocols, particularly configuration files or a custom serverless database type using XML or JSON files. To prevent access, you can simply block access to those files or even a sub-directory.<\/p>\n<\/blockquote>\n\n\n<figure style=\"aspect-ratio:4\/3;\" class=\"wp-block-post-featured-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/designersgate.com\/blog\/wp-content\/uploads\/2025\/03\/a-funny-image-of-a-young-developer-typing-looking-at-the-screen-of-his-laptop-very-intently-hard-at-work-typing.-photo-realistic.jpg\" class=\"attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"made with Microsoft\u00ae Copilot\" style=\"width:100%;height:100%;object-fit:cover;\" srcset=\"https:\/\/designersgate.com\/blog\/wp-content\/uploads\/2025\/03\/a-funny-image-of-a-young-developer-typing-looking-at-the-screen-of-his-laptop-very-intently-hard-at-work-typing.-photo-realistic.jpg 1024w, https:\/\/designersgate.com\/blog\/wp-content\/uploads\/2025\/03\/a-funny-image-of-a-young-developer-typing-looking-at-the-screen-of-his-laptop-very-intently-hard-at-work-typing.-photo-realistic-300x300.jpg 300w, https:\/\/designersgate.com\/blog\/wp-content\/uploads\/2025\/03\/a-funny-image-of-a-young-developer-typing-looking-at-the-screen-of-his-laptop-very-intently-hard-at-work-typing.-photo-realistic-150x150.jpg 150w, https:\/\/designersgate.com\/blog\/wp-content\/uploads\/2025\/03\/a-funny-image-of-a-young-developer-typing-looking-at-the-screen-of-his-laptop-very-intently-hard-at-work-typing.-photo-realistic-768x768.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n<p>Is very simple, but this depends on what webserver type your website is hosted in. Surprisingly most website as of 2025 are hosted under Nginx.<\/p>\n\n\n\n<p>Based on data from w3techs.com, these are the most possible environments which your website might be hosted. As of March 2025, here are some statistics about the usage of Apache, Nginx, and IIS:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Nginx<\/strong>: Used by approximately 33.8% of all websites whose web server is known.<\/li>\n\n\n\n<li><strong>Apache<\/strong>: Accounts for about 26.6% of websites.<\/li>\n\n\n\n<li><strong>Microsoft-IIS<\/strong>: Has a smaller share, being used by 4.1% of websites.<\/li>\n<\/ul>\n\n\n\n<p>These numbers highlight the popularity of Nginx and Apache as leading web servers, with IIS trailing behind.<\/p>\n\n\n\n<p>With that in mind I will give you solutions for Nginx, Apache, and IIS for the few of you that might be hosted under that environment.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Nginx<\/h4>\n\n\n\n<p>To prevent access to specific file types in Nginx, you can use the <code>location<\/code> directive in your Nginx configuration file. Here&#8217;s an example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"server {\n    listen 80;\n    server_name yourdomain.com;\n\n    location ~ \\.(txt|xml|json)$ {\n        deny all;\n        return 404;\n    }\n\n    location \/ {\n        # Your other configurations\n        try_files $uri $uri\/ =404;\n    }\n}\n\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">server<\/span><span style=\"color: #D8DEE9FF\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">   <\/span><span style=\"color: #81A1C1\"> listen <\/span><span style=\"color: #D8DEE9FF\">80<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">   <\/span><span style=\"color: #81A1C1\"> server_name <\/span><span style=\"color: #D8DEE9FF\">yourdomain.com<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">location<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">~<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #EBCB8B\">\\.(txt|xml|json)$ <\/span><span style=\"color: #D8DEE9FF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">       <\/span><span style=\"color: #81A1C1\"> deny <\/span><span style=\"color: #D8DEE9FF\">all<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">404<\/span><span style=\"color: #D8DEE9FF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">location<\/span><span style=\"color: #D8DEE9FF\"> \/ {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #616E88\"># Your other configurations<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">       <\/span><span style=\"color: #81A1C1\"> try_files $<\/span><span style=\"color: #D8DEE9\">uri<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">$<\/span><span style=\"color: #D8DEE9\">uri<\/span><span style=\"color: #D8DEE9FF\">\/ <\/span><span style=\"color: #B48EAD\">=404<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This configuration blocks access to <code>.txt<\/code>, <code>.xml<\/code>, and <code>.json<\/code> files by denying all requests and returning a 404 error. You can modify the file extensions in the <code>location ~<\/code> directive to suit your needs.<\/p>\n\n\n\n<p>To block access to specific file types within a particular directory in Nginx, you can refine the configuration using a <code>location<\/code> directive specific to that directory. Here&#8217;s an example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"server {\n    listen 80;\n    server_name yourdomain.com;\n\n    location \/restricted-directory\/ {\n        location ~ \\.(txt|xml|json)$ {\n            deny all;\n            return 404;\n        }\n    }\n\n    location \/ {\n        # Your other configurations\n        try_files $uri $uri\/ =404;\n    }\n}\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">server<\/span><span style=\"color: #D8DEE9FF\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">   <\/span><span style=\"color: #81A1C1\"> listen <\/span><span style=\"color: #D8DEE9FF\">80<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">   <\/span><span style=\"color: #81A1C1\"> server_name <\/span><span style=\"color: #D8DEE9FF\">yourdomain.com<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">location<\/span><span style=\"color: #D8DEE9FF\"> \/restricted-directory\/ {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">location<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">~<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #EBCB8B\">\\.(txt|xml|json)$ <\/span><span style=\"color: #D8DEE9FF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">           <\/span><span style=\"color: #81A1C1\"> deny <\/span><span style=\"color: #D8DEE9FF\">all<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">404<\/span><span style=\"color: #D8DEE9FF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">location<\/span><span style=\"color: #D8DEE9FF\"> \/ {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #616E88\"># Your other configurations<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">       <\/span><span style=\"color: #81A1C1\"> try_files $<\/span><span style=\"color: #D8DEE9\">uri<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">$<\/span><span style=\"color: #D8DEE9\">uri<\/span><span style=\"color: #D8DEE9FF\">\/ <\/span><span style=\"color: #B48EAD\">=404<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this configuration:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>\/restricted-directory\/<\/code> is the directory you want to restrict.<\/li>\n\n\n\n<li><code>location ~ \\.(txt|xml|json)$<\/code> specifies the file types to block within that directory.<\/li>\n<\/ul>\n\n\n\n<p>After updating your Nginx configuration file, make sure to reload Nginx to apply the changes:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"sudo nginx -s reload\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">sudo<\/span><span style=\"color: #D8DEE9FF\"> nginx -s reload<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>If you are like me, you appreciate the performance of Nginx but continue to use Apache due to its ease of use in that environment, keep reading.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Apache<\/h4>\n\n\n\n<p>Configuring Apache is simpler, which is why many us still to use it.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Via .htaccess<\/h5>\n\n\n\n<p>To block access to specific file types in a particular directory with Apache, you can use an <code>.htaccess<\/code> file or modify the Apache configuration file. Here&#8217;s an example using <code>.htaccess<\/code>:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;FilesMatch &quot;\\.(txt|xml|json)$&quot;&gt;\n    Require all denied\n&lt;\/FilesMatch&gt;\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">&lt;<\/span><span style=\"color: #D8DEE9FF\">FilesMatch <\/span><span style=\"color: #A3BE8C\">&quot;\\.(txt|xml|json)$&quot;<\/span><span style=\"color: #81A1C1\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">Require<\/span><span style=\"color: #D8DEE9FF\"> all denied<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">&lt;\/<\/span><span style=\"color: #D8DEE9FF\">FilesMatch<\/span><span style=\"color: #81A1C1\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This configuration denies access to files with <code>.txt<\/code>, <code>.xml<\/code>, and <code>.json<\/code> extensions in the specified directory.<\/p>\n\n\n\n<p>This is assuming that your webserver allows you to configure via <code>.htaccess<\/code> files. If it doesn&#8217;t then you need to take the following steps to be able to.<\/p>\n\n\n\n<p><strong>Step 1.<\/strong> Ensure that the <code>AllowOverride<\/code> directive in your Apache configuration permits <code>.htaccess<\/code> files. For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;Directory &quot;\/path\/to\/your\/directory&quot;&gt;\n    AllowOverride All\n&lt;\/Directory&gt;\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">&lt;<\/span><span style=\"color: #D8DEE9FF\">Directory <\/span><span style=\"color: #A3BE8C\">&quot;\/path\/to\/your\/directory&quot;<\/span><span style=\"color: #81A1C1\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">AllowOverride<\/span><span style=\"color: #D8DEE9FF\"> All<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">&lt;\/<\/span><span style=\"color: #D8DEE9FF\">Directory<\/span><span style=\"color: #81A1C1\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Step 2.<\/strong> Restart Apache to apply the changes:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"sudo systemctl restart apache2\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #88C0D0\">sudo<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #A3BE8C\">systemctl<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #A3BE8C\">restart<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #A3BE8C\">apache2<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h5 class=\"wp-block-heading\">Directly on the http-conf file<\/h5>\n\n\n\n<p>If you&#8217;d rather configure this directly in the Apache configuration file, you can use the <code>&lt;Directory><\/code> directive:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;Directory &quot;\/path\/to\/your\/directory&quot;&gt;\n    &lt;FilesMatch &quot;\\.(txt|xml|json)$&quot;&gt;\n        Require all denied\n    &lt;\/FilesMatch&gt;\n&lt;\/Directory&gt;\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">&lt;<\/span><span style=\"color: #D8DEE9FF\">Directory <\/span><span style=\"color: #A3BE8C\">&quot;\/path\/to\/your\/directory&quot;<\/span><span style=\"color: #81A1C1\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">&lt;<\/span><span style=\"color: #D8DEE9FF\">FilesMatch <\/span><span style=\"color: #A3BE8C\">&quot;\\.(txt|xml|json)$&quot;<\/span><span style=\"color: #81A1C1\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">Require<\/span><span style=\"color: #D8DEE9FF\"> all denied<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">&lt;\/<\/span><span style=\"color: #D8DEE9FF\">FilesMatch<\/span><span style=\"color: #81A1C1\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">&lt;\/<\/span><span style=\"color: #D8DEE9FF\">Directory<\/span><span style=\"color: #81A1C1\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>To accomplish this just follow these steps:<\/p>\n\n\n\n<p><strong>Step 1:<\/strong> <strong>Locate the Apache Configuration File<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Typically, the main configuration file is named <code>httpd.conf<\/code> or <code>apache2.conf<\/code>, depending on your system.<\/li>\n\n\n\n<li>For virtual hosts, you may also need to edit site-specific files, often located in <code>\/etc\/apache2\/sites-available\/<\/code>.<\/li>\n<\/ul>\n\n\n\n<p><strong>Step 2:<\/strong> <strong>Use the <\/strong><code>&lt;Directory><\/code><strong> Directive<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>&lt;Directory><\/code> directive allows you to specify rules for a particular directory.<\/li>\n\n\n\n<li>The use the above implementation.<\/li>\n\n\n\n<li>Replace <code>\/path\/to\/your\/directory<\/code> with the actual path to the directory.<\/li>\n\n\n\n<li>The <code>FilesMatch<\/code> directive uses a regular expression to match specific file types (in this case, <code>.txt<\/code>, <code>.xml<\/code>, and <code>.json<\/code>).<\/li>\n<\/ul>\n\n\n\n<p><strong>Step 3:<\/strong> After making these changes remember to restart the Apache server as mentioned in the previous section.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">IIS<\/h4>\n\n\n\n<p>As incredible as might sound, this is also very simple to accomplish in Microsoft Internet Information Systems (IIS). In this case, IIS uses the XML language to accomplish similar implementations as Apache, but instead of <code>.htaccess<\/code> files you will use <code>web.config<\/code> files.<\/p>\n\n\n\n<p>To block access to specific file types in IIS using a <code>web.config<\/code> file, you can use the <code>requestFiltering<\/code> feature. Here&#8217;s an example configuration:<\/p>\n\n\n\n<p><strong>Step 1:<\/strong> <strong>Create or Edit the <\/strong><code>web.config<\/code><strong> File<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Place the <code>web.config<\/code> file in the directory where you want to block access to specific file types.<\/li>\n<\/ul>\n\n\n\n<p><strong>Step 2:<\/strong> <strong>Add the Following Configuration<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;configuration&gt;\n    &lt;system.webServer&gt;\n        &lt;security&gt;\n            &lt;requestFiltering&gt;\n                &lt;fileExtensions&gt;\n                    &lt;add fileExtension=&quot;.txt&quot; allowed=&quot;false&quot; \/&gt;\n                    &lt;add fileExtension=&quot;.xml&quot; allowed=&quot;false&quot; \/&gt;\n                    &lt;add fileExtension=&quot;.json&quot; allowed=&quot;false&quot; \/&gt;\n                &lt;\/fileExtensions&gt;\n            &lt;\/requestFiltering&gt;\n        &lt;\/security&gt;\n    &lt;\/system.webServer&gt;\n&lt;\/configuration&gt;\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">&lt;configuration&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">&lt;system.webServer&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">&lt;security&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #81A1C1\">&lt;requestFiltering&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                <\/span><span style=\"color: #81A1C1\">&lt;fileExtensions&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                    <\/span><span style=\"color: #81A1C1\">&lt;add<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">fileExtension<\/span><span style=\"color: #D8DEE9FF\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">.txt<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">allowed<\/span><span style=\"color: #D8DEE9FF\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">false<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                    <\/span><span style=\"color: #81A1C1\">&lt;add<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">fileExtension<\/span><span style=\"color: #D8DEE9FF\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">.xml<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">allowed<\/span><span style=\"color: #D8DEE9FF\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">false<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                    <\/span><span style=\"color: #81A1C1\">&lt;add<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">fileExtension<\/span><span style=\"color: #D8DEE9FF\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">.json<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #8FBCBB\">allowed<\/span><span style=\"color: #D8DEE9FF\">=<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">false<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">                <\/span><span style=\"color: #81A1C1\">&lt;\/fileExtensions&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">            <\/span><span style=\"color: #81A1C1\">&lt;\/requestFiltering&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">        <\/span><span style=\"color: #81A1C1\">&lt;\/security&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">    <\/span><span style=\"color: #81A1C1\">&lt;\/system.webServer&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">&lt;\/configuration&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This configuration blocks <code>.txt<\/code>, <code>.xml<\/code>, and <code>.json<\/code> files from being served by IIS.<\/li>\n<\/ul>\n\n\n\n<p><strong>Step 3:<\/strong> Restart IIS, this might be necessary if you still have access to the files directly.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"iisreset\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D8DEE9FF\">iisreset<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>Securing specific files is straightforward and requires minimal effort, provided you have access to your site configuration files. However, if you do not have access, as is the case with many hosting companies, you will need to contact your hosting provider and request these changes to be implemented, particularly for Nginx web servers.<\/p>\n\n\n\n<p>Unlike Apache\u2019s <code>.htaccess<\/code> and IIS\u2019s <code>web.config<\/code>, Nginx does not have an equivalent file for per-directory configurations. Instead, all configurations are managed centrally in the main Nginx configuration file or its included files (e.g., <code>\/etc\/nginx\/nginx.conf<\/code> or <code>\/etc\/nginx\/sites-available\/<\/code>).<\/p>\n\n\n\n<p>This centralized design is intentional, as it enhances performance by avoiding the need to repeatedly check for configuration files in each directory. To achieve functionality similar to <code>.htaccess<\/code> or <code>web.config<\/code>, you can configure specific settings using <code>location<\/code> blocks in the Nginx configuration file.<\/p>\n\n\n\n<p>Well, I hope this help some of you out there&#8230; Happy Coding, Happy Designing.<\/p>\n\n\n\n<p>This is Designer&#8217;s Gate login out. Be blessed by Yah!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a developer, there are certain files you do not want to expose via HTTP access protocols, particularly configuration files or a custom serverless database type using XML or JSON files. To prevent access, you can simply block access to those files or even a sub-directory. Is very simple, but this depends on what webserver [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3032,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[7],"tags":[38,75,267,45,266,6,268],"class_list":["post-3031","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-apache","tag-coding","tag-iis","tag-internet","tag-ngnix","tag-tutorial","tag-web-config"],"acf":[],"jetpack_featured_media_url":"https:\/\/designersgate.com\/blog\/wp-content\/uploads\/2025\/03\/a-funny-image-of-a-young-developer-typing-looking-at-the-screen-of-his-laptop-very-intently-hard-at-work-typing.-photo-realistic.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/posts\/3031","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/comments?post=3031"}],"version-history":[{"count":1,"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/posts\/3031\/revisions"}],"predecessor-version":[{"id":3033,"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/posts\/3031\/revisions\/3033"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/media\/3032"}],"wp:attachment":[{"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/media?parent=3031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/categories?post=3031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/tags?post=3031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}