Forum: NGINX Configuration Primer

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.
852a62a28f1de229dc861ce903b07a60?d=identicon&s=25 Gavin Kistner (phrogz)
on 2009-02-20 07:19
(Received via mailing list)
Does there exist an english introduction to NginX config 'programming'?

I have found various example configurations, both simplistic and 'full
featured'.

I have found the list of modules on the wiki, and the command-centric
documentation they supply. (Though I wish even this were more in-
depth. For example, what is the regex syntax allowed for the rewrite
command? PCRE? Posix classes? Lookaheads/lookbehinds?)

What I'm missing is an overview of how configurations really work.
With the ability to set variables, scoping, break directives and
rewrite commands like last/break/redirect/permanent, it's more like a
programming language than a set of parameters. Various questions this
has raised in my mind regarding the sort of information I'm looking for:
What is the 'flow' of execution?
When you 'break', what scope/context are you stopping the directives in?
When all is said and done, what is being returned?
Can I chain multiple rewrites? Does a rewrite affect all kinds of
later matches (e.g. 'if' or 'location')?

While answers to the above specific questions would almost certainly
help me string a few islands of knowledge together, I'm hoping someone
knows of a guide already written. Something that starts at NginX
Config Theory 101 (not super-simple examples, but instead something
like stepping through the procedure of matching a request against a
config file from start to finish) and then covers things like Virtual
Hosts and Virtual Directories and so on.

Any chance it exists?
604e194b0b23280a5447a0f31c78ae0b?d=identicon&s=25 Dan Dascalescu (Guest)
on 2009-03-18 08:58
(Received via mailing list)
On Thu, Feb 19, 2009 at 23:09, Gavin Kistner <phrogz@mac.com> wrote:
> Does there exist an english introduction to NginX config 'programming'?

None, AFAIK. I had the same problem a few months ago when I switched
to nginx. I ended up learning by example, getting nginx to do what I
wanted, then forgetting about it.

This is probably the reason nobody wrote a clear, academic, intro to
nginx configuration.

Dan
56080a668b706e94fb2bbe9ee727d006?d=identicon&s=25 Reinis Rozitis (Guest)
on 2009-03-18 10:43
(Received via mailing list)
> On Thu, Feb 19, 2009 at 23:09, Gavin Kistner wrote:
>> Does there exist an english introduction to NginX config 'programming'?
>
> None, AFAIK. I had the same problem a few months ago when I switched
> to nginx. I ended up learning by example, getting nginx to do what I
> wanted, then forgetting about it.
>
> This is probably the reason nobody wrote a clear, academic, intro to
> nginx configuration.

http://wiki.nginx.org/NginxConfiguration
http://wiki.nginx.org/NginxModules

I don't get what else are you expecting?
I mean there are basic samples / advanced configurations / specific
cases
covered. On each ( http://wiki.nginx.org/NginxFullExample ) statement,
option you can click on and see what it actually means / does.

Of course the more documentation the better then again saying there is
none
at all is wrong.

rr
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-03-18 10:58
(Received via mailing list)
On Wed, Mar 18, 2009 at 11:33:03AM +0200, Reinis Rozitis wrote:

> http://wiki.nginx.org/NginxConfiguration
> http://wiki.nginx.org/NginxModules
>
> I don't get what else are you expecting?
> I mean there are basic samples / advanced configurations / specific cases
> covered. On each ( http://wiki.nginx.org/NginxFullExample ) statement,
> option you can click on and see what it actually means / does.
>
> Of course the more documentation the better then again saying there is none
> at all is wrong.

This is a reference and some cookbook recepts but not introdution.
I can write draft description of request processing from confuguration
point of view but without these ugly rewrites as want to change them.
F5a6ed477b109fe6acc11a5a8f87e7e8?d=identicon&s=25 mike (Guest)
on 2009-03-18 16:33
(Received via mailing list)
2009/3/18 Igor Sysoev <is@rambler-co.ru>:

> This is a reference and some cookbook recepts but not introdution.
> I can write draft description of request processing from confuguration
> point of view but without these ugly rewrites as want to change them.

When you say "ugly rewrites" what do you mean?

IMHO, nginx is pretty easy to pick up. At first when I saw the syntax
I thought "oh no, another config file to learn" but it is pretty damn
simple.

My biggest issue is with location blocks. It is still confusing and
gets annoying on sites requiring multiple location blocks, especially
with regexps and determining the right ^~ or *~ etc.

Other than that, a few tweaks to allow things like error_log at -any-
level not just global and server but even inside conditionals would be
neat...

But I'm wondering what you meant by that. You have some code you don't
like in nginx that you want to rewrite? If so, what? Or the "rewrite"
directive itself and such is a nasty thing. I like to hear the plans
and news about nginx (call me an nginx fanboy now) - even a roadmap
would be cool too (I think I've seen bits and pieces in the past) of
what at least you plan on changing/adding, and of course if other
people do third party modules or patch things in the core that can
only enhance it quicker...
535e2bd84829abaf90def03e89299e20?d=identicon&s=25 Marcus Clyne (Guest)
on 2009-03-18 16:52
(Received via mailing list)
Having 'elseif' / 'else' blocks as well as 'if' would be handy too.
It's obviously possible with lots of 'if' statements, but isn't the most
efficient way of doing things.

Marcus.
56080a668b706e94fb2bbe9ee727d006?d=identicon&s=25 Reinis Rozitis (Guest)
on 2009-03-18 17:04
(Received via mailing list)
> My biggest issue is with location blocks. It is still confusing and
> gets annoying on sites requiring multiple location blocks, especially
> with regexps and determining the right ^~ or *~ etc.

The biggest issue in my mind is the way nginx doesnt merge/inherit (
http://wiki.nginx.org/NginxHttpCoreModule#location ) the
options for different location blocks if there are more than one that
matches.
It can be handy sometimes but usually it has created me more issues and
some nasty workarrounds than helped.


Like sometimes there is the need to have:

location ~ ^/zzz { ... }

But if you have the default location ~ \.php$ { .. } defined before

It means that the /zzz/some.php requests wont use any options you
defined in the config.



I have whined about this (and also about global location feature in the
http{} scope) to Igor some time ago but he was sceptical at
that time ;)

rr
F5a6ed477b109fe6acc11a5a8f87e7e8?d=identicon&s=25 mike (Guest)
on 2009-03-18 20:47
(Received via mailing list)
i don't like having to do

location \.php {
  stuff
}

location /foo {
   auth basic stuff
    ... and i have to do the php stuff again
}

i guess there's no real way around it, really. it's just a gripe i
have, i suppose. perhaps some way of inheriting all locations globally
first and then doing second level, then third level, etc...
2e321cc0efe9422d37165e922298494e?d=identicon&s=25 Cliff Wells (Guest)
on 2009-03-18 20:56
(Received via mailing list)
On Wed, 2009-03-18 at 12:38 -0700, mike wrote:
> i don't like having to do
>
> location \.php {
>   stuff
> }
>
> location /foo {
>    auth basic stuff
>     ... and i have to do the php stuff again
> }

Couldn't you just do:

include /etc/nginx/php.conf;

location /foo {
    auth basic stuff
    include /etc/nginx/php.conf;
}

Regards,
Cliff
F5a6ed477b109fe6acc11a5a8f87e7e8?d=identicon&s=25 mike (Guest)
on 2009-03-18 21:11
(Received via mailing list)
yes but each virtual host may have different php configs. so then i'm
supporting a ton of includes :)
This topic is locked and can not be replied to.