Forum: NGINX Nginx Drupal Rewrite

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Claude B. (Guest)
on 2009-05-16 20:17
(Received via mailing list)
Ok, I followed a tutorial online and was trying to get rewrite working
on my
server.  Well, everything works ok except for my Photo gallery which is
located in | <domain>/gallery |.  I'll include my current config for the
domain (wfto.cc and wfto.cc/gallery)
========================
server {
        listen 80;
        server_name www.waterfortheoppressed.com
waterfortheoppressed.com;

        rewrite ^ http://wfto.cc permanent;
}

server {
        listen   80;
        server_name www.wfto.cc  wfto.cc;


        access_log  /var/www/logs/wfto.cc.access.log;

        location = / {
                root   /var/www/wfto.cc;
                index  index.php index.html index.htm;
        }
        location / {
            root   /var/www/wfto.cc;
            index  index.php index.html;

            if (!-f $request_filename) {
                rewrite  ^(.*)$  /index.php?q=$1  last;
                break;
            }

            if (!-d $request_filename) {
                rewrite  ^(.*)$  /index.php?q=$1  last;
                break;
            }
        error_page  404  /index.php;

        # serve static files directly
        location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
              access_log        off;
            expires           30d;
        }
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                root   /var/www/nginx-default;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
                #proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on
127.0.0.1:9000
        #
        location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME
/var/www/wfto.cc$fastcgi_script_name;
                include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny  all;
        }
}
}
========================

Claude

--

Laurence J.
Peter<http://www.brainyquote.com/quotes/authors/l/lauren...
- "Originality is the fine art of remembering what you hear but
forgetting
where you heard it."
Michael S. (Guest)
on 2009-05-16 20:23
(Received via mailing list)
We've got drupal going with a simple try_files $uri $uri/ /path/to/
drupal/index.php?q=$uri&$args;

In nginx 0.7 of course.
Igor S. (Guest)
on 2009-05-16 20:59
(Received via mailing list)
On Sat, May 16, 2009 at 09:15:20AM -0700, Michael S. wrote:

> We've got drupal going with a simple try_files $uri $uri/ /path/to/
> drupal/index.php?q=$uri&$args;
>
> In nginx 0.7 of course.

0.6.36 too.
Igor S. (Guest)
on 2009-05-16 21:01
(Received via mailing list)
On Sat, May 16, 2009 at 06:09:41PM +0200, Claude B. wrote:

> }
>                 index  index.php index.html index.htm;
>             if (!-d $request_filename) {
>                 rewrite  ^(.*)$  /index.php?q=$1  last;
>                 break;
>             }

+         }

>         location = /50x.html {
>         #
>         #
>         location ~ /\.ht {
>                 deny  all;
>         }
> }

- }

> }
> ========================

First, you should fix '}',
Second, use try_files instead of "if"s.
And third, your gallery probably is served as static files by

         location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
Claude B. (Guest)
on 2009-05-16 21:11
(Received via mailing list)
Well I should clarify about the gallery.  It's Gallery2, php-driven.

Where is the } that I should fix?

2009/5/16 Igor S. <removed_email_address@domain.invalid>

> >         server_name www.waterfortheoppressed.com
> >         access_log  /var/www/logs/wfto.cc.access.log;
> >                 rewrite  ^(.*)$  /index.php?q=$1  last;
> >         error_page  404  /index.php;
> >                 root   /var/www/nginx-default;
> >         #
> >         #
> First, you should fix '}',
>
--

Yogi Berra <http://www.brainyquote.com/quotes/authors/y/yogi_b...
-
"If you ask me anything I don't know, I'm not going to answer."
Igor S. (Guest)
on 2009-05-16 21:19
(Received via mailing list)
On Sat, May 16, 2009 at 07:04:43PM +0200, Claude B. wrote:

> Well I should clarify about the gallery.  It's Gallery2, php-driven.

How does typical URL look ?

> Where is the } that I should fix?

I have marked the by "+" and "-":

+        }

         error_page  404  /index.php;

         location ~ /\.ht {
              deny  all;
         }
-}
 }
Claude B. (Guest)
on 2009-05-16 21:23
(Received via mailing list)
K i will attempt to do this in a few minutes.  I'll get back to you
about
the gallery

2009/5/16 Igor S. <removed_email_address@domain.invalid>

> +        }
> >
> > > > ========================
> > > >         server_name www.wfto.cc  wfto.cc;
> > > >             index  index.php index.html;
> > >
> > > >         #
> > > >
> > > >
> > > > }
> > > Igor S.
>
> --
> Игорь Сысоев
> http://sysoev.ru
>
>


--

