# Need help configuring this location directive

**URL:** <https://www.ruby-forum.com/t/need-help-configuring-this-location-directive/218775>\
**Category:** NGINX\
**Created:** [April 11, 2012, 9:46pm UTC](https://www.ruby-forum.com/t/need-help-configuring-this-location-directive/218775 "2012-04-11T21:46:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gurdipe\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b77776/32.png) [@Gurdipe\_D](https://www.ruby-forum.com/u/Gurdipe_D)\
**Post date:** [April 11, 2012, 9:46pm UTC](https://www.ruby-forum.com/t/need-help-configuring-this-location-directive/218775/1 "2012-04-11T21:46:42Z")

</div>

I’ve been reading about how nginx matches requests - most specific to  
least, then regex in the order they are listed. For fastcgi, though, all  
of the tutorials suggest something like:

location ~ .php$ {  
try\_files $uri =404;  
include fastcgi\_params;  
fastcgi\_param SCRIPT\_FILENAME  
$document\_root$fastcgi\_script\_name;  
fastcgi\_pass yada yada;  
}

What if I want/need to run fastcgi from a location that nginx matches  
before this regex, though? Do I have to repeat the whole fastcgi config  
in that block, or is there a more elegant way?

For example:

```
root /srv/http/example.com
location = /favicon.ico {
    log_not_found off;
    access_log off;
}
# /~user/private w/basic auth
location ~ ^/~(.+?)/private(/.*)?$ {
    auth_basic "Restricted";
    auth_basic_user_file htpasswd;
    alias /home/$1/private_html$2;
    index index.html index.htm;
    autoindex on;
}
# /~user
location ~ ^/~(.+?)(/.*)?$ {
    alias /home/$1/public_html$2;
    index index.html index.htm;
    autoindex on;
}
# serve static files directly
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ {
    access_log off;
    expires 30d;
}
# I have no idea what this does
location ~ \..*/.*\.php$ {
    return 403;
}

```

# fastcgi

```
location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME

```

$document\_root$fastcgi\_script\_name;  
fastcgi\_pass phpcgi;  
}

So in the above example, what if I want to serve php from ~/user ?

Posted at Nginx Forum:

> **[need help configuring this location directive](https://forum.nginx.org/read.php?2,225187,225187#msg-225187)**
>
> I've been reading about how nginx matches requests - most specific to least, then regex in the order they are listed. For fastcgi, though, all of the tutorials suggest something like: location ~ \\.php$ { try\_files $uri =404; include fastcgi\_para
