Skip to content

Commit e05d5d9

Browse files
committed
Enhance Nginx configuration with improved error logging and caching mechanisms
1 parent c702b53 commit e05d5d9

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

config/nginx/nginx.conf

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ load_module modules/ngx_http_brotli_static_module.so;
55
# user nobody;
66
daemon off;
77
worker_processes auto;
8-
error_log stderr info;
8+
error_log /dev/stderr info;
99

1010
events {
1111
worker_connections 1024;
@@ -16,7 +16,14 @@ http {
1616
include /etc/nginx/mime.types;
1717
default_type application/octet-stream;
1818

19-
access_log stdout combined;
19+
log_format main_timing '$remote_addr - $remote_user [$time_local] '
20+
'"$request" $status $body_bytes_sent '
21+
'rt=$request_time urt=$upstream_response_time '
22+
'ust=$upstream_status uaddr=$upstream_addr '
23+
'xff="$http_x_forwarded_for" ua="$http_user_agent" '
24+
'cache="$upstream_cache_status"';
25+
26+
access_log /dev/stdout main_timing;
2027

2128
proxy_connect_timeout 600s;
2229
proxy_send_timeout 600s;
@@ -128,6 +135,19 @@ http {
128135
limit_req_zone $binary_remote_addr zone=drupal_heavy:20m rate=1r/s;
129136
limit_conn_zone $binary_remote_addr zone=perip_conn:20m;
130137

138+
fastcgi_cache_path /var/cache/nginx/fastcgi_cache levels=1:2 keys_zone=drupal_microcache:50m inactive=60m max_size=500m;
139+
140+
map $request_method $drupal_cache_bypass_method {
141+
default 1;
142+
GET 0;
143+
HEAD 0;
144+
}
145+
146+
map $http_cookie $drupal_cache_bypass_cookie {
147+
default 0;
148+
~*"(S?SESS)[0-9a-zA-Z]+" 1;
149+
}
150+
131151
add_header X-XSS-Protection '1; mode=block';
132152
add_header X-Frame-Options SAMEORIGIN;
133153
add_header X-Content-Type-Options nosniff;

config/nginx/preset.conf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ location / {
104104
location @drupal {
105105
limit_conn perip_conn 10;
106106
limit_req zone=drupal_rps burst=30 nodelay;
107+
108+
fastcgi_cache drupal_microcache;
109+
fastcgi_cache_key "$scheme$request_method$host$request_uri";
110+
fastcgi_cache_valid 200 301 302 10s;
111+
fastcgi_cache_valid 404 1s;
112+
fastcgi_cache_bypass $drupal_cache_bypass_method $drupal_cache_bypass_cookie $http_authorization $query_string;
113+
fastcgi_no_cache $drupal_cache_bypass_method $drupal_cache_bypass_cookie $http_authorization $query_string;
114+
add_header X-Cache $upstream_cache_status always;
115+
107116
include fastcgi.conf;
108117
fastcgi_param QUERY_STRING $query_string;
109118
fastcgi_param SCRIPT_NAME /index.php;
@@ -114,6 +123,15 @@ location @drupal {
114123
location @drupal-no-args {
115124
limit_conn perip_conn 10;
116125
limit_req zone=drupal_rps burst=30 nodelay;
126+
127+
fastcgi_cache drupal_microcache;
128+
fastcgi_cache_key "$scheme$request_method$host$request_uri";
129+
fastcgi_cache_valid 200 301 302 10s;
130+
fastcgi_cache_valid 404 1s;
131+
fastcgi_cache_bypass $drupal_cache_bypass_method $drupal_cache_bypass_cookie $http_authorization;
132+
fastcgi_no_cache $drupal_cache_bypass_method $drupal_cache_bypass_cookie $http_authorization;
133+
add_header X-Cache $upstream_cache_status always;
134+
117135
include fastcgi.conf;
118136
fastcgi_param QUERY_STRING q=$uri;
119137
fastcgi_param SCRIPT_NAME /index.php;
@@ -124,6 +142,15 @@ location @drupal-no-args {
124142
location = /index.php {
125143
limit_conn perip_conn 10;
126144
limit_req zone=drupal_rps burst=30 nodelay;
145+
146+
fastcgi_cache drupal_microcache;
147+
fastcgi_cache_key "$scheme$request_method$host$request_uri";
148+
fastcgi_cache_valid 200 301 302 10s;
149+
fastcgi_cache_valid 404 1s;
150+
fastcgi_cache_bypass $drupal_cache_bypass_method $drupal_cache_bypass_cookie $http_authorization $query_string;
151+
fastcgi_no_cache $drupal_cache_bypass_method $drupal_cache_bypass_cookie $http_authorization $query_string;
152+
add_header X-Cache $upstream_cache_status always;
153+
127154
fastcgi_pass php;
128155
}
129156

0 commit comments

Comments
 (0)