Skip to content

Commit 44a351b

Browse files
committed
Various enhancements and tweaks for nginx.
1 parent ebc1e24 commit 44a351b

File tree

3 files changed

+34
-63
lines changed

3 files changed

+34
-63
lines changed

roles/services/frontend/templates/nginx-frontend.conf.j2

Lines changed: 17 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -38,39 +38,39 @@ server {
3838

3939
upstream search {
4040
ip_hash;
41-
keepalive 32;
41+
keepalive {{ groups['search_api'] | length * 2 }}; # 2 connections per backend server.
4242

4343
{% for host in groups['search_api'] %}
4444
server {{ hostvars[host]['vlan_ip'] | ipaddr('address') }} max_fails=3 fail_timeout=10s;
4545
{% endfor %}
4646
}
4747

4848
upstream metadata {
49-
keepalive 32;
49+
keepalive {{ groups['search_api'] | length * 2 }};
5050

5151
{% for host in groups['search_api'] %}
5252
server {{ hostvars[host]['vlan_ip'] | ipaddr('address') }} max_fails=3 fail_timeout=10s;
5353
{% endfor %}
5454
}
5555

5656
upstream nsfw {
57-
keepalive 32;
57+
keepalive {{ groups['search_api'] | length * 2 }};
5858

5959
{% for host in groups['nsfw_server'] %}
6060
server {{ hostvars[host]['vlan_ip'] | ipaddr('address') }} max_fails=3 fail_timeout=10;
6161
{% endfor %}
6262
}
6363

6464
upstream pinservice {
65-
keepalive 32;
65+
keepalive {{ groups['search_api'] | length * 2 }};
6666

6767
{% for host in groups['pinservice'] %}
6868
server {{ hostvars[host]['vlan_ip'] | ipaddr('address') }} max_fails=3 fail_timeout=10;
6969
{% endfor %}
7070
}
7171

7272
upstream nyats {
73-
keepalive 32;
73+
keepalive {{ groups['search_api'] | length * 2 }};
7474

7575
{% for host in groups['nyats'] %}
7676
server {{ hostvars[host]['vlan_ip'] | ipaddr('address') }} max_fails=0 fail_timeout=120s;
@@ -90,15 +90,18 @@ server {
9090
return 301 https://app.swaggerhub.com/apis-docs/ipfs-search/ipfs-search;
9191
}
9292

93-
location /v1/search {
94-
proxy_pass http://search/v1/search;
93+
# Required for backend keepalive
94+
proxy_http_version 1.1;
95+
proxy_set_header Connection "";
96+
97+
# Pass on remote address
98+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
9599

96-
# Required for backend keepalive
97-
proxy_http_version 1.1;
98-
proxy_set_header Connection "";
100+
proxy_hide_header Access-Control-Allow-Origin;
101+
add_header Access-Control-Allow-Origin '*' always;
99102

100-
# Pass on remote address
101-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
103+
location /v1/search {
104+
proxy_pass http://search/v1/search;
102105

103106
proxy_cache search_cache;
104107
proxy_cache_use_stale updating;
@@ -112,37 +115,17 @@ server {
112115
expires 15m;
113116

114117
add_header X-Cache-Status $upstream_cache_status always;
115-
116-
proxy_hide_header Access-Control-Allow-Origin;
117-
add_header Access-Control-Allow-Origin '*' always;
118118
}
119119

120120
location /v1/queue-pinservice {
121121
proxy_pass http://pinservice/v1/queue-pinservice;
122122

123-
# Required for backend keepalive
124-
proxy_http_version 1.1;
125-
proxy_set_header Connection "";
126-
127-
# Pass on remote address
128-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
129-
130-
proxy_read_timeout 5s;
131-
132-
proxy_hide_header Access-Control-Allow-Origin;
133-
add_header Access-Control-Allow-Origin '*' always;
123+
proxy_read_timeout 1s;
134124
}
135125

136126
location /v1/metadata {
137127
proxy_pass http://metadata/v1/metadata;
138128

139-
# Required for backend keepalive
140-
proxy_http_version 1.1;
141-
proxy_set_header Connection "";
142-
143-
# Pass on remote address
144-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
145-
146129
proxy_cache metadata_cache;
147130
proxy_cache_use_stale updating;
148131
proxy_cache_lock on;
@@ -155,21 +138,11 @@ server {
155138
expires 1y;
156139

157140
add_header X-Cache-Status $upstream_cache_status always;
158-
159-
proxy_hide_header Access-Control-Allow-Origin;
160-
add_header Access-Control-Allow-Origin '*' always;
161141
}
162142

163143
location /v1/nsfw {
164144
proxy_pass http://nsfw/v1/nsfw;
165145

166-
# Required for backend keepalive
167-
proxy_http_version 1.1;
168-
proxy_set_header Connection "";
169-
170-
# Pass on remote address
171-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
172-
173146
proxy_cache nsfw_cache;
174147
proxy_cache_use_stale updating;
175148
proxy_cache_lock on;
@@ -182,21 +155,11 @@ server {
182155
expires 1y;
183156

184157
add_header X-Cache-Status $upstream_cache_status always;
185-
186-
proxy_hide_header Access-Control-Allow-Origin;
187-
add_header Access-Control-Allow-Origin '*' always;
188158
}
189159

190160
location /v1/thumbnail {
191161
proxy_pass http://nyats/v1/thumbnail;
192162

193-
# Required for backend keepalive
194-
proxy_http_version 1.1;
195-
proxy_set_header Connection "";
196-
197-
# Pass on remote address
198-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
199-
200163
proxy_cache thumbnail_cache;
201164
proxy_cache_use_stale updating;
202165
proxy_cache_lock on;
@@ -209,13 +172,11 @@ server {
209172
expires 1y;
210173

211174
add_header X-Cache-Status $upstream_cache_status always;
212-
213-
proxy_hide_header Access-Control-Allow-Origin;
214-
add_header Access-Control-Allow-Origin '*' always;
215175
}
216176

217177
include {{ options_ssl_nginx }};
218178

219179
ssl_certificate /etc/letsencrypt/live/{{ certbot_name }}/fullchain.pem;
220180
ssl_certificate_key /etc/letsencrypt/live/{{ certbot_name }}/privkey.pem;
181+
ssl_trusted_certificate /etc/letsencrypt/live/{{ certbot_name }}/chain.pem;
221182
}

roles/vendor/certbot/templates/options-ssl-nginx.conf.j2

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@
44
# the up-to-date file that you will need to refer to when manually updating
55
# this file.
66

7-
ssl_session_cache shared:le_nginx_SSL:1m;
8-
ssl_session_timeout 1440m;
7+
ssl_session_cache shared:le_nginx_SSL:10m; # about 40000 sessions
8+
ssl_session_timeout 1d;
9+
ssl_session_tickets off;
910

10-
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
11-
ssl_prefer_server_ciphers on;
12-
13-
ssl_ciphers "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS";
11+
# intermediate configuration
12+
ssl_protocols TLSv1.2 TLSv1.3;
13+
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
14+
ssl_prefer_server_ciphers off;
1415

1516
ssl_dhparam {{ dh_params }};
1617

1718
# config to enable HSTS(HTTP Strict Transport Security) https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security
1819
# to avoid ssl stripping https://en.wikipedia.org/wiki/SSL_stripping#SSL_stripping
1920
# also https://hstspreload.org/
2021
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload" always;
22+
23+
# OCSP stapling
24+
ssl_stapling on;
25+
ssl_stapling_verify on;
26+
27+
resolver 127.0.0.53 valid=5m;

roles/vendor/nginx/templates/nginx.conf.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ user www-data;
22
worker_processes auto;
33
pid /run/nginx.pid;
44

5+
worker_rlimit_nofile 65535;
6+
57
events {
6-
worker_connections 768;
8+
worker_connections 4096;
79
# multi_accept on;
810
}
911

@@ -14,6 +16,7 @@ http {
1416
##
1517

1618
sendfile on;
19+
sendfile_max_chunk 512K;
1720
tcp_nopush on;
1821
tcp_nodelay on;
1922
keepalive_timeout 65;

0 commit comments

Comments
 (0)