Welcome! Log In Create A New Profile

Advanced

need help configuring this location directive

April 11, 2012 03:46PM
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 ?
Subject Author Posted

need help configuring this location directive

dfelicia April 11, 2012 03:46PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 116
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready