# Location expression - PHP treated as binary file

**URL:** <https://www.ruby-forum.com/t/location-expression-php-treated-as-binary-file/223174>\
**Category:** NGINX\
**Created:** [September 25, 2012, 5:04am UTC](https://www.ruby-forum.com/t/location-expression-php-treated-as-binary-file/223174 "2012-09-25T05:04:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [September 25, 2012, 5:04am UTC](https://www.ruby-forum.com/t/location-expression-php-treated-as-binary-file/223174/1 "2012-09-25T05:04:29Z")

</div>

Hi,

Having following configuration, PHP files, if requested from /junk or  
/pub  
locations, are treated as binary. Sample request - [domain.com/pub/i.php](http://domain.com/pub/i.php)  
 →   
file is downloaded to PC instead of executing.

Have no problems serving PHP files from other locations. Having separate  
locations for /pub /junk with autoindex also works, however my intention  
is  
to combine them in one expression.

upstream www-default {  
server unix:/dev/shm/www-default.sock;  
}

server {  
listen 80;  
server\_name \_;  
index index.php index.html;  
fastcgi\_index index.php;  
root /data/www/default/htdocs;  
charset utf-8;  
access\_log /data/www/default/logs/frontend/access.log;  
error\_log /data/www/default/logs/frontend/error.log;  
client\_max\_body\_size 8m;

```
    location ~* \.(jpg|jpeg|gif|css|png|js|swf|ico)$ {
        expires max;
    }

    location / {
        try_files $uri $uri/ /index.html;
    }

    location ~ (/\.svn|/\.ht) {
        deny all;
    }

    location ~* ^/(pub/|junk/) {
        autoindex on;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass www-default;
        fastcgi_param SCRIPT_FILENAME

```

$document\_root$fastcgi\_script\_name;  
fastcgi\_param PATH\_INFO $fastcgi\_path\_info;  
include /etc/nginx/fastcgi\_params;  
}  
}

Posted at Nginx Forum:

> **[location expression - PHP treated as binary file](https://forum.nginx.org/read.php?2,231018,231018#msg-231018)**
>
> Hi, Having following configuration, PHP files, if requested from /junk or /pub locations, are treated as binary. Sample request - domain.com/pub/i.php -\> file is downloaded to PC instead of executing. Have no problems serving PHP files from other...

---

<div class="post-metadata">

**Author:** ![technoplague](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a9a28c/32.png) [@technoplague](https://www.ruby-forum.com/u/technoplague)\
**Post date:** [September 25, 2012, 5:25am UTC](https://www.ruby-forum.com/t/location-expression-php-treated-as-binary-file/223174/2 "2012-09-25T05:25:31Z")

</div>

On Tue, Sep 25, 2012 at 10:04 AM, technoplague [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,
> 
> Having following configuration, PHP files, if requested from /junk or /pub  
> locations, are treated as binary. Sample request - [domain.com/pub/i.php](http://domain.com/pub/i.php) →   
> file is downloaded to PC instead of executing.
> 
> Have no problems serving PHP files from other locations. Having separate  
> locations for /pub /junk with autoindex also works, however my intention is  
> to combine them in one expression.

That’s because when both locations are regexp, the first match is used  
while when it’s regexp and normal, regexp is used. Try moving the php  
block to the top.

Check this reference: [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpCoreModule#location)

(it would be nice if the order list is also copied to official docs.  
The current one which describes it in prose form is harder to read)

---

<div class="post-metadata">

**Author:** ![technoplague](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a9a28c/32.png) [@technoplague](https://www.ruby-forum.com/u/technoplague)\
**Post date:** [September 25, 2012, 6:03am UTC](https://www.ruby-forum.com/t/location-expression-php-treated-as-binary-file/223174/3 "2012-09-25T06:03:29Z")

</div>

Thanks! This seemed to do the trick

Posted at Nginx Forum:

> **[Re: location expression - PHP treated as binary file](https://forum.nginx.org/read.php?2,231018,231024#msg-231024)**
>
> Hi, Having following configuration, PHP files, if requested from /junk or /pub locations, are treated as binary. Sample request - domain.com/pub/i.php -\> file is downloaded to PC instead of executing. Have no problems serving PHP files from other...
