# Block direct access to .inc files not working

**URL:** <https://www.ruby-forum.com/t/block-direct-access-to-inc-files-not-working/244100>\
**Category:** NGINX\
**Created:** [February 20, 2016, 10:07am UTC](https://www.ruby-forum.com/t/block-direct-access-to-inc-files-not-working/244100 "2016-02-20T10:07:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [February 20, 2016, 10:07am UTC](https://www.ruby-forum.com/t/block-direct-access-to-inc-files-not-working/244100/1 "2016-02-20T10:07:53Z")

</div>

I’ve a nginx server on CentOS with PHP setup.  
I’m trying to block direct access to .inc files

I’ve added the following to nginx.conf

```
  location ~ /\.inc
  {
    deny all;
  }

```

& restarted nginx.

But I still able to access .inc files like  
[https://mydomain](https://mydomain),com/includes/config.inc

Pls suggest what I may be missing or how else to fix this issue. I Need  
to  
block access to all .inc files.

Thanks  
Sans

Posted at Nginx Forum:

> **[Block direct access to .inc files not working](https://forum.nginx.org/read.php?2,264663,264663#msg-264663)**
>
> I've a nginx server on CentOS with PHP setup. I'm trying to block direct access to .inc files I've added the following to nginx.conf location ~ /\\.inc { deny all; } & restarted nginx. But I stil

---

<div class="post-metadata">

**Author:** ![rsclmumbai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3be4f8/32.png) [@rsclmumbai](https://www.ruby-forum.com/u/rsclmumbai)\
**Post date:** [February 20, 2016, 10:21am UTC](https://www.ruby-forum.com/t/block-direct-access-to-inc-files-not-working/244100/2 "2016-02-20T10:21:55Z")

</div>

Hello!

On 2/20/2016 4:07 PM, rsclmumbai wrote:

> I’ve a nginx server on CentOS with PHP setup.  
> I’m trying to block direct access to .inc files
> 
> I’ve added the following to nginx.conf
> 
> ```
> location ~ /\.inc
> {
> deny all;
> }
> 
> ```

Have you try :

location ~ .inc {  
deny all;  
}

---

<div class="post-metadata">

**Author:** ![rsclmumbai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3be4f8/32.png) [@rsclmumbai](https://www.ruby-forum.com/u/rsclmumbai)\
**Post date:** [February 21, 2016, 7:20am UTC](https://www.ruby-forum.com/t/block-direct-access-to-inc-files-not-working/244100/3 "2016-02-21T07:20:49Z")

</div>

@dewanggaba Perfect. That worked like a charm.  
Thanks!

Posted at Nginx Forum:

> **[Re: Block direct access to .inc files not working](https://forum.nginx.org/read.php?2,264663,264680#msg-264680)**
>
> I've a nginx server on CentOS with PHP setup. I'm trying to block direct access to .inc files I've added the following to nginx.conf location ~ /\\.inc { deny all; } & restarted nginx. But I stil

---

<div class="post-metadata">

**Author:** ![rsclmumbai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3be4f8/32.png) [@rsclmumbai](https://www.ruby-forum.com/u/rsclmumbai)\
**Post date:** [February 22, 2016, 2:53am UTC](https://www.ruby-forum.com/t/block-direct-access-to-inc-files-not-working/244100/4 "2016-02-22T02:53:13Z")

</div>

You should block access in php file.

For example:  
You define using defined ( ‘ACCESS’… in any file you want direct  
access  
and put the line below to every php files:  
defined ( ‘ACCESS’ ) or die ( ‘Restricted Access’ );

Posted at Nginx Forum:

> **[Re: Block direct access to .inc files not working](https://forum.nginx.org/read.php?2,264663,264694#msg-264694)**
>
> I've a nginx server on CentOS with PHP setup. I'm trying to block direct access to .inc files I've added the following to nginx.conf location ~ /\\.inc { deny all; } & restarted nginx. But I stil
