生产配置示例

生产配置示例

1. nginx.conf

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
user  www-data;

worker_processes auto;
worker_rlimit_nofile 65535;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 4096;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

#log_format main '$http_x_forwarded_for - $remote_addr - $remote_user '
# '[$time_local] "$request" $status $body_bytes_sent '
# '"$http_referer" "$http_user_agent"'
# '"$http_x_forwarded_for" $request_time';

#access_log /var/log/nginx/access.log main;
## LOG ##
log_format main '$upstream_response_time $remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$request_time"';

log_format json '{"@timestamp":"$time_iso8601",'
'"department":"devops",'
'"type":"prod_america_nginx",'
'"@version":"1",'
'"host":"$server_addr",'
'"client":"$remote_addr",'
'"real-client":"$http_x_forwarded_for",'
'"auth_user":"$remote_user",'
'"request":"$request",'
'"method":"$request_method",'
'"port":"$server_port",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"domain":"$host",'
'"UserAgent":"$http_user_agent",'
'"url":"$uri",'
'"status":"$status"}';


<!--log_format logstash_json '{ "@timestamp": "$time_iso8601", '-->
<!--'"remote_addr": "$remote_addr", '-->
<!--'"referer": "$http_referer", '-->
<!--'"request": "$request", '-->
<!--'"status": $status, '-->
<!--'"bytes":$body_bytes_sent, '-->
<!--'"agent": "$http_user_agent", '-->
<!--'"x_forwarded": "$http_x_forwarded_for", '-->
<!--'"upstr_addr": "$upstream_addr",'-->
<!--'"upstr_host": "$upstream_http_host",'-->
<!--'"ups_resp_time": "$upstream_response_time" }';-->

access_log /data/logs/nginx/access_json.log json;
error_log /data/logs/nginx/error.log warn;

ssi on;
ssi_silent_errors off;

server_tokens off;

sendfile on;
tcp_nopush on;
tcp_nodelay on;

client_max_body_size 8M;
client_body_buffer_size 128k;

keepalive_timeout 65;

gzip on;
gzip_min_length 10k;
gzip_comp_level 3;
gzip_types text/plain text/css application/javascript application/json
application/xml application/xhtml+xml text/csv;

include /etc/nginx/conf.d/*.conf;
}

2. redirect-all-to-https.conf

1
2
3
4
5
6
7
8
9
10
server {
listen 80 default_server;
listen 443 default_server;
server_name _;

access_log /var/log/nginx/redirect-all-to-https.access.log main;
error_log /var/log/nginx/redirect-all-to-https.error.log warn;

return 302 https://$host$request_uri;
}

3. upstream

1
2
3
4
5
6
7
8
9
10
11
12
13
####################
# 数据挖掘
####################
upstream wecash_mining_apis {
server 10.40.58.116:8080 max_fails=2 fail_timeout=30s;
}
upstream wecash_mining_router {
server 10.40.58.114:8080 max_fails=2 fail_timeout=30s;
}
upstream wecash_restful_apis {
server 10.40.58.115:8081 max_fails=2 fail_timeout=30s;
server 10.40.61.93:8081 max_fails=2 fail_timeout=30s;
}

4. Server段

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
server {
listen 8081;
server_name 10.40.61.75;
aio threads=default;
client_max_body_size 2048m;
access_log logs/wecash_mining.access.log main;
error_log logs/wecash_mining.error.log error;
location ~ ^/v1/(sms|employer) {
proxy_next_upstream error timeout http_503 http_502 http_504;
proxy_pass http://wecash_mining_apis;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
}
location ~ ^/api/v1/dispatch {
proxy_next_upstream error timeout http_503 http_502 http_504;
proxy_pass http://wecash_mining_router;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
}
location ~ ^/api/v1/(phone_book|segmentation|apply_info|lastest_company|fund|credit_report|social_security|simple_operator|phone_tag) {
proxy_next_upstream error timeout http_503 http_502 http_504;
proxy_pass http://wecash_restful_apis;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

本文标题:生产配置示例

文章作者:shuke

发布时间:2020年04月20日 - 15:04

最后更新:2020年04月20日 - 15:04

原始链接:https://shuke163.github.io/2020/04/20/%E7%94%9F%E4%BA%A7%E9%85%8D%E7%BD%AE%E7%A4%BA%E4%BE%8B/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

-------------本文结束感谢您的阅读-------------

本文标题:生产配置示例

文章作者:shuke

发布时间:2020年04月20日 - 15:04

最后更新:2020年04月20日 - 15:04

原始链接:https://shuke163.github.io/2020/04/20/%E7%94%9F%E4%BA%A7%E9%85%8D%E7%BD%AE%E7%A4%BA%E4%BE%8B/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

0%