Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add 50x html for error page #4164

Merged
merged 29 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion html/50x.html → apisix/cli/html_page.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
--
-- Licensed to the Apache Software Foundation (ASF) under one or more
-- contributor license agreements. See the NOTICE file distributed with
-- this work for additional information regarding copyright ownership.
-- The ASF licenses this file to You under the Apache License, Version 2.0
-- (the "License"); you may not use this file except in compliance with
-- the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--

return [=[
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
Expand All @@ -21,7 +39,7 @@
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Error</title>
<title>500 Internal Server Error</title>
<style>
body {
width: 35em;
Expand All @@ -36,3 +54,4 @@ <h1>An error occurred.</h1>
<p><em>Faithfully yours, <a href="https://apisix.apache.org/">APISIX</a>.</em></p>
</body>
</html>
]=]
2 changes: 1 addition & 1 deletion apisix/cli/ngx_tpl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ http {
charset utf-8;

# error_page
error_page 500 502 503 504 @50x.html;
error_page 500 @50x.html;

{% if real_ip_header then %}
real_ip_header {* real_ip_header *};
Expand Down
9 changes: 9 additions & 0 deletions apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local etcd = require("apisix.cli.etcd")
local util = require("apisix.cli.util")
local file = require("apisix.cli.file")
local ngx_tpl = require("apisix.cli.ngx_tpl")
local html_page = require("apisix.cli.html_page")
local profile = require("apisix.core.profile")
local template = require("resty.template")
local argparse = require("argparse")
Expand Down Expand Up @@ -586,6 +587,11 @@ Please modify "admin_key" in conf/config.yaml .
if not ok then
util.die("failed to update nginx.conf: ", err, "\n")
end

local ok, err = util.write_file(env.apisix_home .. "/html/50x.html", html_page)
if not ok then
util.die("failed to write 50x.html: ", err, "\n")
end
end


Expand All @@ -605,6 +611,9 @@ local function start(env, ...)
local cmd_logs = "mkdir -p " .. env.apisix_home .. "/logs"
util.execute_cmd(cmd_logs)

local cmd_html = "mkdir -p " .. env.apisix_home .. "/html"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add it to gitignore:

conf/nginx.conf

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Please review it again.

util.execute_cmd(cmd_html)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why adding an empty line here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Please review it again.

-- check running
local pid_path = env.apisix_home .. "/logs/nginx.pid"
local pid = util.read_file(pid_path)
Expand Down
2 changes: 1 addition & 1 deletion apisix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ end


function _M.http_header_filter_phase()
if not ngx.ctx then
if not ngx.ctx or not ngx.ctx.api_ctx then
ngx.ctx = ctxdump.apply_ngx_ctx(ngx_var.ctx_ref)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stash ngx.ctx unconditionally but checking the existence of ngx.ctx , this behavior leaks some keys for ngx.ctx tables (for those requests which doesn't make internal redirect).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Please review it again.

end

Expand Down
5 changes: 1 addition & 4 deletions t/APISIX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ my $ssl_ecc_crt = read_file("t/certs/apisix_ecc.crt");
my $ssl_ecc_key = read_file("t/certs/apisix_ecc.key");
my $test2_crt = read_file("t/certs/test2.crt");
my $test2_key = read_file("t/certs/test2.key");
my $test_50x_html = read_file("html/50x.html");
$user_yaml_config = <<_EOC_;
apisix:
node_listen: 1984
Expand Down Expand Up @@ -375,7 +374,7 @@ _EOC_
lua_socket_log_errors off;
client_body_buffer_size 8k;

error_page 500 502 503 504 \@50x.html;
error_page 500 \@50x.html;

upstream apisix_backend {
server 0.0.0.1;
Expand Down Expand Up @@ -650,8 +649,6 @@ $ssl_ecc_key
$test2_crt
>>> ../conf/cert/test2.key
$test2_key
>>> 50x.html
$test_50x_html
$user_apisix_yaml
_EOC_

Expand Down
12 changes: 6 additions & 6 deletions t/error_page/error_page.t
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ GET /hello
--- more_headers
X-Test-Status: 502
--- error_code: 502
--- response_body_like
.*apisix.apache.org.*
--- response_body eval
qr/502 Bad Gateway/



Expand All @@ -91,8 +91,8 @@ GET /hello
--- more_headers
X-Test-Status: 503
--- error_code: 503
--- response_body_like
.*apisix.apache.org.*
--- response_body eval
qr/503 Service Unavailable/



Expand All @@ -102,8 +102,8 @@ GET /hello
--- more_headers
X-Test-Status: 504
--- error_code: 504
--- response_body_like
.*apisix.apache.org.*
--- response_body eval
qr/504 Gateway Time-out/



Expand Down
4 changes: 2 additions & 2 deletions t/node/not-exist-upstream.t
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ GET /not_found
--- request
GET /hello
--- error_code_like: ^(?:50\d)$
--- response_body_like
.*apisix.apache.org.*
--- response_body eval
qr/502 Bad Gateway|500 Internal Server Error/
--- grep_error_log eval
qr/\[error\].*/
--- grep_error_log_out eval
Expand Down
4 changes: 2 additions & 2 deletions t/node/timeout-upstream.t
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ passed
--- request
GET /sleep1
--- error_code: 504
--- response_body_like
.*apisix.apache.org.*
--- response_body eval
qr/504 Gateway Time-out/

--- error_log
timed out) while reading response header from upstream
8 changes: 4 additions & 4 deletions t/node/upstream-status-5xx.t
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ passed
--- request
GET /sleep1
--- error_code: 504
--- response_body_like
.*apisix.apache.org.*
--- response_body eval
qr/504 Gateway Time-out/
--- error_log
X-APISIX-Upstream-Status: 504

Expand Down Expand Up @@ -161,8 +161,8 @@ passed
--- request
GET /hello
--- error_code: 502
--- response_body_like
.*apisix.apache.org.*
--- response_body eval
qr/502 Bad Gateway/
--- error_log
X-APISIX-Upstream-Status: 502

Expand Down
4 changes: 2 additions & 2 deletions t/plugin/grpc-transcode.t
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ passed
=== TEST 10: hit route (Connection refused)
--- request
GET /grpctest
--- response_body_like
.*apisix.apache.org.*
--- response_body eval
qr/502 Bad Gateway/
--- error_log
Connection refused) while connecting to upstream
--- error_code: 502
Expand Down