Custom-Wartungsseite bei nginx
Hallo,
wir nutzen einen nginx als Reverse-Proxy vor einem Applikationsserver, auf dem ein Onlineshop läuft.
Wir würden jetzt gerne - für größere Updates - einen Wartungsmodus aktivieren, der dazu führt, dass alle User eine Wartungsseite sehen, die direkt auf dem nginx liegt. Nur für einige IPs soll hier eine Ausnahme definiert sein, damit wir das Update durchführen und anschließend testen können.
Soweit funktioniert dies auch, wenn ich mit "set $wartung 1;" den Wartungsmodus aktiviere, allerdings kommt dann die Standard nginx 503 Fehlerseite, nicht meine Customseite "maintenance.html".
Wenn der Wartungsmodus deaktiviert ist, kann ich die Fehlerseite problemlos im Browser aufrufen (https://<meineDomain>/maintenance.html)
Hat jemand eine Idee, was ich falsch mache?
Er wirft ja den 503, aber es scheint als würde "error_page 503 /maintenance.html;" keine Wirkung zeigen.
Und hier mal die gesamte Site-Config.
wir nutzen einen nginx als Reverse-Proxy vor einem Applikationsserver, auf dem ein Onlineshop läuft.
Wir würden jetzt gerne - für größere Updates - einen Wartungsmodus aktivieren, der dazu führt, dass alle User eine Wartungsseite sehen, die direkt auf dem nginx liegt. Nur für einige IPs soll hier eine Ausnahme definiert sein, damit wir das Update durchführen und anschließend testen können.
Soweit funktioniert dies auch, wenn ich mit "set $wartung 1;" den Wartungsmodus aktiviere, allerdings kommt dann die Standard nginx 503 Fehlerseite, nicht meine Customseite "maintenance.html".
Wenn der Wartungsmodus deaktiviert ist, kann ich die Fehlerseite problemlos im Browser aufrufen (https://<meineDomain>/maintenance.html)
Hat jemand eine Idee, was ich falsch mache?
Er wirft ja den 503, aber es scheint als würde "error_page 503 /maintenance.html;" keine Wirkung zeigen.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
set $wartung 1;
if ($remote_addr = 234.234.234.234) {
set $wartung 0;
}
if ($remote_addr = 123.123.123.123 ) {
set $wartung 0;
}
if ($wartung = 1) {
return 503;
}
error_page 503 /maintenance.html;
location ~ /maintenance.html$ {
root /srv/www/html/;
}
Und hier mal die gesamte Site-Config.
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
roxy_cache_path /srv/nginx/cache/meineDomain-live levels=1:2 keys_zone=meineDomain_cache:256m inactive=120d max_size=25G;
map $request_method $purge_method {
PURGE 1;
default 0;
}
map $cookie_countrygroupid $cookie_cache_key {
"~([0-9]+)" $1;
default '1';
}
server {
listen 80;
server_name meineDomain.de www.meineDomain.de;
#return 301 https:{{comment_single_line_double_slash:0}}
location ~ /api {
proxy_cache off;
proxy_ignore_headers "Set-Cookie";
proxy_pass http://appserver;
}
location / {
return 301 https://www.meineDomain.de$request_uri;
}
}
server {
listen 443 ssl;
server_name meineDomain.de;
## SSL Zertifikate
#ssl_certificate /srv/ssl_remote/live/meineDomain.de/fullchain.pem;
#ssl_certificate_key /srv/ssl_remote/live/meineDomain.de/privkey.pem;
ssl_certificate /srv/ssl/meineDomain/meineDomain.de.bundle.pem;
ssl_certificate_key /srv/ssl/meineDomain/meineDomain.de.key.pem;
ssl_dhparam /srv/ssl/dhparam.pem;
ssl_session_timeout 5m;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # not possible to do exclusive
return 301 https://www.meineDomain.de$request_uri;
}
server {
status_zone meineDomain_desktop;
listen 443 ssl;
server_name www.meineDomain.de;
access_log /var/log/troubleshoot.log troubleshoot;
#access_log /var/log/nginx/meineDomain.access.log shop;
error_log /var/log/nginx/meineDomain.error.log debug;
proxy_cache meineDomain_cache;
rewrite_log on;
set $cache_key "$request_uri";
proxy_cache_key "$cookie_cache_key$request_uri";
# Caching deaktivieren
set $no_cache "";
#if ($http_cookie ~* "akosha_session*"){
#set $no_cache 1;
#}
# NoCache URLs
if ($request_uri ~* "(/admin.*|/brand.*|/user.*|/login.*|/de/favoriten.pdf)") {
set $no_cache 1;
}
# Wartungsmodus START
set $wartung 0;
if ($remote_addr = 127.0.0.1) {
set $wartung 0;
}
if ($remote_addr = a.a.a.a ) {
set $wartung 0;
}
if ($wartung = 1) {
return 503;
}
error_page 503 /maintenance.html;
location ~ /maintenance.html$ {
root /srv/www/meineDomain.de/;
}
# Wartungsmodus ENDE
# temorär proxycache deaktivieren
proxy_no_cache $no_cache;
## SSL Zertifikate
ssl_certificate /srv/ssl/meineDomain/meineDomain.de.bundle.pem;
ssl_certificate_key /srv/ssl/meineDomain/meineDomain.de.key.pem;
ssl_dhparam /srv/ssl/dhparam.pem;
ssl_session_timeout 5m;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # not possible to do exclusive
## Block some UserAgents
if ($badagent) {
return 403;
}
## Block SQL injections
set $block_sql_injections 0;
if ($query_string ~ "union.*select.*\(") {
set $block_sql_injections 1;
}
if ($query_string ~ "union.*all.*select.*") {
set $block_sql_injections 1;
}
if ($query_string ~ "concat.*\(") {
set $block_sql_injections 1;
}
if ($block_sql_injections = 1) {
return 403;
}
## Block GEO-IP
if ($allowed_country = no) {
return 444;
}
location ~ /robots.txt$ {
root /srv/www/meineDomain.de/;
}
location ~ /web-sitemap.xml$ {
root /srv/www/meineDomain.de/;
}
# jobs
location ~ /jobs$ {
return 301 https://www.meineDomain.de/jobs.html;
}
# Adminbereich
location ~ /admin {
# Access by IP
satisfy any;
allow 10.0.2.0/24;
allow a.a.a.a/32;
deny all;
# Access by Passwort
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_cache off;
proxy_pass http://appserver;
}
# Adminbereich
location ~ /custom/admin {
# Access by IP
satisfy any;
allow 10.0.2.0/24;
allow a.a.a.a/32;
deny all;
# Access by Passwort
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_cache off;
proxy_pass http://appserver;
}
# Startseite
location ~ /$ {
#proxy_cache off;
proxy_ignore_headers "Set-Cookie";
proxy_pass http://appserver;
health_check;
proxy_cache_purge $purge_method;
}
# Cachen
location ~* \.(html)$ {
#proxy_cache off;
proxy_ignore_headers "Set-Cookie";
proxy_pass http://appserver;
health_check;
proxy_cache_purge $purge_method;
}
# Cachen
location ~ /blog {
#proxy_cache off;
proxy_ignore_headers "Set-Cookie";
proxy_pass http://appserver;
health_check;
proxy_cache_purge $purge_method;
}
# Cachen
location ~* \.(webp|gif|jpg|png|pdf)$ {
expires 365d;
proxy_ignore_headers "Set-Cookie";
proxy_pass http://appserver;
health_check;
proxy_cache_purge $purge_method;
}
# Cachen
location ~* \.(js|css|woff|woff2|otf|ttf|eot|svg|ico|map|glyphs)$ {
expires 365d;
proxy_ignore_headers "Set-Cookie";
proxy_pass http://appserver;
health_check;
proxy_cache_purge $purge_method;
}
# nicht cachen (Warenkorb usw)
location ~* \.(cfc|cfm|htm|gz|xml|bin|txt|json)$ {
proxy_cache off;
proxy_pass http://appserver;
health_check;
}
location ~ /api {
proxy_cache off;
proxy_ignore_headers "Set-Cookie";
proxy_pass http://appserver;
}
location ~ /admin$ {
rewrite ^/admin$ /admin/ break;
proxy_pass http://appserver;
}
}
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 3790272700
Url: https://administrator.de/forum/custom-wartungsseite-bei-nginx-3790272700.html
Ausgedruckt am: 07.04.2025 um 07:04 Uhr
4 Kommentare
Neuester Kommentar
Ich weiss nicht ob das bei der Verarbeitung bei nginx eine Rolle spielt, aber hast du schon mal probiert
vorher zu setzen? z.B. so:
Jenachdem wie nginx dies verarbeitet wird ja sonst durch return 503 die abarbeitung beendet, bevor er überhaupt die Definition der 503 Seite erreicht.
1
error_page 503 /maintenance.html;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
error_page 503 /maintenance.html;
location ~ /maintenance.html$ {
root /srv/www/html/;
}
set $wartung 1;
if ($remote_addr = 234.234.234.234) {
set $wartung 0;
}
if ($remote_addr = 123.123.123.123 ) {
set $wartung 0;
}
if ($wartung = 1) {
return 503;
}
Jenachdem wie nginx dies verarbeitet wird ja sonst durch return 503 die abarbeitung beendet, bevor er überhaupt die Definition der 503 Seite erreicht.