Bill Cosby <http://www.brainyquote.com/quotes/authors/b/bill_c...
-
"Fatherhood is pretending the present you love most is soap-on-a-rope."
Claude B. (Guest)
on 2009-05-16 22:07
(Received via mailing list)
Can I just exclude a directory from rewrite?

I suppose I can move the gallery to a subdomain.

2009/5/16 Claude B. <removed_email_address@domain.invalid>

>> How does typical URL look ?
>>              deny  all;
>> > > my
>> > > >
>> > > >         location = / {
>> > > >             }
>> > > >         # serve static files directly
>> > > >
>> > > >                 fastcgi_pass   127.0.0.1:9000;
>> > > >                 deny  all;
>> > > And third, your gallery probably is served as static files by
>> >
>>
>
>
> --
>
> Bill Cosby <http://www.brainyquote.com/quotes/authors/b/bill_c... - "Fatherhood 
is pretending the present you love most is soap-on-a-rope."




--

Yogi Berra <http://www.brainyquote.com/quotes/authors/y/yogi_b...
-
"If you ask me anything I don't know, I'm not going to answer."
AMP Admin (Guest)
on 2009-05-16 22:20
(Received via mailing list)
I'm getting the "No input file specified." But only when there's no
trailing
slash or file specified.

This works:
http://www.example.com/dir/index.php
http://www.example.com/dir/

This does not work:
http://www.example.com/dir

Any ideas?
Igor S. (Guest)
on 2009-05-16 22:22
(Received via mailing list)
On Sat, May 16, 2009 at 07:58:21PM +0200, Claude B. wrote:

> Can I just exclude a directory from rewrite?
> I suppose I can move the gallery to a subdomain.

You do not need rewrite at all:

    root   /var/www/wfto.cc;
    index  index.php index.html;

    location / {
        try_files  $uri  $uri/  /index.php?q=$uri;
    }

    location /gallery/ {
        try_files  $uri  $uri/  /index.php?q=$uri;
    }

    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        ...
    }
Claude B. (Guest)
on 2009-05-16 22:25
(Received via mailing list)
Post your config file, specifically the section where you declare your
php
handler

On Sat, May 16, 2009 at 8:16 PM, AMP Admin 
<removed_email_address@domain.invalid> wrote:

>
> Any ideas?
>
>
>


--

Laurence J.
Peter<http://www.brainyquote.com/quotes/authors/l/lauren...
- "Originality is the fine art of remembering what you hear but
forgetting
where you heard it."
Claude B. (Guest)
on 2009-05-16 22:26
(Received via mailing list)
It says to me when I use try_files  "Unknown directive: 'try_files'" and
I
don't know how to check the version number of nginx

2009/5/16 Igor S. <removed_email_address@domain.invalid>

