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
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
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
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
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
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?
The Boise Drupal Guy!
Hello Garret
mapneeds to be defined at the http level, not server level.Okay, and what about the
Okay, and what about the
location $drupal_dirbit? Where should that go? I'm trying replacing thelocation /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…
The Boise Drupal Guy!
For example, You wanna using
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
the FCGI parameter needs to be changed. So in
fastcgi_drupal.confwe 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
Thanks, but my previous question still stands. Where does the
location: $drupal_dirbit go? plz email me teh codez.The Boise Drupal Guy!
Almost six months late.
Here it is:
https://gist.github.com/perusio/9033447
and
https://gist.github.com/perusio/9033590
Still not working for me. =/
Still not working for me. =/ I have a better idea of what you were trying to tell me now, though. Thanks.
The
mapdirective needs to go inside thehttpblock, right? I put it right at the top.The Boise Drupal Guy!
Yep
mapis an http level directive.What errors are you getting? Share a debug log please.
No Nginx errors. Just 404s or
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.
The Boise Drupal Guy!
Not QUERY_STRING
Changing QUERY_STRING didn't work. I had to change:
to get it to work. Is there a reason SCRIPT_FILENAME is hard-coded in your config?
Hi, I think you can do it
Hi,
I think you can do it good with my code above, this is standard for rewrite using location.
Unnecessary rewrites
in your code.
I got it working
In Perusio config, you need to hack fastcgi_drupal.conf.
Say, for instance your Drupal instance lives in /blog:
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; }