Alias which works like in other web servers
Igor Sysoev
is at rambler-co.ru
Sun Aug 5 11:26:20 MSD 2007
On Sun, Aug 05, 2007 at 05:55:39AM +0400, Maxim Dounin wrote:
> On Sat, 4 Aug 2007, marc at corky.net wrote:
>
> >I already had this working like this. But unfortunately every single
> >request, for any file (jpg, swf...etc) gets passed to fastcgi, too...
>
> The root of your problems is that nginx has no such thing as
> extension-based handlers. Only one location{} configuration matches any
> particular request, and everything needed to process the request must be
> specified in this location (or at higher level).
>
> If you wish to serve *.php through fastcgi backend and static content with
> same url prefix directly from nginx, you should write two locations for
> each such url prefix - one for static content, and one for *.php.
> Something like this:
>
> location /blog/wp-admin/ {
> alias /var/www/wordpress/wp-admin/;
> auth_basic ...
> }
> location ~ ^/blog/wp-admin/.*\.php$ {
> alias /var/www/wordpress/wp-admin/;
> auth_basic ...
>
> fastcgi_pass ...
> ...
> }
You could not use "alias" inside regex location, because nginx does not
what should be aliased. The workaround is to use "rewrite" inside such
locations.
BTW, nginx allows undocumented (because it's not supported by all directives)
inclusive locations:
location /blog/wp-admin/ {
alias /var/www/wordpress/wp-admin/;
auth_basic ...
location ~ \.php$ {
fastcgi_pass ...
...
}
}
Howerver, I'm not sure rigth now, how "alias" will work in inclusive
locations.
> NOTE1: Not really checked, test before using. You probably will need some
> more tweaks to catch .../ -> .../index.php mapping.
>
> NOTE2: Regex locations are tested in order, so please make sure you
> specified "location ~ ^/blog/wp-admin/.*\.php$" before "location ~
> ^/blog/.*\.php$" (and of course before "location ~ \.php$").
>
> NOTE3: This is not performance-optimal solution, since all regex locations
> will be checked for all non-matching requests (but better than passing
> them to backends, of course). To achive maximum performance you should
> separate static and dynamic content (to eliminate regex locations
> completely).
>
> To simplify things with multiple such locations you may use "include"
> directive (e.g. with fastcgi_* params).
>
> Maxim Dounin
>
> >
> >
> >
> >Igor Sysoev wrote:
> >>On Sat, Aug 04, 2007 at 10:21:11AM +0100, marc at corky.net wrote:
> >>
> >>
> >>>I need / to point to /var/www/site, /blog to /var/www/wordpress,
> >>>/nagios to /var/www/nagios, /munin to /var/www/munin the /munin,
> >>>/nagios and /blog/wp-admin dirs should be password protected using auth.
> >>>
> >>>All dirs except /munin and /nagios have PHP scripts in them that need to
> >>>be run.
> >>>
> >>
> >> location / {
> >> root /var/www/site;
> >>
> >> fastcgi_pass ...
> >> fastcgi_index index.php;
> >> fastcgi_param SCRIPT_NAME
> >> $document_root$fastcgi_script_name;
> >> ...
> >> }
> >>
> >> location /blog/ {
> >> alias /var/www/wordpress/;
> >>
> >> fastcgi_pass ...
> >> fastcgi_param SCRIPT_NAME $request_filename;
> >> ...
> >> }
> >>
> >> location /blog/wp-admin/ {
> >> alias /var/www/wordpress/wp-admin/;
> >>
> >> auth_basic "adm"; auth_basic_user_file conf/nginx.user;
> >>
> >> fastcgi_pass ...
> >> fastcgi_param SCRIPT_NAME $request_filename;
> >> ...
> >> }
> >>
> >> location /nagios/ {
> >> root /var/www;
> >>
> >> auth_basic "adm"; auth_basic_user_file conf/nginx.user;
> >> }
> >>
> >> location /munin/ {
> >> root /var/www;
> >>
> >> auth_basic "adm"; auth_basic_user_file conf/nginx.user;
> >> }
> >>
> >>
> >>
> >
> >
> >
>
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list