Skip to content

Commit f3bd1bc

Browse files
committed
Update Nginx configuration to enhance real IP handling and adjust rate limiting parameters
1 parent e05d5d9 commit f3bd1bc

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

config/nginx/nginx.conf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ http {
2020
'"$request" $status $body_bytes_sent '
2121
'rt=$request_time urt=$upstream_response_time '
2222
'ust=$upstream_status uaddr=$upstream_addr '
23-
'xff="$http_x_forwarded_for" ua="$http_user_agent" '
23+
'xff="$http_x_forwarded_for" xri="$http_x_real_ip" '
24+
'rip_orig="$realip_remote_addr" ua="$http_user_agent" '
2425
'cache="$upstream_cache_status"';
2526

2627
access_log /dev/stdout main_timing;
@@ -120,19 +121,22 @@ http {
120121
text/x-component
121122
text/x-cross-domain-policy;
122123

123-
real_ip_header X-Forwarded-For;
124+
real_ip_header X-Real-IP;
124125
real_ip_recursive on;
125126

126127
set_real_ip_from 127.0.0.1;
128+
set_real_ip_from ::1;
127129
set_real_ip_from 10.0.0.0/8;
128130
set_real_ip_from 172.16.0.0/12;
129131
set_real_ip_from 192.168.0.0/16;
132+
set_real_ip_from fc00::/7;
133+
set_real_ip_from fe80::/10;
130134

131135
limit_req_status 429;
132136
limit_conn_status 429;
133137

134-
limit_req_zone $binary_remote_addr zone=drupal_rps:20m rate=5r/s;
135-
limit_req_zone $binary_remote_addr zone=drupal_heavy:20m rate=1r/s;
138+
limit_req_zone $binary_remote_addr zone=drupal_rps:20m rate=20r/s;
139+
limit_req_zone $binary_remote_addr zone=drupal_heavy:20m rate=3r/s;
136140
limit_conn_zone $binary_remote_addr zone=perip_conn:20m;
137141

138142
fastcgi_cache_path /var/cache/nginx/fastcgi_cache levels=1:2 keys_zone=drupal_microcache:50m inactive=60m max_size=500m;

config/nginx/preset.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ location / {
7575

7676
location ~* ^/(search|jsonapi|graphql)(/|$) {
7777
limit_conn perip_conn 5;
78-
limit_req zone=drupal_heavy burst=10 nodelay;
78+
limit_req zone=drupal_heavy burst=30;
7979
try_files $uri @drupal;
8080
}
8181

@@ -103,7 +103,7 @@ location / {
103103

104104
location @drupal {
105105
limit_conn perip_conn 10;
106-
limit_req zone=drupal_rps burst=30 nodelay;
106+
limit_req zone=drupal_rps burst=150;
107107

108108
fastcgi_cache drupal_microcache;
109109
fastcgi_cache_key "$scheme$request_method$host$request_uri";
@@ -122,7 +122,7 @@ location @drupal {
122122

123123
location @drupal-no-args {
124124
limit_conn perip_conn 10;
125-
limit_req zone=drupal_rps burst=30 nodelay;
125+
limit_req zone=drupal_rps burst=150;
126126

127127
fastcgi_cache drupal_microcache;
128128
fastcgi_cache_key "$scheme$request_method$host$request_uri";
@@ -141,7 +141,7 @@ location @drupal-no-args {
141141

142142
location = /index.php {
143143
limit_conn perip_conn 10;
144-
limit_req zone=drupal_rps burst=30 nodelay;
144+
limit_req zone=drupal_rps burst=150;
145145

146146
fastcgi_cache drupal_microcache;
147147
fastcgi_cache_key "$scheme$request_method$host$request_uri";

0 commit comments

Comments
 (0)