Forum: NGINX JSON REST APIs

133011e084462c29c4799fe369d03cec?d=identicon&s=25 Myla John-B22173 (Guest)
on 2013-09-25 02:40
(Received via mailing list)
Hi,

Are there any JSON APIs defined for Nginx Configuration?

Regards,
John
F00aecf79824e260b82897e9f65fd2dd?d=identicon&s=25 Shaun Savage (Guest)
on 2013-09-27 13:22
(Received via mailing list)
I have many "virtual" paths on one nginx server.  What I mean by this is
there can be many top level paths, where each one has a cookie, static
files, and a upstream server.   The way I am doing it now is just
duplicate every path.

Is there a way to do this 'faster' 'less writing'  'better'?  I am
expecting 1000's of entries.


upstream a1 {
#    server localhost:48000;
     unix:/tmp/a1
}
upstream a2 {
     server localhost:48001;
#    unix:/tmp/a2
}
upstream a3 {
#    server localhost:48002;
     unix:/tmp/a3
}

location /a1/exe {   # to upstream if have cookie
     if ($http_cookie !~* 'a1') {
         rewrite ^a1(.*)$ /login?a1=$1;
     }
     proxy_....   #setup
     proxy_pass http://a1;
}

location /a1 { # static files
     if ($http_cookie !~* 'a1') {
         rewrite ^a1(.*)$ /login?a1=$1;
     }
     alias /var/www/a1
}

location /a2/exe {  # to upstream if have cookie
     if ($http_cookie !~* 'a2') {
         rewrite ^a2(.*)$ /login?a2=$1;
     }
     proxy_....   #setup
     proxy_pass http://a2;
}

location /a2 {  #static files
     if ($http_cookie !~* 'a2') {
         rewrite ^a2(.*)$ /login?a2=$1;
     }
     alias /var/www/a2
}

.......
IDEA
*************
not correct!!
location / {
     parse url
     check cookie
     if $2 == 'exe' {
         proxy_pass
     }
     alias /var/www/$2  OR rewrite /var/www/$2
}
36a8284995fa0fb82e6aa2bede32adac?d=identicon&s=25 Francis Daly (Guest)
on 2013-09-27 19:35
(Received via mailing list)
On Fri, Sep 27, 2013 at 04:22:25AM -0700, Shaun Savage wrote:

Hi there,

None of what follows is tested by me. So double-check before committing
to anything :-)

> I have many "virtual" paths on one nginx server.  What I mean by this is
> there can be many top level paths, where each one has a cookie, static
> files, and a upstream server.   The way I am doing it now is just
> duplicate every path.
>
> Is there a way to do this 'faster' 'less writing'  'better'?  I am
> expecting 1000's of entries.

Faster for you to write, or faster for nginx to read and process?

Less writing for you, or for your "turn this input file into an
nginx.conf" script?


It looks like you could either auto-generate the conf file, so that it
will be big; or keep it small by using a (probably, nested) "location"
with regex and named captures.

After you have both, you can test your workload on your hardware to see
if there is a significant benefit of one over the other to you.

Or you can just make one, and see if your workload on your hardware is
handled well enough, and stop if it is.

The examples here look like there is a regular pattern to them. Assuming
that holds for all, then a simple template / macro system that does
a string replacement should work -- you keep your "real config" as a
list of a1, a2, etc; then run the script to generate the fragment of
nginx.conf that can be pasted in or "include"d.

Or you could try something like

==
 location / {
  location ~ ^/(?<bit>[^/]*)/exe {
   # your "exe" stuff goes here, with $bit = a1 or a2
  }
  location ~ ^/(?<bit>[^/]*) {
   # your "static" stuff goes here, with $bit = a1 or a2
  }
 }
==

but even with that, you're likely to want to auto-generate the
"upstream"
sections externally to nginx anyway.

(You'll need other top-level location{} blocks for anything that should
not match the pattern you have shown, such as /login.)

All the "alias" lines you've shown look equivalent to a single "root
/var/www" at server-level -- that might simplify things, depending on
what else you plan to use the server for.

  f
--
Francis Daly        francis@daoine.org
F00aecf79824e260b82897e9f65fd2dd?d=identicon&s=25 shaun (Guest)
on 2013-09-30 09:19
(Received via mailing list)
Attachment: error.log (9 KB)
I am have a problem

I am very confused.  There is an extra "?" added to the end of the
rewrite. I have no idea why, I look at the logs, and is magically
appears.

I want to reload the login page, but nothing happens, any ideas?

         location /login/ {
                 if ($args) {
                         set $lin 1;
                         rewrite ^/login/login(.*)$ /auth$1;
                 }
                 alias /var/www/login/;

         }

         location /hzc/ws {
                 if ($http_cookie !~* 'hzc') {
                         rewrite ^/hzc(.*)$ /login/;
                 }
                 proxy_redirect off;
                 proxy_buffering off;
                 proxy_set_header        Host            $host;
                 proxy_set_header        X-Real-IP $remote_addr;
                 proxy_set_header        X-Real-Port $remote_port;
                 proxy_set_header        X-Forwarded-For
$proxy_add_x_forwarded_for;
                 proxy_set_header Upgrade $http_upgrade;
                 proxy_set_header Connection "upgrade";
                 proxy_http_version 1.1;
                 proxy_pass_request_headers on;
                 proxy_pass http://gofw;
         }
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2013-09-30 14:20
(Received via mailing list)
Hello!

On Mon, Sep 30, 2013 at 12:18:41AM -0700, shaun wrote:

> I am very confused.  There is an extra "?" added to the end of the
> rewrite. I have no idea why, I look at the logs, and is magically
> appears.

Could you please point out where is the "?" which confuses you?
Please note that in debug logs like

> 2013/09/29 23:42:00 [debug] 3386#0: *1 internal redirect: "/login/index.html?"

the "?" character is printed unconditionally as a separator
between r->uri and r->args.

> I want to reload the login page, but nothing happens, any ideas?

As per debug log you've provided, the "/var/www/login/index.html"
file is properly returned as configured.  Not sure what you want
nginx to do instead.

--
Maxim Dounin
http://nginx.org/en/donation.html
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.