>    location / {
>     location ~ \.php$ {
> > >
> > >> I have marked the by "+" and "-":
> > >>
> > >> > > > located in | <domain>/gallery |.  I'll include my current config
> > >> > > > }
> > >> > > >                 index  index.php index.html index.htm;
> > >> > > >             if (!-d $request_filename) {
> > >> > > >               access_log        off;
> > >> > > >         # proxy the PHP scripts to Apache listening on
> > >> > > >                 fastcgi_pass   127.0.0.1:9000;
> > >> > > >         location ~ /\.ht {
> > >> > > Second, use try_files instead of "if"s.
> > >> >
> > >> http://sysoev.ru
> >
> http://sysoev.ru/en/
>
>


--

Casey
Stengel<http://www.brainyquote.com/quotes/authors/c/casey_...
- "There comes a time in every man's life, and I've had plenty of
them."
Igor S. (Guest)
on 2009-05-16 22:37
(Received via mailing list)
On Sat, May 16, 2009 at 01:16:01PM -0500, AMP Admin wrote:

> Any ideas?
Could you show configuration ?
Igor S. (Guest)
on 2009-05-16 22:37
(Received via mailing list)
On Sat, May 16, 2009 at 08:19:50PM +0200, Claude B. wrote:

> It says to me when I use try_files  "Unknown directive: 'try_files'" and I
> don't know how to check the version number of nginx

nginx -v
Claude B. (Guest)
on 2009-05-16 22:42
(Received via mailing list)
*nginx version: nginx/0.6.32
*

2009/5/16 Igor S. <removed_email_address@domain.invalid>

> > > On Sat, May 16, 2009 at 07:58:21PM +0200, Claude B. wrote:
> > >        try_files  $uri  $uri/  /index.php?q=$uri;
> > >        fastcgi_pass   127.0.0.1:9000;
> > > > > 2009/5/16 Igor S. <removed_email_address@domain.invalid>
> > > > >> I have marked the by "+" and "-":
> > > > >>
> > > which
> > > > >> > > waterfortheoppressed.com;
> > > > >> > > >
> > > > >> > > >                 break;
> > > > >> > > >
> > > > >> > > >                 root   /var/www/nginx-default;
> on
> > > > >> > > >         # deny access to .htaccess files, if Apache's
> > > > >> > >
> > > > >> > > --
> > > > >>  -
> > > > >
> > > > Yogi Berra <
> >
>
>


--

Yogi Berra <http://www.brainyquote.com/quotes/authors/y/yogi_b...
-
"If you ask me anything I don't know, I'm not going to answer."
Igor S. (Guest)
on 2009-05-16 22:52
(Received via mailing list)
On Sat, May 16, 2009 at 08:35:25PM +0200, Claude B. wrote:

> *nginx version: nginx/0.6.32
> *

You may upgrade to 0.6.36 or use

   location / {
       error_page  404 = /index.php?q=$uri;
       log_not_found  off;
   }

on 0.6.32 instead of

   location / {
       try_files  $uri  $uri/  /index.php?q=$uri;
   }
Claude B. (Guest)
on 2009-05-16 23:02
(Received via mailing list)
And how would I go about replacing my current version with the newest
one?
I'm running Debian Lenny, so I just used apt-get install nginx (which I
know
would yield a slightly older version, but it was much easier at the
time).
Would I just download, compile, and install the source over the current
one?

2009/5/16 Igor S. <removed_email_address@domain.invalid>

>   }
> > >
> > > > >
> > > > >    }
> > > > >         ...
> > > > > > > 2009/5/16 Igor S. <removed_email_address@domain.invalid>
> > > > > > >> I have marked the by "+" and "-":
> > > > > > >>
> > > gallery
> > > > > > >> > > >         listen 80;
> > > > > > >> > > >
> > > > > > >> > > >             if (!-f $request_filename) {
> > > > > > >> > >
> > > > > > >> > > >         error_page   500 502 503 504  /50x.html;
> > > > > > >> > > >
> > > > > > >> > > >                 include        fastcgi_params;
> > > > > > >> > > > }
> > > > > > >> > >
> > > > > > >> > --
> > > > > > >>
> > > > > >
> > > > > Igor S.
> > > > them."
> > Yogi Berra <http://www.brainyquote.com/quotes/authors/y/yogi_b...
>  -
> > "If you ask me anything I don't know, I'm not going to answer."
>
> --
> Igor S.
> http://sysoev.ru/en/
>
>


--

Laurence J.
Peter<http://www.brainyquote.com/quotes/authors/l/lauren...
- "Originality is the fine art of remembering what you hear but
forgetting
where you heard it."
Igor S. (Guest)
on 2009-05-16 23:23
(Received via mailing list)
On Sat, May 16, 2009 at 08:54:02PM +0200, Claude B. wrote:

> And how would I go about replacing my current version with the newest one?
> I'm running Debian Lenny, so I just used apt-get install nginx (which I know
> would yield a slightly older version, but it was much easier at the time).
> Would I just download, compile, and install the source over the current one?

You may build nginx without package manager, but note, that default
nginx installation paths differ from Debian ones: you should use
something
like this:

./configure --prefix=/usr --with-conf-path=/etc/nginx/nginx.conf ...
etc.
Claude B. (Guest)
on 2009-05-16 23:26
(Received via mailing list)
Ok.  Until I get this working, I'm re-enabling apache2 (sigh).  I will
work
on this asap.

2009/5/16 Igor S. <removed_email_address@domain.invalid>

>
> > > > *nginx version: nginx/0.6.32
> > >
> > > and
> > > > > > > > I suppose I can move the gallery to a subdomain.
> > > > > > >    location /gallery/ {
> > > > > > >
> > > > > > > > >
> > > > > > > > >> I have marked the by "+" and "-":
> > > > > > > > >>
> > > > > > > > >> > > > server.  Well, everything works ok except for my
> > > > > > > > >> > > > ========================
> > > > > > > > >> > > >         server_name www.wfto.cc  wfto.cc;
> > > > > > > > >> > > >         location / {
> > > > > > > > >> > > >                 rewrite  ^(.*)$  /index.php?q=$1
> ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
> > > > > > > > >> > > >         }
> > > listening
> > > > > > > > >> > > >
> > > > > > > > >> > >
> > > > > > > > >> > >
> > > > > > > > >> >
> > > > > > > > >> http://sysoev.ru
> > > > > > > >
> > > > > > >
> > > > > http://www.brainyquote.com/quotes/authors/c/casey_...
> > > > --
> > >
> --
> Igor S.
> http://sysoev.ru/en/
>
>


--

Bill Cosby <http://www.brainyquote.com/quotes/authors/b/bill_c...
-
"Fatherhood is pretending the present you love most is soap-on-a-rope."
Igor S. (Guest)
on 2009-05-16 23:57
(Received via mailing list)
On Sat, May 16, 2009 at 09:20:31PM +0200, Claude B. wrote:

> Ok.  Until I get this working, I'm re-enabling apache2 (sigh).  I will work
> on this asap.

You may stay with 0.6.32 using

   location / {
       error_page  404 = /index.php?q=$uri;
       log_not_found  off;
   }
Michael S. (Guest)
on 2009-05-17 00:58
(Received via mailing list)
I will say I did notice the behavior for Drupal and possibly other
apps that require GET parameters. I've noted it in a blog post:

http://michaelshadle.com/2009/05/15/dont-forget-the-args/

2009/5/16 Igor S. <removed_email_address@domain.invalid>:
Igor S. (Guest)
on 2009-05-17 10:01
(Received via mailing list)
On Sat, May 16, 2009 at 01:46:06PM -0700, Michael S. wrote:

> I will say I did notice the behavior for Drupal and possibly other
> apps that require GET parameters. I've noted it in a blog post:
>
> http://michaelshadle.com/2009/05/15/dont-forget-the-args/

Does Drupal understand

try_files $uri $uri/ /foo/index.php?u=$irequest_uri;

instead of

try_files $uri $uri/ /foo/index.php?u=$uri&$args;

?
Igor S. (Guest)
on 2009-05-17 10:03
(Received via mailing list)
On Sun, May 17, 2009 at 09:47:32AM +0400, Igor S. wrote:

> On Sat, May 16, 2009 at 01:46:06PM -0700, Michael S. wrote:
>
> > I will say I did notice the behavior for Drupal and possibly other
> > apps that require GET parameters. I've noted it in a blog post:
> >
> > http://michaelshadle.com/2009/05/15/dont-forget-the-args/
>
> Does Drupal understand
>
> try_files $uri $uri/ /foo/index.php?u=$irequest_uri;

- try_files $uri $uri/ /foo/index.php?u=$irequest_uri;
+ try_files $uri $uri/ /foo/index.php?u=$request_uri;
Hendry Lee (Guest)
on 2009-05-17 11:51
(Received via mailing list)
> - try_files $uri $uri/ /foo/index.php?u=$irequest_uri;
> + try_files $uri $uri/ /foo/index.php?u=$request_uri;

This doesn't work. With q or u variables. I tried it on an installation
of
Drupal with clean url. The request failed during an AJAX request.

index.php?q=$uri&$args works though.

Notice it's 'q=' not 'u='

-Hendry
AMP Admin (Guest)
on 2009-05-17 15:41
(Received via mailing list)
I figured it out.  It was the way index was specified.
AMP Admin (Guest)
on 2009-05-19 21:08
(Received via mailing list)
I'm on 0.6.35... is this the suggested version to be running?
Cliff W. (Guest)
on 2009-05-19 21:12
(Received via mailing list)
On Tue, 2009-05-19 at 12:00 -0500, AMP Admin wrote:
> I'm on 0.6.35... is this the suggested version to be running?

Depends on who you ask.   Some prefer the stable series, others (like
me) prefer the development branch.

Cliff
Michael S. (Guest)
on 2009-05-19 21:25
(Received via mailing list)
+! for 0.7.x

been running it since i started, no complaints.
Kon W. (Guest)
on 2009-05-19 22:13
(Received via mailing list)
No problems here either, and I've been upgrading all our production
servers to the 0.7.x versions. Of course, I wait a few days and watch
the mailing list for any bugreports :)
Igor S. (Guest)
on 2009-05-20 12:59
(Received via mailing list)
On Tue, May 19, 2009 at 12:00:52PM -0500, AMP Admin wrote:

> I'm on 0.6.35... is this the suggested version to be running?

I'm going to branch 0.8 development version and mark 0.7 as stable on
this or the next week.
Jim O. (Guest)
on 2009-05-20 15:18
(Received via mailing list)
The "development" branch has more frequent changes, hence it's referred
to as such.

The "stable" branch has fewer version releases, hence it is referred to
as such.

New features are added to the development branch, and sometimes ported
to the stable branch, sometimes not.

There are many large sites running the development branch, and quite a
few running the stable branch, and still a fair number running a legacy
version (0.5.x or perhaps earlier).

There are bugs in all of them (probably), as bug fixes are often part of
new releases in both the stable and development branches.

