perusio's config and Drupal in a subdirectory

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by Garrett Albright on September 9, 2013 at 4:11am

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

Posted by perusio on September 10, 2013 at 9:50am

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

Posted by ronyclau on October 6, 2013 at 6:46pm

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

Posted by tmcti on September 24, 2015 at 3:13pm

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

Posted by johntang on September 14, 2013 at 8:54am

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

Posted by Garrett Albright on September 15, 2013 at 7:23am

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

Posted by perusio on September 16, 2013 at 12:07pm

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

Okay, and what about the

Posted by Garrett Albright on September 22, 2013 at 10:55pm

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

Posted by johntang on September 23, 2013 at 4:44am

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

Posted by perusio on September 23, 2013 at 8:27am

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

Posted by Garrett Albright on September 29, 2013 at 4:52pm

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. =/

Posted by Garrett Albright on February 20, 2014 at 10:07pm

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

Posted by perusio on February 21, 2014 at 1:26pm

map is an http level directive.

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

No Nginx errors. Just 404s or

Posted by Garrett Albright on February 24, 2014 at 4:29pm

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

Posted by tmcti on September 24, 2015 at 3:16pm

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

Posted by johntang on September 16, 2013 at 3:54am

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

Posted by perusio on September 23, 2013 at 8:29am

in your code.

I got it working

Posted by tmcti on September 25, 2015 at 2:50pm

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:

AltStyle によって変換されたページ (->オリジナル) /