nginx.conf.j2
8.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
user www www;
# setup worker proccess and worker cpu affinity
worker_processes {{processor_count}};
{% if processor_count == '2' %}
worker_cpu_affinity 01 10;
{% elif processor_count == '4' %}
worker_cpu_affinity 1000 0100 0010 0001;
{% elif processor_count >= '8' %}
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
{% else %}
worker_cpu_affinity 1000 0100 0010 0001;
{% endif %}
pid logs/nginx.pid;
# [ debug | info | notice | warn | error | crit ]
#error_log /Data/logs/nginx/nginx_error.log info;
error_log /Data/logs/nginx/nginx_error.log info;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
#maxclient = worker_processes * worker_connections / cpu_number
worker_connections 51200;
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312,utf-8;
charset utf-8;
log_format fenxi '$remote_addr|$http_x_forwarded_for|[$time_local]|$http_host|$request|'
'$status|$body_bytes_sent|$request_time|$upstream_response_time|$upstream_cache_status|$http_referer|'
'$http_user_agent|$upstream_addr|'
'$real_ip|$request_api_method|$request_uid|$request_udid';
log_format union '$remote_addr|$http_x_forwarded_for|[$time_local]|$http_host|$request|'
'$status|$body_bytes_sent|$request_time|$upstream_response_time|$upstream_cache_status|$http_referer|'
'$http_user_agent|$upstream_addr|';
# resolver: local dns servers
resolver {% for i in groups['nameservers'] %} {{ i }} {% endfor %};
#General Options
server_names_hash_bucket_size 128;
client_header_buffer_size 512k;
large_client_header_buffers 4 512k;
client_body_buffer_size 8m; #256k
#
#server_tokens off;
ignore_invalid_headers on;
recursive_error_pages on;
server_name_in_redirect off;
sendfile on;
#timeouts
keepalive_timeout 75s;
keepalive_requests 10000;
#test
#client_body_timeout 3m;
#client_header_timeout 3m;
#send_timeout 3m;
#TCP Options
tcp_nopush on;
tcp_nodelay on;
#fastcgi options
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
#hiden php version
fastcgi_hide_header X-Powered-By;
#size limits
client_max_body_size 50m;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
#gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml application/json;
gzip_vary on;
add_header x-yh-nginx-dc {{ dc }};
fastcgi_temp_path /dev/shm/fastcgi_temp;
client_body_temp_path /dev/shm/client_body_temp;
# where the lua package exists
lua_package_path "/Data/local/openresty-1.9.15.1/nginx/conf/lua/?.lua;;";
init_by_lua_file "conf/lua/init_lua.lua";
# lua_shared_dict luacachedb 80m;
lua_shared_dict upstream 20m;
lua_shared_dict malips 10m;
lua_shared_dict ngxconf 20m;
init_worker_by_lua_file "conf/lua/init_config_worker.lua";
#brower service
upstream brower {
{% for i in groups['java-brower'] %}
server {{ i }}:8092;
{% endfor %}
keepalive 100;
}
# uic service
upstream uic {
{% for i in groups['java-uic'] %}
server {{ i }}:8096;
{% endfor %}
keepalive 100;
}
# review
upstream review {
{% for i in groups['java-review'] %}
server {{ i }}:8063;
{% endfor %}
keepalive 100;
}
# message controller
upstream message {
{% for i in groups['java-message-controller'] %}
server {{ i }}:8087;
{% endfor %}
keepalive 100;
}
# search
upstream search{
{% for i in groups['search-service'] %}
server {{ i }}:8080;
{% endfor %}
keepalive 100;
}
#apigatewaystart
upstream apigateway {
{% if upstream_az == 'aws' %}
server java-gateway-431f16063270008f.elb.cn-north-1.amazonaws.com.cn:8080 max_fails=5 fail_timeout=3s;
{% elif upstream_az == 'az1'%}
server 10.66.4.112:8080 max_fails=5 fail_timeout=3s;
{% else %}
{% for i in groups['java-gateway'] %}
server {{ i }}:8080 max_fails=5 fail_timeout=3s;
{% endfor %}
{% endif %}
keepalive 32;
}
#apigatewayend
# activity
upstream activityApi{
{% for i in groups['java-activity'] %}
server {{ i }}:8090;
{% endfor %}
keepalive 100;
}
# wechat
upstream apiWechat {
{% for i in groups['java-wechat'] %}
server {{ i }}:8094;
{% endfor %}
keepalive 100;
}
# erp gateway
upstream erpgateway {
{% for i in groups['java-erpgateway'] %}
server {{ i }}:8089;
{% endfor %}
keepalive 100;
}
# union servers
upstream union_pools {
{% for i in groups['java-union'] %}
server {{ i }}:8088 max_fails=5 fail_timeout=3s;
{% endfor %}
keepalive 100;
}
#ufo-gateway
upstream ufogateway {
{% if upstream_az == 'aws' %}
server 172.31.70.86:8080 max_fails=5 fail_timeout=3s;
{% elif upstream_az == 'az1'%}
server 10.66.70.77:8080 max_fails=5 fail_timeout=3s;
server 10.66.70.63:8080 max_fails=5 fail_timeout=3s;
server 10.66.70.84:8080 max_fails=5 fail_timeout=3s;
{% else %}
{% for i in groups['java-ufo-fore'] %}
server {{ i }}:8080 max_fails=5 fail_timeout=3s;
{% endfor %}
{% endif %}
keepalive 32;
}
################ ufo limit #############
geo $limited {
default 1;
# CIDR in the list below are not limited
10.66.0.0/16 0;
10.67.0.0/16 0;
192.168.0.0/16 0;
172.31.0.0/16 0;
}
map $limited $limit {
1 $binary_remote_addr;
0 "";
}
limit_req_zone $limit zone=limit_ufo:90m rate=30r/s;
################ uic limit for mars app #############
geo $uic_blacklist {
default 1;
# CIDR in the list below are limited
10.66.251.0/24 0;
192.168.32.0/19 0;
}
map $uic_blacklist $limit_uic {
0 $binary_remote_addr;
1 "";
}
limit_req_zone $limit_uic zone=limit_uic_zone:30m rate=50r/s;
##############################################################
#upstream
fastcgi_next_upstream error timeout invalid_header http_500;
#fastcgi cache
#fastcgi_cache_path /nginxcache levels=1:2 keys_zone=two:10m inactive=1d max_size=3000m;
#for example just for study! have fun!
include vhosts/api.yoho.cn.conf;
include vhosts/api_single.yoho.cn.conf;
include vhosts/erp.yoho.yohoops.org.conf;
include vhosts/single.conf;
include vhosts/union.yoho.cn.conf;
include vhosts/api.ufo.conf;
include vhosts/y-d.conf;
include vhosts/uic.conf;
include vhosts/review.conf;
include vhosts/message-controller.conf;
include vhosts/search.conf;
}