I always run the latest development release on the forum, currently
0.7.58.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,2197,2202#msg-2202
Igor S. (Guest)
on 2009-05-20 16:40
(Received via mailing list)
On Sun, May 17, 2009 at 02:43:08PM +0700, Hendry Lee wrote:

> > - try_files $uri $uri/ /foo/index.php?u=$irequest_uri;
> > + try_files $uri $uri/ /foo/index.php?u=$request_uri;
>
> This doesn't work. With q or u variables. I tried it on an installation of
> Drupal with clean url. The request failed during an AJAX request.
>
> index.php?q=$uri&$args works though.
>
> Notice it's 'q=' not 'u='

So, just to make clear: this

 try_files $uri $uri/ /foo/index.php?q=$request_uri;

does not work, but this

 try_files $uri $uri/ /foo/index.php?q=$uri&$args;

works.

How does Drupal go with zero $args ? I.e., /foo/index.php?$uri& ?
Hendry Lee (Guest)
on 2009-05-20 17:33
(Received via mailing list)
> So, just to make clear: this
>
>  try_files $uri $uri/ /foo/index.php?q=$request_uri;
>
> does not work, but this
>
>  try_files $uri $uri/ /foo/index.php?q=$uri&$args;
>
> works.

Correct.

> How does Drupal go with zero $args ? I.e., /foo/index.php?$uri& ?

Failed too, as reported by someone earlier. $args is crucial in
try_files
for Drupal to work. This is a sample of url that generated an error.

Http://example.com/request/ajax/handle?operation=v...
%2Fgoogle.com%2F

When the PHP code checked the 'operation' variable, as in

if ($_REQUEST['operation']), it returned false.

With try_files $uri $uri/ /foo/index.php?q=$request_uri; it acts exactly
like my previous rewrite line.

if (!-e $request_filename) {
  rewrite ^/(.*)$ /index.php?q=$1 last;
  break;
}
Igor S. (Guest)
on 2009-05-20 17:39
(Received via mailing list)
On Wed, May 20, 2009 at 08:22:09PM +0700, Hendry Lee wrote:

> Correct.
>
> > How does Drupal go with zero $args ? I.e., /foo/index.php?$uri& ?
>
> Failed too, as reported by someone earlier. $args is crucial in try_files
> for Drupal to work. This is a sample of url that generated an error.

No, I meant how does Drupal go with trailing "&", if an original request
has no query string at all, say

/some/page.html

will be //foo/index.php?q=/some/page.html&
Michael S. (Guest)
on 2009-05-20 20:50
(Received via mailing list)
2009/5/20 Igor S. <removed_email_address@domain.invalid>:

> No, I meant how does Drupal go with trailing "&", if an original request
> has no query string at all, say
>
> /some/page.html
>
> will be //foo/index.php?q=/some/page.html&

I think this assumes Drupal is running with friendly URLs enabled,
which are extensionless, and also, the PHP script will see that as a
single parameter still, just 'q'

Since the slug /some/page.html is 'q', the & will be ignored as it is
a standard query string.

I think WordPress might do it slightly differently in how it parses
the URI, which is why it worked without $args (at least it appeared to
for a long time for me) - Drupal apparently needs the args passed to
it, whereas WordPress probably grabs the URI from another source (and
actually you might be able to pass nothing to the index.php and it
handles it from PATH_INFO. I think.)
Hendry Lee (Guest)
on 2009-05-20 21:23
(Received via mailing list)
> No, I meant how does Drupal go with trailing "&", if an original request
> has no query string at all, say
>
> /some/page.html
>
> will be //foo/index.php?q=/some/page.html&
>

Tested that. Everything works fine. Just that I can't have parameters in
the
URL. For that I need to add $args.

Drupal clean url doesn't have extension, but I tried /submit, /node/1,
and
other longer urls, they all work fine.

-Hendry
Igor S. (Guest)
on 2009-05-20 21:31
(Received via mailing list)
On Wed, May 20, 2009 at 09:43:45AM -0700, Michael S. wrote:

> which are extensionless, and also, the PHP script will see that as a
> handles it from PATH_INFO. I think.)
Probably WordPress gets URI from REQUEST_URI.
Michael S. (Guest)
on 2009-05-20 23:06
(Received via mailing list)
2009/5/20 Igor S. <removed_email_address@domain.invalid>:

> Probably WordPress gets URI from REQUEST_URI.

Yeah, WordPress handles it a little bit better, and accepts multiple
styles of input and figures it out. Drupal is a bit more strict.

Both work fine with $args, but Drupal seems to require $args.
This topic is locked and can not be replied to.