JSON REST APIs

Hi,

Are there any JSON APIs defined for Nginx Configuration?

Regards,
John

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
}

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 :slight_smile:

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 ~ ^/(?[^/]*)/exe {

your “exe” stuff goes here, with $bit = a1 or a2

}
location ~ ^/(?[^/]*) {

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 D. [email protected]

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;
}

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 D.
http://nginx.org/en/donation.html