perusio's config and Drupal in a subdirectory

Events happening in the community are now at Drupal community events on www.drupal.org.
Garrett Albright's picture

A bug was recently discovered in my module Pathologic that only materializes when Drupal is installed in a subdirectory under the web root - so in http://example.com/foo/ instead of just http://example.com/ . At various times since switching to Nginx, I've tried to figure out how to get perusio's config to play nice with Drupal installed this way so that I can test Pathologic with that sort of set-up, but can't recall ever having success. Has anyone else figured it out? Am I missing something simple?

Comments

The easiest way is to prefix

perusio's picture

the directory for the locations that start not by a regex.

E.g.

## This replaces the / location on the config.
location /drupal_dir {
     ## prefix all locations that start by a non-regex.
}

You can make it work for any dir with a map:
map $uri $drupal_dir {
    ~^(?<dir>/[^/]*)/ $dir;
}

Now use it like this:

location $drupal_dir {

## prefix all locations that start by a non-regex.
}

Is it clear?

I am also struggling on this

ronyclau's picture

I am also struggling on this problem.
I have been trying to use the "map" method but without success.

May you please comfirm that a variable can be used as a matching URI for a location block?
The debug log tells that the server don't even try to match with that particular location block, namely "location $drupal_dir { ... }".

Every request is catched by the "*.php" block instead, which returns 404:

2013/10/06 18:36:55 [debug] 7188#0: *2 test location: "/install.php"
2013/10/06 18:36:55 [debug] 7188#0: *2 test location: "/rss.xml"
2013/10/06 18:36:55 [debug] 7188#0: *2 test location: "/xmlrpc.php"
2013/10/06 18:36:55 [debug] 7188#0: *2 test location: "/update.php"
2013/10/06 18:36:55 [debug] 7188#0: *2 test location: "/sitemap.xml"
2013/10/06 18:36:55 [debug] 7188#0: *2 test location: ~ "^.+.php$"
2013/10/06 18:36:55 [debug] 7188#0: *2 using configuration "^.+.php$"

Thanks.

Nginx cannot use a variable in a location

tmcti's picture

It seems nginx never matches a variable in a location, so if you have:

$foo = 'bar'

location /$foo {
...
}

Theoretically that should match like writing: location /bar { ... }

But it doesn't! Turning on nginx error log in 'debug' mode shows it tries location /$foo { } .. but never uses it.

Try with my case or perusio

johntang's picture

Try with my case or perusio too :)

location /drupal_dir 
    {
        try_files $uri $uri/ @drupal_dir;
    }
    location @drupal_dir
    {
        rewrite ^/f(.+)$ /f/index.php?p=$1 last;
bla, bla, bla;
    }

Could both of you clarify

Garrett Albright's picture

Could both of you clarify which file I should modify for your respective approaches? perusio, I tried doing the map approach (since I'd rather not have to tweak config files and bounce the daemon every time I switch between a site using a prefix and one not) in apps/drupal/drupal.conf since that seemed like the most likely candidate, but I'm told "map" directive is not allowed here.

johntang, why rewrite instead of try_files? And can you remind me what the @ signifies?

Hello Garret

perusio's picture

map needs to be defined at the http level, not server level.

Okay, and what about the

Garrett Albright's picture

Okay, and what about the location $drupal_dir bit? Where should that go? I'm trying replacing the location / in drupal.conf with that, but it's not seeming to have the desired effect.

I'm trying to RTFM and GIFMyself, but your config generally exceeds in complexity any other examples or tutorials I can find out there…

For example, You wanna using

johntang's picture

For example, You wanna using other @forum that support nginx server (outside drupal), with the sub-folder is /forum:

#Server block.
server
{
location /forum
    {
        try_files $uri $uri/ @forum;
    }
    location @forum
    {
        rewrite ^/f(.+)$ /f/index.php?p=$1 last;
    }
}

Other example, this case to rewrite a url inside drupal site, we having the url is http://yousite.com/tagadelic_taxonomy and for now you want to write to http://yoursite.com/tags, just using

location /tags 
    {   
        rewrite ^/(.*)$ /tagadelic_taxonomy/$1 last;
    }

Hope help with your case.

Well I forgot to tell you that

perusio's picture

the FCGI parameter needs to be changed. So in fastcgi_drupal.conf we must set:


fastcgi_param QUERY_STRING q=$drupal_dir$uri&$args;

Right now only the home page will load. If that doesn't fix it then please paste a debug log somewhere so that I get a picture of what's going on.

Thanks, but my previous

Garrett Albright's picture

Thanks, but my previous question still stands. Where does the location: $drupal_dir bit go? plz email me teh codez.

Still not working for me. =/

Garrett Albright's picture

Still not working for me. =/ I have a better idea of what you were trying to tell me now, though. Thanks.

The map directive needs to go inside the http block, right? I put it right at the top.

Yep

perusio's picture

map is an http level directive.

What errors are you getting? Share a debug log please.

No Nginx errors. Just 404s or

Garrett Albright's picture

No Nginx errors. Just 404s or 500s when I try to actually access anything in a browser.

Maybe if we meet IRL at a con or something, I'll trade some of your time for a drink or something and you can try to beat this stuff through my thick skull. For now, I'll just go back to firing up MAMP when I need to test this.

Not QUERY_STRING

tmcti's picture

Changing QUERY_STRING didn't work. I had to change:

fastcgi_param SCRIPT_FILENAME $document_root/blog/index.php;

to get it to work. Is there a reason SCRIPT_FILENAME is hard-coded in your config?

Hi, I think you can do it

johntang's picture

Hi,

I think you can do it good with my code above, this is standard for rewrite using location.

try_files tries the literal path you specify in relation to the defined root directive and sets the internal file pointer.

Unnecessary rewrites

perusio's picture

in your code.

I got it working

tmcti's picture

In Perusio config, you need to hack fastcgi_drupal.conf.

Say, for instance your Drupal instance lives in /blog:

fastcgi_param QUERY_STRING &$args;
fastcgi_param SCRIPT_NAME /blog/index.php;
fastcgi_param SCRIPT_FILENAME $document_root/blog/index.php;

Do NOT use the map with $drupal_dir in it, or put in $drupal_dir in location stanzas.
IT WON'T WORK.

Instead, make sure you prepend the subdir everywhere that's needed. Here's a snippet of what the config looks like with /blog:

location /blog {
    location ^~ /blog/system/files/ {
        include conf/fastcgi_drupal_subdir.conf;
        fastcgi_pass phpcgi;
        log_not_found off;
    }

    location ^~ /blog/sites/default/files/private/ {
        internal;
    }

Nginx

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: