Issue with upstream

I’m having some problems configuring upstream servers with localhost
backup
(error page)

upstream backend1 {
server 1.2.3.4;
server 2.3.4.5;
server localhost backup;
}

upstream backend2 {
server 3.4.5.6;
server 4.5.6.7;
}

Works, but:

upstream backend1 {
server 1.2.3.4;
server 2.3.4.5;
server localhost backup;
}

upstream backend2 {
server 3.4.5.6;
server 4.5.6.7;
server localhost backup;
}

Causes:

Testing nginx configuration: [emerg]: invalid parameter “backup”

Is this a bug?

Cheers
Phil.

Problem solved, strangely enough the order in which my servers are
loaded
seams to trigger this error, it’s actually nothing to do with the
upstream
settings but forcing one of my server configs to be loaded last resolved
the
issue.

On 16 November 2010 13:16, Phil B. [email protected]
wrote:

server 3.4.5.6;

Is this a bug?

Cheers
Phil.


Phil B.
Developer
Techlightenment

3.08 Tea Building | 56 Shoreditch High St | London | E1 6JJ
t: +44 (0) 8445814444
m: +44 (0) 7711117117
e: [email protected]
www.techlightenment.com

Social Media Developer positions available. See http://bit.ly/afmRt4
for
info

Hello!

On Tue, Nov 16, 2010 at 01:16:25PM +0000, Phil B. wrote:

server 3.4.5.6;

Is this a bug?
Most likely you used backend2 somewhere in proxy_pass before
defining upstream backend2. This is not generally supported and
and shouldn’t be allowed, but happens to “work” (though with
several unexpected side effects) for now.

Attached patch makes sure such configuration like

server {
location / {
proxy_pass backend;

}

}

upstream backend {

}

will generate “upstream “backend” defined too late” error during
configuration parsing.

Maxim D.

Hello!

On Tue, Nov 16, 2010 at 03:02:00PM +0000, Phil B. wrote:

I had actually prefixed upstream and localhost 000 and everything else 100
to force them to load in the correct order.
On 1 particular domain it would throw that error unless it was loaded last,
hence just giving it a prefix 101 solved the issue.
Bit strange!

Addition prefixes isn’t going to do anything good as nginx doesn’t sort
included files (I assume you used something like “include
/path/*.conf”) and they are loaded in unspecified order (as
filesystem returns them).

You have to manually preserve correct order, i.e. use something
like

include /path/to/generic/includes/.conf;
include /path/to/virtual/hosts/
.conf;

Maxim D.

p.s. Please do not top-post. Thank you.

I had actually prefixed upstream and localhost 000 and everything else
100
to force them to load in the correct order.
On 1 particular domain it would throw that error unless it was loaded
last,
hence just giving it a prefix 101 solved the issue.
Bit strange!

On 16 November 2010 14:49, Maxim D. [email protected] wrote:

server 2.3.4.5;

upstream backend1 {

upstream backend {
[email protected]
nginx Info Page


Phil B.
Developer
Techlightenment

3.08 Tea Building | 56 Shoreditch High St | London | E1 6JJ
t: +44 (0) 8445814444
m: +44 (0) 7711117117
e: [email protected]
www.techlightenment.com

Social Media Developer positions available. See http://bit.ly/afmRt4
for
info

On 16 Nov 2010 18h24 WET, [email protected] wrote:

Addition prefixes isn’t going to do anything good as nginx doesn’t
sort included files (I assume you used something like “include
/path/*.conf”) and they are loaded in unspecified order (as
filesystem returns them).

You have to manually preserve correct order, i.e. use something
like

include /path/to/generic/includes/.conf;
include /path/to/virtual/hosts/
.conf;

Well that’s interesting. I was under the (wrong) impression that in
fact it operated like in Apache. Where there’s a 000-default vhost
config file in Debian that is a symlink created when enabling the
site.

I have a 000-default file that just returns a 444 when the Host header
doesn’t match any of the server_name directives. I guess that I should
be loading that file explicitly before all other.

include /etc/nginx/sites-enabled/000-default
include /etc/nginx/sites-enabled/[a-z]*

Right?

Thanks,
— appa

Hello!

On Tue, Nov 16, 2010 at 06:32:19PM +0000, António P. P. Almeida wrote:

strange!
include /path/to/virtual/hosts/.conf;
include /etc/nginx/sites-enabled/000-default
include /etc/nginx/sites-enabled/[a-z]

Right?

Alternative solution is to use “listen … default;” (or “listen
… default_server;” which is the same) in a server which should
be default on a given socket.

http://nginx.org/en/docs/http/request_processing.html#how_to_prevent_undefined_server_names

Maxim D.

If you order them 000, 001, 002 that is the same order as the filesystem
returns:

phil@proxy:~$ ls -l /etc/nginx/sites-enabled/
total 0
lrwxrwxrwx 1 root root 28 2010-11-12 22:56 000-l*
lrwxrwxrwx 1 root root 27 2010-11-13 00:19 000-u*
lrwxrwxrwx 1 root root 26 2010-11-13 02:06 100-p*
lrwxrwxrwx 1 root root 29 2010-11-13 00:20 101-d*
lrwxrwxrwx 1 root root 33 2010-11-15 20:30 200-p*
lrwxrwxrwx 1 root root 46 2010-11-15 20:30 201-s*
lrwxrwxrwx 1 root root 50 2010-11-16 14:11 202-p*

Maybe not the case on all OS? This solution worked perfectly for me,
Ubuntu
10.10 server :slight_smile:

Hello!

On Tue, Nov 16, 2010 at 08:14:34PM +0000, Phil B. wrote:

lrwxrwxrwx 1 root root 46 2010-11-15 20:30 201-s*
lrwxrwxrwx 1 root root 50 2010-11-16 14:11 202-p*

ls returns sorted results, see here:

http://www.opengroup.org/onlinepubs/9699919799/utilities/ls.html

Maybe not the case on all OS? This solution worked perfectly for me, Ubuntu
10.10 server :slight_smile:

Some filesystems may return sorted results, but it’s unlikely to
be so in your case.

Maxim D.

Hello!

On Tue, Nov 16, 2010 at 05:49:16PM +0300, Maxim D. wrote:

[…]

Most likely you used backend2 somewhere in proxy_pass before
defining upstream backend2. This is not generally supported and
and shouldn’t be allowed, but happens to “work” (though with
several unexpected side effects) for now.

Disregard this (and patch). Actually, the only thing which won’t
work as expected is an attempt to redefine unix socket with
upstream{} block.

New patch attached.

Maxim D.

You might be right, find returns different order.

I guess to be safe, I’ll move the upstream declarations into a new
folder
‘sites-enabled-upstream’ and stick that first in nginx.conf