Mercurial > hg > nginx
annotate src/stream/ngx_stream_upstream_round_robin.h @ 8122:106328a70f4e
Added warning about redefinition of listen socket protocol options.
The "listen" directive in the http module can be used multiple times
in different server blocks. Originally, it was supposed to be specified
once with various socket options, and without any parameters in virtual
server blocks. For example:
server { listen 80 backlog=1024; server_name foo; ... }
server { listen 80; server_name bar; ... }
server { listen 80; server_name bazz; ... }
The address part of the syntax ("address[:port]" / "port" / "unix:path")
uniquely identifies the listening socket, and therefore is enough for
name-based virtual servers (to let nginx know that the virtual server
accepts requests on the listening socket in question).
To ensure that listening options do not conflict between virtual servers,
they were allowed only once. For example, the following configuration
will be rejected ("duplicate listen options for 0.0.0.0:80 in ..."):
server { listen 80 backlog=1024; server_name foo; ... }
server { listen 80 backlog=512; server_name bar; ... }
At some point it was, however, noticed, that it is sometimes convenient
to repeat some options for clarity. In nginx 0.8.51 the "ssl" parameter
was allowed to be specified multiple times, e.g.:
server { listen 443 ssl backlog=1024; server_name foo; ... }
server { listen 443 ssl; server_name bar; ... }
server { listen 443 ssl; server_name bazz; ... }
This approach makes configuration more readable, since SSL sockets are
immediately visible in the configuration. If this is not needed, just the
address can still be used.
Later, additional protocol-specific options similar to "ssl" were
introduced, notably "http2" and "proxy_protocol". With these options,
one can write:
server { listen 443 ssl backlog=1024; server_name foo; ... }
server { listen 443 http2; server_name bar; ... }
server { listen 443 proxy_protocol; server_name bazz; ... }
The resulting socket will use ssl, http2, and proxy_protocol, but this
is not really obvious from the configuration.
To emphasize such misleading configurations are discouraged, nginx now
warns as long as the "listen" directive is used with options different
from the options previously used if this is potentially confusing.
In particular, the following configurations are allowed:
server { listen 8401 ssl backlog=1024; server_name foo; }
server { listen 8401 ssl; server_name bar; }
server { listen 8401 ssl; server_name bazz; }
server { listen 8402 ssl http2 backlog=1024; server_name foo; }
server { listen 8402 ssl; server_name bar; }
server { listen 8402 ssl; server_name bazz; }
server { listen 8403 ssl; server_name bar; }
server { listen 8403 ssl; server_name bazz; }
server { listen 8403 ssl http2; server_name foo; }
server { listen 8404 ssl http2 backlog=1024; server_name foo; }
server { listen 8404 http2; server_name bar; }
server { listen 8404 http2; server_name bazz; }
server { listen 8405 ssl http2 backlog=1024; server_name foo; }
server { listen 8405 ssl http2; server_name bar; }
server { listen 8405 ssl http2; server_name bazz; }
server { listen 8406 ssl; server_name foo; }
server { listen 8406; server_name bar; }
server { listen 8406; server_name bazz; }
And the following configurations will generate warnings:
server { listen 8501 ssl http2 backlog=1024; server_name foo; }
server { listen 8501 http2; server_name bar; }
server { listen 8501 ssl; server_name bazz; }
server { listen 8502 backlog=1024; server_name foo; }
server { listen 8502 ssl; server_name bar; }
server { listen 8503 ssl; server_name foo; }
server { listen 8503 http2; server_name bar; }
server { listen 8504 ssl; server_name foo; }
server { listen 8504 http2; server_name bar; }
server { listen 8504 proxy_protocol; server_name bazz; }
server { listen 8505 ssl http2 proxy_protocol; server_name foo; }
server { listen 8505 ssl http2; server_name bar; }
server { listen 8505 ssl; server_name bazz; }
server { listen 8506 ssl http2; server_name foo; }
server { listen 8506 ssl; server_name bar; }
server { listen 8506; server_name bazz; }
server { listen 8507 ssl; server_name bar; }
server { listen 8507; server_name bazz; }
server { listen 8507 ssl http2; server_name foo; }
server { listen 8508 ssl; server_name bar; }
server { listen 8508; server_name bazz; }
server { listen 8508 ssl backlog=1024; server_name foo; }
server { listen 8509; server_name bazz; }
server { listen 8509 ssl; server_name bar; }
server { listen 8509 ssl backlog=1024; server_name foo; }
The basic idea is that at most two sets of protocol options are allowed:
the main one (with socket options, if any), and a shorter one, with options
being a subset of the main options, repeated for clarity. As long as the
shorter set of protocol options is used, all listen directives except the
main one should use it.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 28 Jan 2023 01:29:45 +0300 |
parents | 90cc7194e993 |
children |
rev | line source |
---|---|
6115 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #ifndef _NGX_STREAM_UPSTREAM_ROUND_ROBIN_H_INCLUDED_ | |
9 #define _NGX_STREAM_UPSTREAM_ROUND_ROBIN_H_INCLUDED_ | |
10 | |
11 | |
12 #include <ngx_config.h> | |
13 #include <ngx_core.h> | |
14 #include <ngx_stream.h> | |
15 | |
16 | |
17 typedef struct ngx_stream_upstream_rr_peer_s ngx_stream_upstream_rr_peer_t; | |
18 | |
19 struct ngx_stream_upstream_rr_peer_s { | |
20 struct sockaddr *sockaddr; | |
21 socklen_t socklen; | |
22 ngx_str_t name; | |
23 ngx_str_t server; | |
24 | |
25 ngx_int_t current_weight; | |
26 ngx_int_t effective_weight; | |
27 ngx_int_t weight; | |
28 | |
29 ngx_uint_t conns; | |
6705 | 30 ngx_uint_t max_conns; |
6115 | 31 |
32 ngx_uint_t fails; | |
33 time_t accessed; | |
34 time_t checked; | |
35 | |
36 ngx_uint_t max_fails; | |
37 time_t fail_timeout; | |
6708
4080f94a996f
Modules compatibility: slow start fields.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6705
diff
changeset
|
38 ngx_msec_t slow_start; |
4080f94a996f
Modules compatibility: slow start fields.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6705
diff
changeset
|
39 ngx_msec_t start_time; |
6115 | 40 |
6713
63b8b157b776
Modules compatibility: down flag promoted to a bitmask.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6712
diff
changeset
|
41 ngx_uint_t down; |
6115 | 42 |
43 void *ssl_session; | |
44 int ssl_session_len; | |
45 | |
46 #if (NGX_STREAM_UPSTREAM_ZONE) | |
47 ngx_atomic_t lock; | |
48 #endif | |
6701
d69964eb8335
Upstream: style, ngx_http_upstream_rr_peer_t.next moved.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6643
diff
changeset
|
49 |
d69964eb8335
Upstream: style, ngx_http_upstream_rr_peer_t.next moved.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6643
diff
changeset
|
50 ngx_stream_upstream_rr_peer_t *next; |
6715
d200a0fd00b7
Introduced the NGX_COMPAT macro.
Ruslan Ermilov <ru@nginx.com>
parents:
6713
diff
changeset
|
51 |
d200a0fd00b7
Introduced the NGX_COMPAT macro.
Ruslan Ermilov <ru@nginx.com>
parents:
6713
diff
changeset
|
52 NGX_COMPAT_BEGIN(25) |
d200a0fd00b7
Introduced the NGX_COMPAT macro.
Ruslan Ermilov <ru@nginx.com>
parents:
6713
diff
changeset
|
53 NGX_COMPAT_END |
6115 | 54 }; |
55 | |
56 | |
57 typedef struct ngx_stream_upstream_rr_peers_s ngx_stream_upstream_rr_peers_t; | |
58 | |
59 struct ngx_stream_upstream_rr_peers_s { | |
60 ngx_uint_t number; | |
61 | |
62 #if (NGX_STREAM_UPSTREAM_ZONE) | |
63 ngx_slab_pool_t *shpool; | |
64 ngx_atomic_t rwlock; | |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6115
diff
changeset
|
65 ngx_stream_upstream_rr_peers_t *zone_next; |
6115 | 66 #endif |
67 | |
68 ngx_uint_t total_weight; | |
7750
90cc7194e993
Upstream: excluded down servers from the next_upstream tries.
Ruslan Ermilov <ru@nginx.com>
parents:
6736
diff
changeset
|
69 ngx_uint_t tries; |
6115 | 70 |
71 unsigned single:1; | |
72 unsigned weighted:1; | |
73 | |
74 ngx_str_t *name; | |
75 | |
76 ngx_stream_upstream_rr_peers_t *next; | |
77 | |
78 ngx_stream_upstream_rr_peer_t *peer; | |
79 }; | |
80 | |
81 | |
82 #if (NGX_STREAM_UPSTREAM_ZONE) | |
83 | |
84 #define ngx_stream_upstream_rr_peers_rlock(peers) \ | |
85 \ | |
86 if (peers->shpool) { \ | |
87 ngx_rwlock_rlock(&peers->rwlock); \ | |
88 } | |
89 | |
90 #define ngx_stream_upstream_rr_peers_wlock(peers) \ | |
91 \ | |
92 if (peers->shpool) { \ | |
93 ngx_rwlock_wlock(&peers->rwlock); \ | |
94 } | |
95 | |
96 #define ngx_stream_upstream_rr_peers_unlock(peers) \ | |
97 \ | |
98 if (peers->shpool) { \ | |
99 ngx_rwlock_unlock(&peers->rwlock); \ | |
100 } | |
101 | |
102 | |
103 #define ngx_stream_upstream_rr_peer_lock(peers, peer) \ | |
104 \ | |
105 if (peers->shpool) { \ | |
106 ngx_rwlock_wlock(&peer->lock); \ | |
107 } | |
108 | |
109 #define ngx_stream_upstream_rr_peer_unlock(peers, peer) \ | |
110 \ | |
111 if (peers->shpool) { \ | |
112 ngx_rwlock_unlock(&peer->lock); \ | |
113 } | |
114 | |
115 #else | |
116 | |
117 #define ngx_stream_upstream_rr_peers_rlock(peers) | |
118 #define ngx_stream_upstream_rr_peers_wlock(peers) | |
119 #define ngx_stream_upstream_rr_peers_unlock(peers) | |
120 #define ngx_stream_upstream_rr_peer_lock(peers, peer) | |
121 #define ngx_stream_upstream_rr_peer_unlock(peers, peer) | |
122 | |
123 #endif | |
124 | |
125 | |
126 typedef struct { | |
6712
fd5c2781460b
Modules compatibility: upstream config field.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6708
diff
changeset
|
127 ngx_uint_t config; |
6115 | 128 ngx_stream_upstream_rr_peers_t *peers; |
129 ngx_stream_upstream_rr_peer_t *current; | |
130 uintptr_t *tried; | |
131 uintptr_t data; | |
132 } ngx_stream_upstream_rr_peer_data_t; | |
133 | |
134 | |
135 ngx_int_t ngx_stream_upstream_init_round_robin(ngx_conf_t *cf, | |
136 ngx_stream_upstream_srv_conf_t *us); | |
137 ngx_int_t ngx_stream_upstream_init_round_robin_peer(ngx_stream_session_t *s, | |
138 ngx_stream_upstream_srv_conf_t *us); | |
6643
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6198
diff
changeset
|
139 ngx_int_t ngx_stream_upstream_create_round_robin_peer(ngx_stream_session_t *s, |
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6198
diff
changeset
|
140 ngx_stream_upstream_resolved_t *ur); |
6115 | 141 ngx_int_t ngx_stream_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, |
142 void *data); | |
143 void ngx_stream_upstream_free_round_robin_peer(ngx_peer_connection_t *pc, | |
144 void *data, ngx_uint_t state); | |
145 | |
146 | |
147 #endif /* _NGX_STREAM_UPSTREAM_ROUND_ROBIN_H_INCLUDED_ */ |