Forum: NGINX perl help

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.
Cada0e1ce6247850bf38269d43c58963?d=identicon&s=25 Kingsley Foreman (Guest)
on 2009-02-05 06:38
(Received via mailing list)
Hi guys,

I just need a quick hand with a rewrite rule im have issues with

i need to have a url like so
http://blah.com/text.php?bitstart=21000

i need to use the bitstart=21200
and using that to add the header
Content-Range: 21200
to a request before handing it of to a proxied site.

Of all things im having trouble getting bitstart=21200, in perl  to use
it.


Kingsley Foreman
Technical Leader Content Services / Content Services Group

=============================================
Internode Systems Pty Ltd

PO Box 284, Rundle Mall 5000
Level 5 150 Grenfell Street, Adelaide 5000
Phone:  +61 8 8228 2978
Fax:    +61 8 8235 6978
Web:    http://www.internode.on.net
        http://games.on.net
=============================================
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-02-05 08:33
(Received via mailing list)
On Thu, Feb 05, 2009 at 03:56:43PM +1030, Kingsley Foreman wrote:

> to a request before handing it of to a proxied site.
>
> Of all things im having trouble getting bitstart=21200, in perl  to use it.

If you use 0.7.x:

        proxy_set_header  Content-Range  $arg_bitstart;

Other way is defining perl variable handler:

http {

    perl_set  $content_range '
        sub {
            my $r = shift;
            my $a = $r->args;
            if ($a =~ /bitstart=(\d+)/) {
                return $1;
            }
            return "";
       }';

       ...

           proxy_set_header  Content-Range  $content_range;
Cada0e1ce6247850bf38269d43c58963?d=identicon&s=25 unknown (Guest)
on 2009-02-06 01:57
(Received via mailing list)
Great that mostly helped however


                        if ($arg_bitstart && $arg_bitstart != 0){
                                proxy_set_header  Content-Range
bytes=$arg_bitstart-;
                                proxy_set_header  Range
bytes=$arg_bitstart-;
                        }

I get this error

2009/02/06 11:12:38 [emerg] 31739#0: invalid condition "$arg_bitstart"
in
/etc/nginx/nginx.conf:111
2009/02/06 11:12:38 [emerg] 31739#0: the configuration file
/etc/nginx/nginx.conf test failed

Kingsley


--------------------------------------------------
From: "Igor Sysoev" <is@rambler-co.ru>
Sent: Thursday, February 05, 2009 5:50 PM
To: <nginx@sysoev.ru>
Subject: Re: perl help
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-02-06 11:32
(Received via mailing list)
On Fri, Feb 06, 2009 at 11:16:02AM +1030, kingsley@internode.com.au
wrote:

> I get this error
>
> 2009/02/06 11:12:38 [emerg] 31739#0: invalid condition "$arg_bitstart" in
> /etc/nginx/nginx.conf:111
> 2009/02/06 11:12:38 [emerg] 31739#0: the configuration file
> /etc/nginx/nginx.conf test failed

nginx curerently does not support "&&", etc inside "if".

However, in this case

       if ($arg_bitstart) {

is enough as both "" and "0" are false.
The more stronger test is:

       if ($arg_bitstart ~ [1-9]\d+) {
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-02-06 11:34
(Received via mailing list)
On Fri, Feb 06, 2009 at 01:12:50PM +0300, Igor Sysoev wrote:

> >                        }
> However, in this case
>
>        if ($arg_bitstart) {
>
> is enough as both "" and "0" are false.
> The more stronger test is:
>
>        if ($arg_bitstart ~ [1-9]\d+) {

-        if ($arg_bitstart ~ [1-9]\d+) {
+        if ($arg_bitstart ~ ^[1-9]\d+$) {
Cada0e1ce6247850bf38269d43c58963?d=identicon&s=25 Kingsley Foreman (Guest)
on 2009-02-06 12:20
(Received via mailing list)
getting there,

I have a new error now :)

2009/02/06 21:35:23 [emerg] 10444#0: "proxy_set_header" directive is not
allowed here in /etc/nginx/nginx.conf:112
2009/02/06 21:35:23 [emerg] 10444#0: the configuration file
/etc/nginx/nginx.conf test failed

however it works if the if statement isn't there.

Kingsley

--------------------------------------------------
From: "Igor Sysoev" <is@rambler-co.ru>
Sent: Friday, February 06, 2009 8:53 PM
To: <nginx@sysoev.ru>
Subject: Re: perl help
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-02-07 11:07
(Received via mailing list)
On Fri, Feb 06, 2009 at 09:36:41PM +1030, Kingsley Foreman wrote:

> getting there,
>
> I have a new error now :)
>
> 2009/02/06 21:35:23 [emerg] 10444#0: "proxy_set_header" directive is not
> allowed here in /etc/nginx/nginx.conf:112
> 2009/02/06 21:35:23 [emerg] 10444#0: the configuration file
> /etc/nginx/nginx.conf test failed
>
> however it works if the if statement isn't there.

Something like this:

       set  $range  $http_range;

       if ($arg_bitstart ~ ^[1-9]\d+$) {
           set   $range  $arg_bitstart;
       }

       proxy_pass  ...;

       proxy_set_header  Content-Range  $range;
       proxy_set_header  Range          $range;
This topic is locked and can not be replied to.