-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssl_server_lb.conf
173 lines (147 loc) · 4.56 KB
/
ssl_server_lb.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
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
#
# Handle all requests to (non SSL) http.
#
server {
server_name <load balancer API domain name> default_server;
listen 80;
root /var/www/html;
location ~ ^/.well-known/acme-challenge* {
# try_files $uri @go2https;
access_log /var/log/nginx/acme_access_log;
error_log /var/log/nginx/acme_error_log;
}
# Default location match - will drop all connections
# immediately if not an acme request. Comment this,
# uncomment tri_files above and location block below
# if you want to forward all non-acme requests to
# SSL port.
location / {
return 444;
}
# Mutually exclusive location to above. Redirects to SSL https
# location @go2https {
# rewrite ^ https://$server_name$request_uri? permanent;
# }
}
#
# bts_tools web interface - with basic authentication
# NOTE: uses a different server name!
#
server {
listen 443 ssl;
server_name <bts_tools-domain.com>;
ssl on;
ssl_certificate /etc/nginx/ssl/certs/bts_tools.crt;
ssl_certificate_key /etc/nginx/ssl/private/bts_tools.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
# Alternate cipher specs. Many other possible as well.
# ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
# ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
# ssl_prefer_server_ciphers on;
#
charset utf-8;
location / { try_files $uri @bts_tools; }
location @bts_tools {
auth_basic "No Access Here!";
auth_basic_user_file <your password list file>;
include uwsgi_params;
uwsgi_pass unix:<path to bts_tools uwsgi socket>;
}
}
#
# Final destination for local websocket server (ws not wss)
#
upstream local_ws_svr {
server localhost:<port>;
}
#
# This virtual host is used to translate wss into ws & proxy for local ws server
#
server {
listen <local wss (not 443) port> ssl;
server_name <public-api-domain.com (public non-load balanced wss)>;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 25000;
ssl on;
ssl_certificate /etc/nginx/ssl/certs/server.crt;
ssl_certificate_key /etc/nginx/ssl/private/server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
#
# Default location match - will drop all connections
# immediately if websocket location below fails to match.
location / {
return 444;
}
# Matches websocket URL address
location ~ ^/wss$ {
limit_req zone=ws burst=5;
proxy_http_version 1.1;
#proxy_connect_timeout 2;
proxy_pass http://local_ws_svr;
proxy_set_header Host $host;
proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_next_upstream error timeout invalid_header http_500;
}
}
#
# Proxy / load balancer for public websocket API.
#
# NOTE: the other servers also proxy wss to ws
upstream websockets {
server localhost:<local wsS port used above>
server 2.2.2.2:443
server 3.3.3.3:443
server 4.4.4.4:443
server 5.5.5.5:443
}
#
# Virtual host for load balanced wss websocket public API
#
server {
listen 443 ssl;
server_name <public-api-domain.com (load balanced)>;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 100000;
ssl on;
ssl_certificate /etc/nginx/ssl/certs/server.crt;
ssl_certificate_key /etc/nginx/ssl/private/server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
# Provided to verify https certificate is working
location ~ ^/.well-known/acme-challenge* {
root /var/www/html;
access_log /var/log/nginx/acme_access_log;
error_log /var/log/nginx/acme_error_log;
break;
}
#
# Default location match - will drop all connections
# immediately if the other location blocks fail to match.
location / {
return 444;
}
# Matches websocket URL address
location ~ ^/wss$ {
limit_req zone=ws burst=5;
proxy_http_version 1.1;
proxy_connect_timeout 2;
proxy_pass https://websockets;
proxy_set_header Host $host;
proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500;
}
}